Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get untabify on save to work #345

Closed
veripoolbot opened this issue May 10, 2011 · 4 comments
Closed

can't get untabify on save to work #345

veripoolbot opened this issue May 10, 2011 · 4 comments

Comments

@veripoolbot
Copy link
Collaborator


Author Name: David Rogoff
Original Redmine Issue: 345 from https://www.veripool.org
Original Date: 2011-05-10


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?

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2011-05-10T01:20:10Z


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))
nil))))

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: David Rogoff
Original Date: 2011-05-10T03:51:54Z


Yay! That works!

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Kaushal Modi
Original Date: 2015-09-16T16:03:19Z


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)

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.

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: David Rogoff
Original Date: 2015-12-16T00:58:25Z


Wow - I just ran into the problem Kaushal mentioned of the previous solution affecting all modes and messing up makefiles. I did a google search on this and it brought me here - to my own question from 4 years ago. Can't beat that!

Thanks,

David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant