Emacs模型在文件末尾一行 [英] Emacs modeline at the end of file in one line

查看:137
本文介绍了Emacs模型在文件末尾一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,有些人使用vi,有些使用emacs和其他(包括gedit)。执行(至少是视觉)风格的最简单而全球的方式(尽管不是完美的)是将以下行添加到每个文件的末尾:

  ... 
return 0;
}
//编辑器模型 - 由http://www.wireshark.org/tools/modelines.html
生成//局部变量:
// c-basic-偏移量:4
// tab-width:4
// indent-tabs-mode:t
// truncate-lines:1
// End:
// vim:set ft = cpp ts = 4 sw = 4 sts = 4 nowrap:cindent:

问题是:如何将emacs部分转换为一行代码(如vim可以)?并将其保留在源文件的末尾(不在顶部)。



(可能这可以被称为Lisp问题,但我不熟悉)

解决方案

您可以使用 eval:声明,但Emacs会要求您确认评估是否安全。如果您告诉Emacs永久接受它,它不会再次询问该表达式(它将它存储在custom-set-variables中的 safe-local-variable-values 中您的初始化文件的部分)。

  ;;;本地变量:
;;; eval:(setq c-basic-offset 4 tab-width 4 indent-tabs-mode t truncate-lines 1)
;;;结束:

您可以在 progn中包装多个表达式

  ;;;本地变量:
;;; eval:(progn(setq c-basic-offset 4)(messagehello))
;;;结束:

或使用任何其他结构(我不认为有任何限制) p>

I am working on a project where some people use vi, some use emacs and some others (including gedit). The most simple yet global way (although not perfect) to enforce (at least visual) style was to add the following lines to the end of each file:

  ...
  return 0;
}
// Editor modelines  -  generated by http://www.wireshark.org/tools/modelines.html
// Local variables:
// c-basic-offset: 4
// tab-width: 4
// indent-tabs-mode: t
// truncate-lines: 1
// End:
// vim:set ft=cpp ts=4 sw=4 sts=4 nowrap: cindent:

the question is: how can I convert the emacs portion in a "one-line" code (as vim can)? and yet keep it at the end of the source file (not at the top).

(Probably this can be recasted as Lisp question but I am not familiar with it)

解决方案

You can use the eval: declaration, but Emacs will ask you to confirm that it is safe to evaluate. If you tell Emacs to accept it permanently, it won't ask about that expression again (it stores it in safe-local-variable-values in the custom-set-variables section of your init file).

;;; Local Variables:
;;; eval:(setq c-basic-offset 4 tab-width 4 indent-tabs-mode t truncate-lines 1)
;;; End:

You can wrap multiple expressions in progn:

;;; Local Variables:
;;; eval:(progn (setq c-basic-offset 4) (message "hello"))
;;; End:

Or use any other constructs (I don't think there are any restrictions).

这篇关于Emacs模型在文件末尾一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆