简体   繁体   English

如何设置emacs在verilog模式下使用3个空格而不是制表符?

[英]How do I set emacs to use 3 spaces instead of tabs in verilog mode?

I am pretty new to emacs (using version 23.3) and I wanted to set the default tab key to insert 3 spaces instead of a tab character in verilog mode. 我是emacs的新手(使用版本23.3),我想设置默认的tab键以在verilog模式下插入3个空格而不是制表符。 I did find a number of posts regarding this in stack overflow. 我确实在堆栈溢出中发现了一些关于此的帖子。 Some of them are: - 他们之中有一些是: -

How To Force spaces instead of tabs regardless of major mode 无论主要模式如何,如何强制使用空格而不是制表符

Why might my Emacs use spaces instead of tabs? 为什么我的Emacs可能使用空格而不是制表符?

Emacs global configuration of tabs Emacs标签的全局配置

But they do not seem to work in verilog mode. 但它们似乎不适用于verilog模式。 This is how my .emacs file looks like 这就是我的.emacs文件的样子

(custom-set-variables      
 '(tab-stop-list ('(3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108 111 114 117 120)))
 '(verilog-case-indent 3)    
 '(verilog-indent-level-directive 0)
 '(verilog-indent-level 3)    
 '(verilog-tab-always-indent nil))
(custom-set-faces
  )
(add-hook 'after-change-major-mode-hook 
          '(lambda () 
             (setq-default indent-tabs-mode nil)
             (setq tab-width 3)))

(setq-default indent-tabs-mode nil)
(setq-default tab-width 3)
(setq-default standard-indent 3)

If I try to edit a text file, the setup works perfectly and inserts 3 spaces instead of a tab. 如果我尝试编辑文本文件,则设置完美,并插入3个空格而不是选项卡。 However it still inserts a tab character when I try to edit a verilog file (.v). 但是,当我尝试编辑verilog文件(.v)时,它仍会插入制表符。 I can select the entire text and do Mx untabify to get the required result but is there another direct solution? 我可以选择整个文本并执行Mx解压缩以获得所需的结果但是还有其他直接解决方案吗?

In the hook you should use setq instead of setq-default , so you need to rewrite your hook to something like: 在钩子中你应该使用setq而不是setq-default ,所以你需要将钩子重写为:

(defun my-verilog-hook ()
    (setq indent-tabs-mode nil)
    (setq tab-width 3))
 (add-hook 'verilog-mode-hook 'my-verilog-hook)

PS it's better to use dedicated functions in hooks, as it's easier to change them, and you can also remove them from hooks PS最好在钩子中使用专用功能,因为它更容易更改它们,你也可以从钩子中删除它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM