[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

Issue #345

can't get untabify on save to work

Added by David Rogoff about 5 years ago. Updated 6 months ago.

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

0%

Category:General
Target version:-

Description

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?

History

#1 Updated by Wilson Snyder about 5 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))
      nil))))

#2 Updated by David Rogoff about 5 years ago

Yay! That works!

#3 Updated by Wilson Snyder about 5 years ago

  • Status changed from Assigned to Closed

#4 Updated by Kaushal Modi 9 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)

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.

#5 Updated by David Rogoff 6 months ago

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

Also available in: Atom PDF