Emacs缩进级全局覆盖 [英] Emacs indent level global override

查看:117
本文介绍了Emacs缩进级全局覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将缩进模式设置为仅限制标签,任何模式均为4个字符宽度。这似乎是一个微不足道的事情,但我没有成功。每个模式似乎都有自己的变量和选项。我已经尝试这样做为Perl和R没有成功。
没有工作的东西:

 (setq-default tab-width 4)
(setq standard -intent 4)
(setq-default r-indent-level 4)
(setq perl-indent-level 4)

(setq c-basic-offset 4)适用于c模式,但没有其他的。我忘记了什么吗?我设置了错误的变量吗? X-4545454545新新新旗新新新新旗新新旗新新旗新新200新200新新旗新新旗新新旗200新新新旗新旗旗新旗旗新新旗新旗新新旗旗由于我喜欢跨语言使用相同的缩进,是否有这样一个全局覆盖变量,我可以设置,使缩进级别和样式在所有模式下是一致的?如果没有,有没有办法在启动时为每种模式设置它们?如果一切都失败,那么必须有一个elisp脚本来执行此操作。



使用Emacs 23






RESOLVED:我不得不单独设置每个模式的变量,因为没有这样的全局覆盖。您可以将以下语句放在〜/ .emacs文件中以在启动时配置emac。



R模式来自 ESS 包。阅读文档,我发现:(setq ess-indent-level 4)



在CPerl模式下(setq cperl-indent-level 4)



看起来你只需要搜索正确的变量X-454545 X-454545 X-4545 X- 20045 X-4545 X-4545 X- 20045 X-4545 X-4545 X- 200 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X-45。您可以在Emacs Wiki上阅读所有内容:

http://www.emacswiki.org/emacs/新新新新旗新新200新新新旗新新200新旗新新旗新新200新旗新新旗新200旗新新旗新200旗新新旗新新旗新新200新旗新新旗新新旗新200新新新新旗新新款:所以没有,没有全局缩进配置,保证影响每个可能的主要模式(尽管在实践中,某些变量都是按照惯例完全标准的)。


如果没有,有没有办法在启动时为每种模式设置它们?


当然。最简单的方法是使用 Mx 自定义 RET 接口来配置值和默认值,尽管只有使用<$ 200新新新新旗新新新旗新新旗新新旗新新旗新新200新200新新新200新200新新新200新200新新新200新新200新200新新200新新200新新旗新新200新新200新新新新旗新新200新新新新旗新新200新新旗新新200新新200新新旗新新200新新旗新新200新新新新旗新新旗新新款旗新新旗新新款旗新新旗新新款旗新新旗新新款旗新新旗新新旗新新款旗新新旗新新旗新新旗新新旗新新款旗新新旗新新旗新新款旗新新旗新新款旗新新款新旗



使用 setq (mode-name)-hook 变量的函数列表,因此任何模式特定的定制都可以写入一个elisp函数,并添加到您的init文件中的适当的挂钩列表。



例如:

 (defun my-c-mode-config()
(空格模式1)
(setq indent-tabs-mode t
tab-width 4 $ b X- 20045454545 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- pre>

I want to set the indentation mode to tabs only, with a 4 character width for any mode. This seems like a trivial thing, but I have not had success. Every mode seems to have its own variables and options. I've tried doing this for Perl and R without success. Things that have not worked:

(setq-default tab-width 4)
(setq standard-indent 4)
(setq-default r-indent-level 4)
(setq perl-indent-level 4)

(setq c-basic-offset 4) works for c-mode but nothing else. Am I forgetting something? Did I set the wrong variables? Is there no such option?

I work with a variety of languages (R, Perl, sh, C/C++ etc.) on a daily basis. Since I like to use the same indentation across languages, is there such a global override variable that I can set so that the indentation level and style is consistent across all modes? If not, is there a way to set them for each mode on startup? If all else fails, there has to be an elisp script that does this.

Using Emacs 23


RESOLVED: I had to set the variables for each mode individually because there is no such global override. You can put the following statements in your ~/.emacs file to configure emacs on startup.

R mode comes from the ESS package. Reading through the documentation, I found this: (setq ess-indent-level 4)

In CPerl mode (setq cperl-indent-level 4)

Looks like you'll just have to search for the right variable in each mode.

解决方案

Indentation in Emacs isn't really a "trivial thing". You can read all about it at the Emacs Wiki:
http://www.emacswiki.org/emacs/CategoryIndentation

Any major mode is free to implement indentation however it wishes and, as you've noticed, several of them introduce indentation-related variables; so no, there is no global indentation configuration which is guaranteed to affect every possible major mode (although in practice, certain variables are completely standard by convention).

If not, is there a way to set them for each mode on startup?

Of course. The easiest way is to configure values and defaults using the M-x customize RET interface, although only variables defined with defcustom appear there, so it isn't necessarily comprehensive (but it can still be very useful for browsing some of the available settings, even if you don't actually use it to set the values).

Setting values (or defaults in the case of automatically buffer-local variables) in your init file with setq and setq-default, as you've done, is also fine.

If you want more control, you can use mode hooks. Pretty much every mode runs the list of functions assigned to the (mode-name)-hook variable after initialising itself in a buffer, so any mode-specific customisations can be written in an elisp function and added to the appropriate hook list, in your init file.

e.g.:

(defun my-c-mode-config ()
  (whitespace-mode 1)
  (setq indent-tabs-mode t
        tab-width        4
        c-basic-offset   4))

(add-hook 'c-mode-hook 'my-c-mode-config)

这篇关于Emacs缩进级全局覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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