Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* another simple question about hooks
@ 2007-11-10 11:58 David Rod
  2007-11-11  9:43 ` Tassilo Horn
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: David Rod @ 2007-11-10 11:58 UTC (permalink / raw)
  To: info-gnus-english


(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 
Also another question.  is there a hook by killing a buffer which
contains a file with the extension as .txt ?

-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: another simple question about hooks
  2007-11-10 11:58 another simple question about hooks David Rod
@ 2007-11-11  9:43 ` Tassilo Horn
  2007-11-12 18:14 ` David Z Maze
       [not found] ` <mailman.3249.1194774209.18990.info-gnus-english@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Tassilo Horn @ 2007-11-11  9:43 UTC (permalink / raw)
  To: info-gnus-english

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: another simple question about hooks
  2007-11-10 11:58 another simple question about hooks David Rod
  2007-11-11  9:43 ` Tassilo Horn
@ 2007-11-12 18:14 ` David Z Maze
  2007-11-12 23:05   ` David Rod
       [not found] ` <mailman.3249.1194774209.18990.info-gnus-english@gnu.org>
  2 siblings, 1 reply; 6+ messages in thread
From: David Z Maze @ 2007-11-12 18:14 UTC (permalink / raw)
  To: info-gnus-english

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 

You probably got a better response on how to call
canonically-space-region with point-min and point-max, but it's good
style to call elisp code that indirectly manipulates the point or mark
inside a save-excursion block as well.  (text-mode-hook might get called
in a context where the point is assumed to be somewhere else, like the
start of the message body.)  The help I have for `C-h f
mark-whole-buffer' states that "it is usually a mistake for a Lisp
function to use any subrouten that uses or sets the mark".

> Also another question.  is there a hook by killing a buffer which
> contains a file with the extension as .txt ?

Not a Gnus question per se, but kill-buffer-hook gets called with the
buffer being killed as the current buffer, so you can look at
buffer-local variables like major-mode to see.

  --dzm

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: another simple question about hooks
       [not found] ` <mailman.3249.1194774209.18990.info-gnus-english@gnu.org>
@ 2007-11-12 22:57   ` David Rod
  0 siblings, 0 replies; 6+ messages in thread
From: David Rod @ 2007-11-12 22:57 UTC (permalink / raw)
  To: info-gnus-english

thankyou for this. it works.
D.
-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: another simple question about hooks
  2007-11-12 18:14 ` David Z Maze
@ 2007-11-12 23:05   ` David Rod
  2007-11-13  7:50     ` Tassilo Horn
  0 siblings, 1 reply; 6+ messages in thread
From: David Rod @ 2007-11-12 23:05 UTC (permalink / raw)
  To: info-gnus-english


> ..., but kill-buffer-hook gets called with the
> buffer being killed as the current buffer, so you can look at
> buffer-local variables like major-mode to see.

How do I look at buffer-local variables?
-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: another simple question about hooks
  2007-11-12 23:05   ` David Rod
@ 2007-11-13  7:50     ` Tassilo Horn
  0 siblings, 0 replies; 6+ messages in thread
From: Tassilo Horn @ 2007-11-13  7:50 UTC (permalink / raw)
  To: info-gnus-english

David Rod <angel_ov_north@tiscali.co.uk> writes:

Hi David,

>> ..., but kill-buffer-hook gets called with the
>> buffer being killed as the current buffer, so you can look at
>> buffer-local variables like major-mode to see.
>
> How do I look at buffer-local variables?

There's no difference than looking to a global variable, e.g.

    (if (eq major-mode 'foobar-mode)
        (do-stuff)
      (do-other-stuff))

(major-mode is always buffer-local.)

Bye,
Tassilo
-- 
My opinions may have changed, but not the fact that I am right.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-11-13  7:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-10 11:58 another simple question about hooks David Rod
2007-11-11  9:43 ` Tassilo Horn
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

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).