1
votes

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. 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 global configuration of tabs

But they do not seem to work in verilog mode. This is how my .emacs file looks like

(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. However it still inserts a tab character when I try to edit a verilog file (.v). I can select the entire text and do M-x untabify to get the required result but is there another direct solution?

1

1 Answers

5
votes

In the hook you should use setq instead of setq-default, so you need to rewrite your hook to something like:

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

P.S. it's better to use dedicated functions in hooks, as it's easier to change them, and you can also remove them from hooks