Using hooks in Emacs

Chaining code onto hooks are a great way to extend Emacs. The basic idea is that hooks are lists of code to execute when a particular action takes place. The following is an example of code that chains off the find-file-hooks which gets executed when a file is opened. The “untabify-buffer” function removes the tabs from the file and replaces with spaces.

(defun untabify-buffer ()
    (untabify (point-min) (point-max)))

(add-hook
  'find-file-hooks
  'untabify-buffer)

Leave a Reply