0

I am changing the default value for fill-column, then hook it for prog-mode. Would be neat to have a way that I can have a single function to do this. Currently add-hook requires a call to an outside function colum-property in order to set it.

(defun colum-property ()
  (setq fill-column 72))

(defun colum-mhook ()
  (add-hook 'prog-mode-hook #'colum-property))

1 Answer 1

0

You can call the hook with a lambda function.

(defun colum-mhook ()
  (add-hook 'prog-mode-hook (lambda()(setq fill-column 72))))

As NickD rightly points out, encapsulating the add-hook in a function doesn't seem to help much. You might as well write the add-hook directly in the Emacs initialization file.

3
  • I was about to say the same thing but also to remark that doing this makes it a bit more tricky to undo via remove-hook. Aug 29, 2022 at 9:17
  • @Fran Burstall: (remove-hook 'prog-mode-hook (lambda()(setq fill-column 72))) do the trick as if it is a named function.
    – gigiair
    Aug 29, 2022 at 9:39
  • Why is colum-mhook (sic) needed at all? Why not call add-hook directly?
    – NickD
    Aug 29, 2022 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.