all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* hook for buffer creation
@ 2010-03-13 17:44 Francis Moreau
  2010-03-15 14:40 ` Lowell Gilbert
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Francis Moreau @ 2010-03-13 17:44 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I'd like to hilight some keywords for any buffers whatever the mode
used for this buffer. In order to achieve that I'd like to use the
hook called when a buffer is created but I can't find it. I only found
the hook used when a buffer is killed.

Could anybody tell me the revelant hook to use ?

Thanks


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

* Re: hook for buffer creation
  2010-03-13 17:44 hook for buffer creation Francis Moreau
@ 2010-03-15 14:40 ` Lowell Gilbert
  2010-03-15 20:37   ` Francis Moreau
  2010-03-17 22:24 ` Colin S. Miller
  2010-05-05  4:39 ` Stefan Monnier
  2 siblings, 1 reply; 10+ messages in thread
From: Lowell Gilbert @ 2010-03-15 14:40 UTC (permalink / raw)
  To: help-gnu-emacs

Francis Moreau <francis.moro@gmail.com> writes:

> I'd like to hilight some keywords for any buffers whatever the mode
> used for this buffer. In order to achieve that I'd like to use the
> hook called when a buffer is created but I can't find it. I only found
> the hook used when a buffer is killed.
>
> Could anybody tell me the revelant hook to use ?

This is a kind of strange request.  There are several options in the
"Standard Hooks" node of the elisp manual (Appendix 1).  If the buffers
will always have files attached, I'd suggest find-file-hook.  Otherwise,
something related to local variables will probably get executed at the
right time.



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

* Re: hook for buffer creation
  2010-03-15 14:40 ` Lowell Gilbert
@ 2010-03-15 20:37   ` Francis Moreau
  2010-03-15 22:16     ` Lowell Gilbert
  0 siblings, 1 reply; 10+ messages in thread
From: Francis Moreau @ 2010-03-15 20:37 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 15, 3:40 pm, Lowell Gilbert <lguse...@be-well.ilk.org> wrote:
> Francis Moreau <francis.m...@gmail.com> writes:
> > I'd like to hilight some keywords for any buffers whatever the mode
> > used for this buffer. In order to achieve that I'd like to use the
> > hook called when a buffer is created but I can't find it. I only found
> > the hook used when a buffer is killed.
>
> > Could anybody tell me the revelant hook to use ?
>
> This is a kind of strange request.  There are several options in the
> "Standard Hooks" node of the elisp manual (Appendix 1).  If the buffers
> will always have files attached, I'd suggest find-file-hook.  Otherwise,
> something related to local variables will probably get executed at the
> right time.

This is a kind of a strange answer :)

So there's no hook for buffer creation if the new buffer is not
attached to a file ?


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

* Re: hook for buffer creation
  2010-03-15 20:37   ` Francis Moreau
@ 2010-03-15 22:16     ` Lowell Gilbert
  0 siblings, 0 replies; 10+ messages in thread
From: Lowell Gilbert @ 2010-03-15 22:16 UTC (permalink / raw)
  To: help-gnu-emacs

Francis Moreau <francis.moro@gmail.com> writes:

> On Mar 15, 3:40 pm, Lowell Gilbert <lguse...@be-well.ilk.org> wrote:
>> Francis Moreau <francis.m...@gmail.com> writes:
>> > I'd like to hilight some keywords for any buffers whatever the mode
>> > used for this buffer. In order to achieve that I'd like to use the
>> > hook called when a buffer is created but I can't find it. I only found
>> > the hook used when a buffer is killed.
>>
>> > Could anybody tell me the revelant hook to use ?
>>
>> This is a kind of strange request.  There are several options in the
>> "Standard Hooks" node of the elisp manual (Appendix 1).  If the buffers
>> will always have files attached, I'd suggest find-file-hook.  Otherwise,
>> something related to local variables will probably get executed at the
>> right time.
>
> This is a kind of a strange answer :)

Yes, I suppose so.  I just can't imagine wanting to apply the same
highlighting to all my buffers, including the minibuffer, *Help*,
and so on.

> So there's no hook for buffer creation if the new buffer is not
> attached to a file ?

I didn't know for sure, so I pointed you in the direction of the
documentation you might find useful.  I've checked now, though,
and I don't *think* there's a hook for that.  switch-to-buffer is
defined in C code, so it's not as easy to look up as Lisp
functions.  You still might want to check the manual item I
suggested, as there are other options I didn't mention.

Putting on my psychic tech-support hat, on the other hand, I'm
going to guess that faced with whatever you're really trying to
do, I'd probably write a minor mode to do the highlighting and use
normal hooks to apply it as appropriate.


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

* Re: hook for buffer creation
  2010-03-13 17:44 hook for buffer creation Francis Moreau
  2010-03-15 14:40 ` Lowell Gilbert
@ 2010-03-17 22:24 ` Colin S. Miller
  2010-03-20 18:45   ` Francis Moreau
                     ` (2 more replies)
  2010-05-05  4:39 ` Stefan Monnier
  2 siblings, 3 replies; 10+ messages in thread
From: Colin S. Miller @ 2010-03-17 22:24 UTC (permalink / raw)
  To: help-gnu-emacs

Francis Moreau wrote:
> Hello,
> 
> I'd like to hilight some keywords for any buffers whatever the mode
> used for this buffer. In order to achieve that I'd like to use the
> hook called when a buffer is created but I can't find it. I only found
> the hook used when a buffer is killed.
> 
> Could anybody tell me the revelant hook to use ?
> 
> Thanks

Francis,

You could use   buffer-list-changed-hook.  It's called whenever
a frame has its buffers modified. You'd need to call (window-list) on
that frame, and then get the buffer for each window. Then check if that
buffer has yet to be processed by your hook

If you want only the text-editing buffers, regardless of the major mode,
then putting a defadvice on fundamental-mode (it doesn't have a hook),
should work. IIRC, all text-edting modes are derived from fundamental-mode,
and its hooks/init function are called.

HTH,
Colin S. Miller


-- 
Replace the obvious in my email address with the first three letters of the hostname to reply.


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

* Re: hook for buffer creation
  2010-03-17 22:24 ` Colin S. Miller
@ 2010-03-20 18:45   ` Francis Moreau
  2010-03-22 15:33     ` Stefan Monnier
  2010-05-04 17:50   ` Dan Davison
       [not found]   ` <mailman.15.1272995469.29092.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 10+ messages in thread
From: Francis Moreau @ 2010-03-20 18:45 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

On 17 mar, 23:24, "Colin S. Miller" <no-spam-
thank-...@csmiller.demon.co.uk> wrote:
>
> You could use   buffer-list-changed-hook.  It's called whenever
> a frame has its buffers modified. You'd need to call (window-list) on
> that frame, and then get the buffer for each window. Then check if that
> buffer has yet to be processed by your hook
>
> If you want only the text-editing buffers, regardless of the major mode,
> then putting a defadvice on fundamental-mode (it doesn't have a hook),
> should work. IIRC, all text-edting modes are derived from fundamental-mode,
> and its hooks/init function are called.

That's a good hint, thanks.


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

* Re: hook for buffer creation
  2010-03-20 18:45   ` Francis Moreau
@ 2010-03-22 15:33     ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2010-03-22 15:33 UTC (permalink / raw)
  To: help-gnu-emacs

>> If you want only the text-editing buffers, regardless of the major mode,
>> then putting a defadvice on fundamental-mode (it doesn't have a hook),
>> should work.

It does have a hook: after-change-major-mode-hook
This was introduced in Emacs-22.1, IIRC.


        Stefan


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

* Re: hook for buffer creation
  2010-03-17 22:24 ` Colin S. Miller
  2010-03-20 18:45   ` Francis Moreau
@ 2010-05-04 17:50   ` Dan Davison
       [not found]   ` <mailman.15.1272995469.29092.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 10+ messages in thread
From: Dan Davison @ 2010-05-04 17:50 UTC (permalink / raw)
  To: Colin S. Miller; +Cc: help-gnu-emacs

"Colin S. Miller" <no-spam-thank-you@csmiller.demon.co.uk> writes:

> Francis Moreau wrote:
>> Hello,
>>
>> I'd like to hilight some keywords for any buffers whatever the mode
>> used for this buffer. In order to achieve that I'd like to use the
>> hook called when a buffer is created but I can't find it. I only found
>> the hook used when a buffer is killed.
>>
>> Could anybody tell me the revelant hook to use ?
>>
>> Thanks
>
> Francis,
>
> You could use   buffer-list-changed-hook.  It's called whenever
> a frame has its buffers modified.

Would change-major-mode-hook be another alternative? I've been trying to
use it recently with the aim of changing things in all buffers.

Dan


> You'd need to call (window-list) on
> that frame, and then get the buffer for each window. Then check if that
> buffer has yet to be processed by your hook
>
> If you want only the text-editing buffers, regardless of the major mode,
> then putting a defadvice on fundamental-mode (it doesn't have a hook),
> should work. IIRC, all text-edting modes are derived from fundamental-mode,
> and its hooks/init function are called.
>
> HTH,
> Colin S. Miller




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

* Re: hook for buffer creation
       [not found]   ` <mailman.15.1272995469.29092.help-gnu-emacs@gnu.org>
@ 2010-05-04 19:49     ` Colin S. Miller
  0 siblings, 0 replies; 10+ messages in thread
From: Colin S. Miller @ 2010-05-04 19:49 UTC (permalink / raw)
  To: help-gnu-emacs

Dan Davison wrote:
> 
> Would change-major-mode-hook be another alternative? I've been trying to
> use it recently with the aim of changing things in all buffers.
> 
> Dan
> 

Francis/Dan,

I'm not sure; it's not defined in 22.2.1, with only the standard libraries loaded.
By the name of it, then it might be a better hook.

Colin S. Miller

-- 
Replace the obvious in my email address with the first three letters of the hostname to reply.


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

* Re: hook for buffer creation
  2010-03-13 17:44 hook for buffer creation Francis Moreau
  2010-03-15 14:40 ` Lowell Gilbert
  2010-03-17 22:24 ` Colin S. Miller
@ 2010-05-05  4:39 ` Stefan Monnier
  2 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2010-05-05  4:39 UTC (permalink / raw)
  To: help-gnu-emacs

> I'd like to hilight some keywords for any buffers whatever the mode
> used for this buffer.  In order to achieve that I'd like to use the
> hook called when a buffer is created but I can't find it.  I only
> found the hook used when a buffer is killed.  Could anybody tell me
> the revelant hook to use ?

You can try `after-change-major-mode-hook', tho it's fairly recent and
will not always be run when you use code that hasn't been updated to
run it.

`change-major-mode-hook' is also an option (more reliable), but it's run
before changing major mode, so any buffer-local var you may modify from
it will be erased right after (it's typically used to turn off
a major-mode dependent minor mode).

You could also use define-globalized-minor-mode (which internally uses
the above): first define the highlighting you want as a buffer-local
minor-mode and then define a global version of it with
define-globalized-minor-mode.


        Stefan


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

end of thread, other threads:[~2010-05-05  4:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-13 17:44 hook for buffer creation Francis Moreau
2010-03-15 14:40 ` Lowell Gilbert
2010-03-15 20:37   ` Francis Moreau
2010-03-15 22:16     ` Lowell Gilbert
2010-03-17 22:24 ` Colin S. Miller
2010-03-20 18:45   ` Francis Moreau
2010-03-22 15:33     ` Stefan Monnier
2010-05-04 17:50   ` Dan Davison
     [not found]   ` <mailman.15.1272995469.29092.help-gnu-emacs@gnu.org>
2010-05-04 19:49     ` Colin S. Miller
2010-05-05  4:39 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.