[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to apply a minor mode to all buffers
From: |
Kevin Rodgers |
Subject: |
Re: How to apply a minor mode to all buffers |
Date: |
Wed, 07 Feb 2007 00:42:49 -0700 |
User-agent: |
Thunderbird 1.5.0.9 (Macintosh/20061207) |
leoboiko@gmail.com wrote:
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.
Do you do much editing in 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))))
You may still want to show it even if you can't delete it:
(unless buffer-read-only
(delete-trailing-whitespace))
(show-trailing-whitespace)
(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).
How about:
(add-hook 'find-file-hook 'delete/show-trailing-whitespace)
(add-hook 'text-mode-hook 'delete/show-trailing-whitespace)
(setq default-major-mode 'text-mode)
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.
--
Kevin Rodgers
Denver, Colorado, USA
- Re: How to apply a minor mode to all buffers, leoboiko, 2007/02/02
- Re: How to apply a minor mode to all buffers, Stefan Monnier, 2007/02/07
- Re: How to apply a minor mode to all buffers, Robert Thorpe, 2007/02/07
- Re: How to apply a minor mode to all buffers, Leonardo Boiko, 2007/02/08
- Re: How to apply a minor mode to all buffers, Juanma Barranquero, 2007/02/08
- Message not available
- Re: How to apply a minor mode to all buffers, Robert Thorpe, 2007/02/08
- Re: How to apply a minor mode to all buffers, Juanma Barranquero, 2007/02/08
- Message not available
- Re: How to apply a minor mode to all buffers, Robert Thorpe, 2007/02/09
- Re: How to apply a minor mode to all buffers, Juanma Barranquero, 2007/02/09