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

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

Re: How to apply a minor mode to all buffers


From: leoboiko
Subject: Re: How to apply a minor mode to all buffers
Date: Fri, 02 Feb 2007 17:27:24 -0200
User-agent: Wanderlust/2.15.5 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/22.0.93 (i486-pc-linux-gnu) MULE/5.0 (SAKAKI)

At Mon, 22 Jan 2007 11:57:35 -0500,
Stefan Monnier wrote:
> You could start with find-file-hook.

find-file-hook won’t apply to buffers unrelated to files, though.
after-change-major-mode-hook almost does the trick, but it still
doesn’t get fundamental-mode.

What I’d like is fundamental-mode-hook.

“Damn vim users”, I said.  “Keep leaving those trailing whitespaces
all over the place.  It disrupts my mental concentration, for I have
show-trailing-whitespace globally as t, and I have to stop whatever
I’m doing to delete-trailing-whitespace.”

“You could put it in a hook, you know”, said my friend.

“Yes, of course”, I replied, with my best “why I didn’t think of this
before” voice.  “But I need to test whether the buffer is read-only,
else we’d generate lots of beeps”:


(setq-default show-trailing-whitespace nil)

(defun leoboiko/delete-and-show-trailing-whitespace ()
  "If the buffer is not readonly, delete trailing whitespace and turn on
`show-trailing-whitespace'."
  (interactive)
  (if (not buffer-read-only)
      (progn
        (delete-trailing-whitespace)
        (setq show-trailing-whitespace t))))

(add-hook 'hook-for-all-buffers ;; what to put here?
          'leoboiko/delete-and-show-trailing-whitespace)

My first attempt was find-file-hook, but I want it to apply to
non-file buffers too (like email drafts, etc).  My second attempt was
fundamental-mode-hook, but there is no such thing.  My third attempt
(after reading fundamental-mode’s source) was
after-change-major-mode-hook, but this still doesn’t work for
fundamental buffers (say, if I simply create a scratch buffer).

The rationale I saw about why there is no fundamental-mode-hook is
that variable customizations on fundamental mode are really global
customizations.  That’s nice, but I don’t want to change variables, I
want to be able to run arbitrary functions every time a buffer is
created.
--
Leonardo Boiko
http://namakajiri.net






reply via email to

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