Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: info-gnus-english@gnu.org
Subject: Re: another simple question about hooks
Date: Sun, 11 Nov 2007 10:43:09 +0100	[thread overview]
Message-ID: <87zlxlw21e.fsf@baldur.tsdh.de> (raw)
In-Reply-To: <upryis46l.fsf@tiscali.co.uk>

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

  reply	other threads:[~2007-11-11  9:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-10 11:58 David Rod
2007-11-11  9:43 ` Tassilo Horn [this message]
2007-11-12 18:14 ` David Z Maze
2007-11-12 23:05   ` David Rod
2007-11-13  7:50     ` Tassilo Horn
     [not found] ` <mailman.3249.1194774209.18990.info-gnus-english@gnu.org>
2007-11-12 22:57   ` David Rod

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zlxlw21e.fsf@baldur.tsdh.de \
    --to=tassilo@member.fsf.org \
    --cc=info-gnus-english@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).