Major Tools
Other Tools
General Info

Issue #345

can't get untabify on save to work

Added by David Rogoff over 4 years ago. Updated 18 days ago.

Status:ClosedStart date:05/10/2011
Priority:HighDue date:
Assignee:-% Done:


Target version:-


To follow my groups coding standard, I need to make sure I remove tabs from my code. I tried the following from the FAQ at verilog.com: (add-hook 'verilog-mode-hook '(lambda () (add-hook 'local-write-file-hooks (lambda() (untabify (point-min) (point-max))))))

However, it doesn't seem to work. I'm using "gnu" emacs 23.3 on Linux and I'm not that fluent in elisp and add-hook.

Any suggestions?


#1 Updated by Wilson Snyder over 4 years ago

  • Status changed from New to Assigned

The emacs docs say the variable name changed, try this - note the nil.

(add-hook 'verilog-mode-hook '(lambda ()
  (add-hook 'write-file-functions (lambda()
      (untabify (point-min) (point-max))

#2 Updated by David Rogoff over 4 years ago

Yay! That works!

#3 Updated by Wilson Snyder over 4 years ago

  • Status changed from Assigned to Closed

#4 Updated by Kaushal Modi 18 days ago

As per the recent discussion on this debbugs thread ( https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21492 ). before-save-hook (a normal hook) is probably a better candidate than write-file-functions (which is an abnormal hook and will abort the saving if any of the functions added to this hook returns a non-nil value).

In this case, the untabify function does not return a nil value and will causing problem with file saving. And so that extra nil had to be added.

To simplify this, before-save-hook can be used instead. I have also used a coding convention of NOT using lambdas and creating mini functions instead so that it is easier to remove hooks if needed and to review the hook values using describe-variable function (Example: C-h v before-save-hook)

(defun my/untabify-buffer ()
  "Untabify the current buffer." 
  (untabify (point-min) (point-max)))

(defun my/verilog-mode-customizations ()
  (add-hook 'before-save-hook #'my/untabify-buffer nil :local))

(add-hook 'verilog-mode-hook #'my/verilog-mode-customizations)

NOTE: The my/untabify-buffer function is added locally to the before-save-hook so that untabification does not happen for all the major modes. If you happen to add this to the before-save-hook globally and edit Makefiles, it can mess up those as Makefiles need the TAB characters.

Also available in: Atom PDF