[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another simple question about hooks
From: |
Tassilo Horn |
Subject: |
Re: another simple question about hooks |
Date: |
Sun, 11 Nov 2007 10:43:09 +0100 |
User-agent: |
Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux) |
David Rod <angel_ov_north@tiscali.co.uk> writes:
> (defun david-r-turn-on-text-stuff ()
> (flyspell-mode 1)
> (abbrev-mode 1)
> )
>
> (add-hook 'text-mode-hook 'david-r-turn-on-text-stuff)
>
> this works fine. I want to add a (mark-whole-buffer)
> (canonically-space-region)
> Whenever I try this, this renders new messages and follow-ups
> by gnus inoperable
The problem is that message-mode is derived from text-mode, so when a
buffer switches to message-mode text-mode-hook is run, too.
Try this one. It should run canonically-space-region only if you're not
in message-mode.
--8<---------------cut here---------------start------------->8---
(defun david-r-turn-on-text-stuff ()
(flyspell-mode 1)
(abbrev-mode 1)
(unless (eq major-mode 'message-mode)
(canonically-space-region (point-min)
(point-max))))
--8<---------------cut here---------------end--------------->8---
> Also another question. is there a hook by killing a buffer which
> contains a file with the extension as .txt ?
No, but you can check that in the hook's function.
--8<---------------cut here---------------start------------->8---
(defun foo ()
(if (and buffer-file-name
(string= (file-name-extension buffer-file-name) "txt"))
(do-stuff-for-text-files)
(do-stuff-for-non-text-files)))
(add-hook 'kill-buffer-hook 'foo)
--8<---------------cut here---------------end--------------->8---
Bye,
Tassilo