bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#21492: 25.0.50: Make untabify work nicely with write-file-functions


From: Kaushal Modi
Subject: bug#21492: 25.0.50: Make untabify work nicely with write-file-functions
Date: Wed, 16 Sep 2015 15:54:25 +0000

Thanks for the right direction, Stefan.

I am closing this bug as it makes sense to not modify the untabify function. I was following the example of delete-trailing-whitespace.

For reference, I now have put the crux of this discussion in my config as below:

(defun modi/untabify-buffer ()
  "Untabify the current buffer.

http://www.veripool.org/issues/345-Verilog-mode-can-t-get-untabify-on-save-to-work
Note that the function's return value is set to nil because if this function is
added to `write-file-functions' hook, emacs will stay stuck at at the
\"Saving file ..\" message and the file won't be saved if any function added to
`write-file-functions' returned a non-nil value.

As per the suggestion in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21492,
for this purpose, it makes a better sense to use `before-save-hook' (a normal
hook) instead of `write-file-functions' (an abnormal hook that relies on stuff
like the function return values).

So below would be a recommended way of using this function:

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

Note that it is suggested to add this function to the `before-save-hook'
*locally* within a hook for a major mode which does not require the use of
tabs instead of spaces. Do NOT add this function to the hook globally,
because it can cause issues with files like Makefiles that rely on the use of
tabs explicitly."
  (interactive)
  (untabify (point-min) (point-max))
  ;; Return nil for the benefit of `write-file-functions'.
  nil)

I also have now started using before-save-hook instead of write-file-functions where I don't care about the return values of the functions added to the hook.

Thanks Glenn, Stefan!


On Wed, Sep 16, 2015 at 9:14 AM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> I personally have dealt with the issue where I cannot add untabify directly
> to write-file-functions hook, because untabify does not return nil.

If it hurts, then don't do that.  We have before-save-hook for that.


        Stefan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]