can't get untabify on save to work
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.
#4 Updated by Kaushal Modi 8 months 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." (interactive) (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)
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.