1

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?

Community
  • 1
  • 1
Pulimon
  • 1,776
  • 4
  • 31
  • 45

1 Answers1

5

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

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • Thanks Alex, but I still have the problem. Browsing through the different options I do find 4 option named 1) Verilog auto hook, 2) Verilog before auto hook 3) verilog delete auto hook and 4) verilog before delete auto hook. Should I change these values for it to work?\ – Pulimon Nov 28 '11 at 16:27
  • That's very strange - I just checked this function once again (gnu emacs 24 from bzr), and when I set `indent-tabs-mode` to `t`, then I get tabs in source code, but when I set it to `nil`, then I get space... Could you check - maybe you have some hook, that is part of Emacs init code? Which functions are listed in `verilog-mode-hook` ? – Alex Ott Nov 29 '11 at 09:07
  • Ok I checked the `verilog-mode-hook` it says `my-verilog-hook` THe problem still persists. Btb I am using emacs version 23.3, downloaded from [emacs official site](http://www.gnu.org/s/emacs/). Might be a bug that got fixed in version 24. And yes I did get a temporary work around [here](http://www.veripool.org/issues/345-Verilog-mode-can-t-get-untabify-on-save-to-work) This seems to work fine. Tabs will be converted to spaces when I save the file – Pulimon Nov 29 '11 at 09:45
  • I also checked code for verilog-mode - it doesn't use indent-tabs-mode directly, so it should be handled by underlying mode... But that's fine that `untabify` works for you – Alex Ott Nov 29 '11 at 10:36