unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* auto-revert-mode
@ 2010-09-14  8:24 Gary
  2010-09-14  9:06 ` auto-revert-mode Deniz Dogan
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Gary @ 2010-09-14  8:24 UTC (permalink / raw)
  To: help-gnu-emacs

I know I can use M-x auto-revert-mode to turn this on manually on a per
buffer basis, but is there any way to do so for all files matching the
pattern ".*\.foo" (for example)? I tried adding it to the mode hook
related to "foo" files but it didn't work for some reason.

-- 
Gary        Please do NOT send me 'courtesy' replies off-list.
GNU Emacs 23.2.1
emacsclient 23.2
1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin




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

* Re: auto-revert-mode
  2010-09-14  8:24 auto-revert-mode Gary
@ 2010-09-14  9:06 ` Deniz Dogan
  2010-09-14  9:35   ` auto-revert-mode Gary
  2010-09-14  9:17 ` auto-revert-mode Oleksandr Gavenko
       [not found] ` <mailman.5.1284455865.12957.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 14+ messages in thread
From: Deniz Dogan @ 2010-09-14  9:06 UTC (permalink / raw)
  To: help-gnu-emacs

2010/9/14 Gary <help-gnu-emacs@garydjones.name>:
> I know I can use M-x auto-revert-mode to turn this on manually on a per
> buffer basis, but is there any way to do so for all files matching the
> pattern ".*\.foo" (for example)? I tried adding it to the mode hook
> related to "foo" files but it didn't work for some reason.
>
> --
> Gary        Please do NOT send me 'courtesy' replies off-list.
> GNU Emacs 23.2.1
> emacsclient 23.2
> 1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin
>
>
>

This seems to work for me:

(add-hook 'find-file-hook 'auto-revert-mode)

That will affect all files and file extensions. I can't see any reason
why it wouldn't work for just about any hook. Are you sure
foo-mode-hook is executed at all?

As a last resort, you can use something like this (untested):

(add-hook
 'find-file-hook
 (lambda ()
   (when (string-match "\\.foo\\'" buffer-file-name)
     (auto-revert-mode 1))))

-- 
Deniz Dogan



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

* Re: auto-revert-mode
  2010-09-14  8:24 auto-revert-mode Gary
  2010-09-14  9:06 ` auto-revert-mode Deniz Dogan
@ 2010-09-14  9:17 ` Oleksandr Gavenko
  2010-09-14  9:49   ` auto-revert-mode Gary
                     ` (2 more replies)
       [not found] ` <mailman.5.1284455865.12957.help-gnu-emacs@gnu.org>
  2 siblings, 3 replies; 14+ messages in thread
From: Oleksandr Gavenko @ 2010-09-14  9:17 UTC (permalink / raw)
  To: help-gnu-emacs

On 14.09.2010 11:24, Gary wrote:
> I know I can use M-x auto-revert-mode to turn this on manually on a per
> buffer basis, but is there any way to do so for all files matching the
> pattern ".*\.foo" (for example)? I tried adding it to the mode hook
> related to "foo" files but it didn't work for some reason.
>

(add-to-list
  'find-file-hook
  (lambda nil
    (when (equal (file-name-extension (buffer-file-name)) "log")
        (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
        )))

I don't know more efficient way to do this.




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

* Re: auto-revert-mode
  2010-09-14  9:06 ` auto-revert-mode Deniz Dogan
@ 2010-09-14  9:35   ` Gary
  0 siblings, 0 replies; 14+ messages in thread
From: Gary @ 2010-09-14  9:35 UTC (permalink / raw)
  To: help-gnu-emacs

Deniz Dogan wrote:
> 2010/9/14 Gary :
>> I know I can use M-x auto-revert-mode to turn this on manually on a per
>> buffer basis, but is there any way to do so for all files matching the
>> pattern ".*\.foo" (for example)? I tried adding it to the mode hook
>> related to "foo" files but it didn't work for some reason.

> This seems to work for me:
>
> (add-hook 'find-file-hook 'auto-revert-mode)
>
> That will affect all files and file extensions. I can't see any reason
> why it wouldn't work for just about any hook. Are you sure
> foo-mode-hook is executed at all?

Umm... err... Look! What's that over there? *points and runs away

I, ahh, had a stale .elc :D Thanks for pointing it out :)

-- 
Gary        Please do NOT send me 'courtesy' replies off-list.
GNU Emacs 23.2.1
emacsclient 23.2
1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin




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

* Re: auto-revert-mode
  2010-09-14  9:17 ` auto-revert-mode Oleksandr Gavenko
@ 2010-09-14  9:49   ` Gary
  2010-09-14 18:32   ` auto-revert-mode Thamer Mahmoud
       [not found]   ` <mailman.3.1284489201.20547.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 14+ messages in thread
From: Gary @ 2010-09-14  9:49 UTC (permalink / raw)
  To: help-gnu-emacs

Oleksandr Gavenko wrote:
> (add-to-list
>  'find-file-hook
>  (lambda nil
>    (when (equal (file-name-extension (buffer-file-name)) "log")
>        (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
>        )))
>
> I don't know more efficient way to do this.

Actually I really like this. I have two types of file associated with
the mode in question, one of which is generated from the other, that is
why I want to automatically revert the generated files when I generate
them from the originals. Your solution allows me to differentiate between
the two. Thanks!

-- 
Gary        Please do NOT send me 'courtesy' replies off-list.
GNU Emacs 23.2.1
emacsclient 23.2
1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin




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

* Re: auto-revert-mode
       [not found] ` <mailman.5.1284455865.12957.help-gnu-emacs@gnu.org>
@ 2010-09-14 14:39   ` Stefan Monnier
  0 siblings, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2010-09-14 14:39 UTC (permalink / raw)
  To: help-gnu-emacs

> (add-to-list
>  'find-file-hook

Please use add-hook when adding things to hooks.
Otherwise you may be surprised when applying add-to-list to a hook that
was made buffer-local.


        Stefan


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

* Re: auto-revert-mode
  2010-09-14  9:17 ` auto-revert-mode Oleksandr Gavenko
  2010-09-14  9:49   ` auto-revert-mode Gary
@ 2010-09-14 18:32   ` Thamer Mahmoud
  2010-09-14 19:33     ` auto-revert-mode Oleksandr Gavenko
       [not found]   ` <mailman.3.1284489201.20547.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 14+ messages in thread
From: Thamer Mahmoud @ 2010-09-14 18:32 UTC (permalink / raw)
  To: help-gnu-emacs

Oleksandr Gavenko <gavenko@bifit.com.ua> writes:
>
> (add-to-list
>  'find-file-hook
>  (lambda nil
>    (when (equal (file-name-extension (buffer-file-name)) "log")
>        (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
>        )))
>
> I don't know more efficient way to do this.
>

Here is another solution:

(add-to-list 'auto-mode-alist 
	     '("\\.foo\\'" (lambda () (auto-revert-mode 1)) t))

-- 
Thamer




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

* Re: auto-revert-mode
       [not found]   ` <mailman.3.1284489201.20547.help-gnu-emacs@gnu.org>
@ 2010-09-14 19:23     ` Andreas Politz
  2010-09-15  8:31       ` auto-revert-mode Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Andreas Politz @ 2010-09-14 19:23 UTC (permalink / raw)
  To: help-gnu-emacs

Thamer Mahmoud <thamer.mahmoud@gmail.com> writes:

> Oleksandr Gavenko <gavenko@bifit.com.ua> writes:
>>
>> (add-to-list
>>  'find-file-hook
>>  (lambda nil
>>    (when (equal (file-name-extension (buffer-file-name)) "log")
>>        (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
>>        )))
>>
>> I don't know more efficient way to do this.
>>
>
> Here is another solution:
>
> (add-to-list 'auto-mode-alist 
> 	     '("\\.foo\\'" (lambda () (auto-revert-mode 1)) t))

With the sideeffect of inhibiting the proper major-mode for .foo files.
Maybe this calls for another variable `auto-minor-mode-alist'.

-ap


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

* Re: auto-revert-mode
  2010-09-14 18:32   ` auto-revert-mode Thamer Mahmoud
@ 2010-09-14 19:33     ` Oleksandr Gavenko
  2010-09-14 22:54       ` auto-revert-mode Thamer Mahmoud
  0 siblings, 1 reply; 14+ messages in thread
From: Oleksandr Gavenko @ 2010-09-14 19:33 UTC (permalink / raw)
  To: help-gnu-emacs

Thamer Mahmoud wrote:
> Oleksandr Gavenko <gavenko@bifit.com.ua> writes:
>> (add-to-list
>>  'find-file-hook
>>  (lambda nil
>>    (when (equal (file-name-extension (buffer-file-name)) "log")
>>        (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
>>        )))
>>
>> I don't know more efficient way to do this.
>>
> 
> Here is another solution:
> 
> (add-to-list 'auto-mode-alist 
> 	     '("\\.foo\\'" (lambda () (auto-revert-mode 1)) t))
> 

auto-mode-alist is a variable defined in `files.el'.
Documentation:
Alist of filename patterns vs corresponding major mode functions.
...
If the element has the form (REGEXP FUNCTION NON-NIL), then after
calling FUNCTION (if it's not nil), we delete the suffix that matched
REGEXP and search the list again for another match.


So if my file has name my.c.foo and I open it I got
file in major c-mode and minor auto-revert-mode!


Beside side effect of this hack for me interesting
how 'auto-mode-alist' processed - invoke major mode once for first
regex match on for all matches?

So if for your .foo extension desired some major mode
you may hid it by minor mode!

-- 
Best regards!




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

* Re: auto-revert-mode
  2010-09-14 19:33     ` auto-revert-mode Oleksandr Gavenko
@ 2010-09-14 22:54       ` Thamer Mahmoud
  2010-09-15  5:00         ` auto-revert-mode Deniz Dogan
  0 siblings, 1 reply; 14+ messages in thread
From: Thamer Mahmoud @ 2010-09-14 22:54 UTC (permalink / raw)
  To: help-gnu-emacs

Oleksandr Gavenko <gavenkoa@gmail.com> writes:

> Thamer Mahmoud wrote:
>> Here is another solution:
>>
>> (add-to-list 'auto-mode-alist 	     '("\\.foo\\'" (lambda ()
>> (auto-revert-mode 1)) t))
[...]
>
> So if for your .foo extension desired some major mode
> you may hid it by minor mode!

Yes, you're right. I used the code above for an extension that Emacs
doesn't yet know about (with no major-mode, and no major-mode
hook). However, it's possible to set both the major and minor mode for
one extension using the following:

(add-to-list 'auto-mode-alist 
	     '("\\.foo\\'" . (lambda () (c-mode) (auto-revert-mode 1))))

Perhaps it would be useful if Emacs had an `auto-minor-mode-alist'
variable, i.e., a list of minor modes that are enabled based on file
name without bothering with major modes.

-- 
Thamer




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

* Re: auto-revert-mode
  2010-09-14 22:54       ` auto-revert-mode Thamer Mahmoud
@ 2010-09-15  5:00         ` Deniz Dogan
  0 siblings, 0 replies; 14+ messages in thread
From: Deniz Dogan @ 2010-09-15  5:00 UTC (permalink / raw)
  To: Thamer Mahmoud; +Cc: help-gnu-emacs

2010/9/15 Thamer Mahmoud <thamer.mahmoud@gmail.com>:
> Oleksandr Gavenko <gavenkoa@gmail.com> writes:
>
>> Thamer Mahmoud wrote:
>>> Here is another solution:
>>>
>>> (add-to-list 'auto-mode-alist             '("\\.foo\\'" (lambda ()
>>> (auto-revert-mode 1)) t))
> [...]
>>
>> So if for your .foo extension desired some major mode
>> you may hid it by minor mode!
>
> Yes, you're right. I used the code above for an extension that Emacs
> doesn't yet know about (with no major-mode, and no major-mode
> hook). However, it's possible to set both the major and minor mode for
> one extension using the following:
>
> (add-to-list 'auto-mode-alist
>             '("\\.foo\\'" . (lambda () (c-mode) (auto-revert-mode 1))))
>
> Perhaps it would be useful if Emacs had an `auto-minor-mode-alist'
> variable, i.e., a list of minor modes that are enabled based on file
> name without bothering with major modes.
>

I think that any respectable major mode should provide an appropriable
foo-mode-hook instead.

-- 
Deniz Dogan



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

* Re: auto-revert-mode
  2010-09-14 19:23     ` auto-revert-mode Andreas Politz
@ 2010-09-15  8:31       ` Stefan Monnier
  2010-09-15 10:29         ` auto-revert-mode Andreas Politz
  2010-09-15 10:31         ` auto-revert-mode Andreas Politz
  0 siblings, 2 replies; 14+ messages in thread
From: Stefan Monnier @ 2010-09-15  8:31 UTC (permalink / raw)
  To: help-gnu-emacs

>>> (add-to-list
>>> 'find-file-hook
>>> (lambda nil
>>> (when (equal (file-name-extension (buffer-file-name)) "log")
>>> (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
>>> )))
>>> 
>>> I don't know more efficient way to do this.
>>> 
>> 
>> Here is another solution:
>> 
>> (add-to-list 'auto-mode-alist 
>> '("\\.foo\\'" (lambda () (auto-revert-mode 1)) t))

In Emacs-24 you'll be able to just say

   (add-to-list 'auto-mode-alist '("\\.foo\\'" auto-revert-mode t))

> With the sideeffect of inhibiting the proper major-mode for .foo files.
> Maybe this calls for another variable `auto-minor-mode-alist'.

No, the t he put at the end tells Emacs to keep looking for a major mode
(but I'm not sure if his incantation will work because the subsequent
call to the major mode may end up turning off auto-revert-mode, I'm
afraid).


        Stefan


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

* Re: auto-revert-mode
  2010-09-15  8:31       ` auto-revert-mode Stefan Monnier
@ 2010-09-15 10:29         ` Andreas Politz
  2010-09-15 10:31         ` auto-revert-mode Andreas Politz
  1 sibling, 0 replies; 14+ messages in thread
From: Andreas Politz @ 2010-09-15 10:29 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>>> (add-to-list
>>>> 'find-file-hook
>>>> (lambda nil
>>>> (when (equal (file-name-extension (buffer-file-name)) "log")
>>>> (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
>>>> )))
>>>> 
>>>> I don't know more efficient way to do this.
>>>> 
>>> 
>>> Here is another solution:
>>> 
>>> (add-to-list 'auto-mode-alist 
>>> '("\\.foo\\'" (lambda () (auto-revert-mode 1)) t))
>
> In Emacs-24 you'll be able to just say
>
>    (add-to-list 'auto-mode-alist '("\\.foo\\'" auto-revert-mode t))
>
>> With the sideeffect of inhibiting the proper major-mode for .foo files.
>> Maybe this calls for another variable `auto-minor-mode-alist'.
>
> No, the t he put at the end tells Emacs to keep looking for a major mode

But with the extension removed.  At least that's how the 3rd value is
explained in the documentation.

-ap


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

* Re: auto-revert-mode
  2010-09-15  8:31       ` auto-revert-mode Stefan Monnier
  2010-09-15 10:29         ` auto-revert-mode Andreas Politz
@ 2010-09-15 10:31         ` Andreas Politz
  1 sibling, 0 replies; 14+ messages in thread
From: Andreas Politz @ 2010-09-15 10:31 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>>> (add-to-list
>>>> 'find-file-hook
>>>> (lambda nil
>>>> (when (equal (file-name-extension (buffer-file-name)) "log")
>>>> (auto-revert-mode 1) ;; or (auto-revert-tail-mode 1) !!
>>>> )))
>>>>
>>>> I don't know more efficient way to do this.
>>>>
>>>
>>> Here is another solution:
>>>
>>> (add-to-list 'auto-mode-alist
>>> '("\\.foo\\'" (lambda () (auto-revert-mode 1)) t))
>
> In Emacs-24 you'll be able to just say
>
>    (add-to-list 'auto-mode-alist '("\\.foo\\'" auto-revert-mode t))
>
>> With the sideeffect of inhibiting the proper major-mode for .foo files.
>> Maybe this calls for another variable `auto-minor-mode-alist'.
>
> No, the t he put at the end tells Emacs to keep looking for a major mode

But with the extension removed.  At least that's how the 3rd value is
explained in the documentation.

-ap


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

end of thread, other threads:[~2010-09-15 10:31 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-14  8:24 auto-revert-mode Gary
2010-09-14  9:06 ` auto-revert-mode Deniz Dogan
2010-09-14  9:35   ` auto-revert-mode Gary
2010-09-14  9:17 ` auto-revert-mode Oleksandr Gavenko
2010-09-14  9:49   ` auto-revert-mode Gary
2010-09-14 18:32   ` auto-revert-mode Thamer Mahmoud
2010-09-14 19:33     ` auto-revert-mode Oleksandr Gavenko
2010-09-14 22:54       ` auto-revert-mode Thamer Mahmoud
2010-09-15  5:00         ` auto-revert-mode Deniz Dogan
     [not found]   ` <mailman.3.1284489201.20547.help-gnu-emacs@gnu.org>
2010-09-14 19:23     ` auto-revert-mode Andreas Politz
2010-09-15  8:31       ` auto-revert-mode Stefan Monnier
2010-09-15 10:29         ` auto-revert-mode Andreas Politz
2010-09-15 10:31         ` auto-revert-mode Andreas Politz
     [not found] ` <mailman.5.1284455865.12957.help-gnu-emacs@gnu.org>
2010-09-14 14:39   ` auto-revert-mode Stefan Monnier

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 read-only IMAP folder(s) and NNTP newsgroup(s).