* new buffer - should its mode reflect its name when the name matches auto-mode-alist?
@ 2009-09-22 14:31 Drew Adams
2009-09-22 14:47 ` Deniz Dogan
0 siblings, 1 reply; 13+ messages in thread
From: Drew Adams @ 2009-09-22 14:31 UTC (permalink / raw
To: emacs-devel
Haven't thought about this before, but I wonder if the mode should respect
auto-mode-alist when you create a new buffer? There's no doubt a good reason or
two why we don't do this - just wondering.
E.g. `C-x b foo.el', where there is no existing buffer foo.el. The mode is
Fundamental; should it be Emacs-Lisp instead?
(I realize that a new buffer need not be intended to be saved as a file.)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-22 14:31 new buffer - should its mode reflect its name when the name matches auto-mode-alist? Drew Adams
@ 2009-09-22 14:47 ` Deniz Dogan
2009-09-22 15:07 ` Drew Adams
0 siblings, 1 reply; 13+ messages in thread
From: Deniz Dogan @ 2009-09-22 14:47 UTC (permalink / raw
To: Drew Adams; +Cc: emacs-devel
2009/9/22 Drew Adams <drew.adams@oracle.com>:
> Haven't thought about this before, but I wonder if the mode should respect
> auto-mode-alist when you create a new buffer? There's no doubt a good reason or
> two why we don't do this - just wondering.
>
> E.g. `C-x b foo.el', where there is no existing buffer foo.el. The mode is
> Fundamental; should it be Emacs-Lisp instead?
>
> (I realize that a new buffer need not be intended to be saved as a file.)
>
As an end-user and not having contributed anything to Emacs myself, I
would expect the buffer to "respect" auto-mode-alist, i.e. set the
mode depending on the buffer name. However, I think the default
behavior when creating buffers non-interactively should *not* respect
auto-mode-alist.
--
Deniz Dogan
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-22 14:47 ` Deniz Dogan
@ 2009-09-22 15:07 ` Drew Adams
2009-09-23 20:50 ` Mathias Dahl
2009-09-24 2:31 ` Kevin Rodgers
0 siblings, 2 replies; 13+ messages in thread
From: Drew Adams @ 2009-09-22 15:07 UTC (permalink / raw
To: 'Deniz Dogan'; +Cc: emacs-devel
> > Haven't thought about this before, but I wonder if the mode
> > should respect auto-mode-alist when you create a new buffer?
> > There's no doubt a good reason or
> > two why we don't do this - just wondering.
> >
> > E.g. `C-x b foo.el', where there is no existing buffer
> > foo.el. The mode is
> > Fundamental; should it be Emacs-Lisp instead?
> >
> > (I realize that a new buffer need not be intended to be
> > saved as a file.)
> >
>
> As an end-user and not having contributed anything to Emacs myself, I
> would expect the buffer to "respect" auto-mode-alist, i.e. set the
> mode depending on the buffer name. However, I think the default
> behavior when creating buffers non-interactively should *not* respect
> auto-mode-alist.
Yes, I meant interactively only, but should have made that clear. Thx.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-22 15:07 ` Drew Adams
@ 2009-09-23 20:50 ` Mathias Dahl
2009-09-24 21:07 ` Juri Linkov
2009-09-24 2:31 ` Kevin Rodgers
1 sibling, 1 reply; 13+ messages in thread
From: Mathias Dahl @ 2009-09-23 20:50 UTC (permalink / raw
To: Drew Adams; +Cc: emacs-devel, Deniz Dogan
I would like this behaviour too. From time to time I also do this and
it is a tiny annoyance that I have to save the file and then revert it
to get the default mode loaded. Of course I sometimes enable the mode
manually as well but for some files I do not always know the mode
name.
On Tue, Sep 22, 2009 at 5:07 PM, Drew Adams <drew.adams@oracle.com> wrote:
>> > Haven't thought about this before, but I wonder if the mode
>> > should respect auto-mode-alist when you create a new buffer?
>> > There's no doubt a good reason or
>> > two why we don't do this - just wondering.
>> >
>> > E.g. `C-x b foo.el', where there is no existing buffer
>> > foo.el. The mode is
>> > Fundamental; should it be Emacs-Lisp instead?
>> >
>> > (I realize that a new buffer need not be intended to be
>> > saved as a file.)
>> >
>>
>> As an end-user and not having contributed anything to Emacs myself, I
>> would expect the buffer to "respect" auto-mode-alist, i.e. set the
>> mode depending on the buffer name. However, I think the default
>> behavior when creating buffers non-interactively should *not* respect
>> auto-mode-alist.
>
> Yes, I meant interactively only, but should have made that clear. Thx.
>
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-22 15:07 ` Drew Adams
2009-09-23 20:50 ` Mathias Dahl
@ 2009-09-24 2:31 ` Kevin Rodgers
2009-09-24 3:14 ` Drew Adams
1 sibling, 1 reply; 13+ messages in thread
From: Kevin Rodgers @ 2009-09-24 2:31 UTC (permalink / raw
To: emacs-devel
Drew Adams wrote:
>>> Haven't thought about this before, but I wonder if the mode
>>> should respect auto-mode-alist when you create a new buffer?
>>> There's no doubt a good reason or
>>> two why we don't do this - just wondering.
>>>
>>> E.g. `C-x b foo.el', where there is no existing buffer
>>> foo.el. The mode is
>>> Fundamental; should it be Emacs-Lisp instead?
>>>
>>> (I realize that a new buffer need not be intended to be
>>> saved as a file.)
>>>
>> As an end-user and not having contributed anything to Emacs myself, I
>> would expect the buffer to "respect" auto-mode-alist, i.e. set the
>> mode depending on the buffer name. However, I think the default
>> behavior when creating buffers non-interactively should *not* respect
>> auto-mode-alist.
>
> Yes, I meant interactively only, but should have made that clear. Thx.
I think I posted this in response to a request on gnu.emacs.help, back around
2008-11-18, but I can't find it via Google:
(defadvice switch-to-buffer (around interactive-normal-mode activate)
"When called interactively to create a new buffer not visiting a file,
temporarily bind `buffer-file-name' and call `normal-mode'."
(let ((existing-buffer (get-buffer (ad-get-arg 0))))
ad-do-it
(when (and (interactive-p)
(null existing-buffer)
(null buffer-file-name))
(let ((buffer-file-name (expand-file-name (buffer-name))))
(normal-mode)))))
Not appropriate for src/buffer.c of course, but you get the idea.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-24 2:31 ` Kevin Rodgers
@ 2009-09-24 3:14 ` Drew Adams
2009-09-24 21:32 ` Juri Linkov
0 siblings, 1 reply; 13+ messages in thread
From: Drew Adams @ 2009-09-24 3:14 UTC (permalink / raw
To: 'Kevin Rodgers', emacs-devel
> >>> Haven't thought about this before, but I wonder if the mode
> >>> should respect auto-mode-alist when you create a new buffer?
> >>> There's no doubt a good reason or
> >>> two why we don't do this - just wondering.
> >>>
> >>> E.g. `C-x b foo.el', where there is no existing buffer
> >>> foo.el. The mode is
> >>> Fundamental; should it be Emacs-Lisp instead?
> >>>
> >>> (I realize that a new buffer need not be intended to be
> >>> saved as a file.)
> >>>
> >> As an end-user and not having contributed anything to
> >> Emacs myself, I would expect the buffer to "respect"
> >> auto-mode-alist, i.e. set the mode depending on the
> >> buffer name. However, I think the default behavior when
> >> creating buffers non-interactively should *not* respect
> >> auto-mode-alist.
> >
> > Yes, I meant interactively only, but should have made that
> > clear. Thx.
>
> I think I posted this in response to a request on
> gnu.emacs.help, back around 2008-11-18, but I can't find it
> via Google:
>
> (defadvice switch-to-buffer (around interactive-normal-mode activate)
> "When called interactively to create a new buffer not
> visiting a file, temporarily bind `buffer-file-name' and call
> `normal-mode'."
> (let ((existing-buffer (get-buffer (ad-get-arg 0))))
> ad-do-it
> (when (and (interactive-p)
> (null existing-buffer)
> (null buffer-file-name))
> (let ((buffer-file-name (expand-file-name (buffer-name))))
> (normal-mode)))))
>
> Not appropriate for src/buffer.c of course, but you get the idea.
Yes, you did - I see it now. You posted it on 2009-11-18, with Subject "emacs
mode line suggestions".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-23 20:50 ` Mathias Dahl
@ 2009-09-24 21:07 ` Juri Linkov
0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2009-09-24 21:07 UTC (permalink / raw
To: Mathias Dahl; +Cc: Deniz Dogan, Drew Adams, emacs-devel
> I would like this behaviour too. From time to time I also do this and
> it is a tiny annoyance that I have to save the file and then revert it
> to get the default mode loaded. Of course I sometimes enable the mode
> manually as well but for some files I do not always know the mode name.
We could add all possible modes to the main menu to allow enabling them
easily from the menu.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-24 3:14 ` Drew Adams
@ 2009-09-24 21:32 ` Juri Linkov
2009-09-24 22:01 ` Drew Adams
2009-09-25 0:38 ` Stefan Monnier
0 siblings, 2 replies; 13+ messages in thread
From: Juri Linkov @ 2009-09-24 21:32 UTC (permalink / raw
To: Drew Adams; +Cc: 'Kevin Rodgers', emacs-devel
>> (defadvice switch-to-buffer (around interactive-normal-mode activate)
>> "When called interactively to create a new buffer not
>> visiting a file, temporarily bind `buffer-file-name' and call
>> `normal-mode'."
>> (let ((existing-buffer (get-buffer (ad-get-arg 0))))
>> ad-do-it
>> (when (and (interactive-p)
>> (null existing-buffer)
>> (null buffer-file-name))
>> (let ((buffer-file-name (expand-file-name (buffer-name))))
>> (normal-mode)))))
>>
>> Not appropriate for src/buffer.c of course, but you get the idea.
>
> Yes, you did - I see it now. You posted it on 2009-11-18, with Subject "emacs
> mode line suggestions".
Do you mean "You will post it on 2009-11-18"?
Well, until it's posted I'd like to present a way to do this without defadvice:
Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.1083
diff -c -r1.1083 files.el
*** lisp/files.el 21 Sep 2009 22:12:30 -0000 1.1083
--- lisp/files.el 24 Sep 2009 21:30:34 -0000
***************
*** 1190,1197 ****
(set (make-local-variable 'icomplete-with-completion-tables)
(cons rbts-completion-table
icomplete-with-completion-tables))))
! (read-buffer prompt (other-buffer (current-buffer))
! (confirm-nonexistent-file-or-buffer)))))
(defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
"Select the buffer specified by BUFFER-OR-NAME in another window.
--- 1190,1202 ----
(set (make-local-variable 'icomplete-with-completion-tables)
(cons rbts-completion-table
icomplete-with-completion-tables))))
! (let ((buffer (read-buffer prompt (other-buffer (current-buffer))
! (confirm-nonexistent-file-or-buffer))))
! (unless (get-buffer buffer)
! (with-current-buffer (get-buffer-create buffer)
! (let ((buffer-file-name (buffer-name)))
! (normal-mode))))
! buffer))))
(defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
"Select the buffer specified by BUFFER-OR-NAME in another window.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-24 21:32 ` Juri Linkov
@ 2009-09-24 22:01 ` Drew Adams
2009-09-25 0:38 ` Stefan Monnier
1 sibling, 0 replies; 13+ messages in thread
From: Drew Adams @ 2009-09-24 22:01 UTC (permalink / raw
To: 'Juri Linkov'; +Cc: 'Kevin Rodgers', emacs-devel
> > > I think I posted this in response to a request on
> > > gnu.emacs.help, back around 2008-11-18, but I can't
> > > find it via Google:
> >
> > Yes, you did - I see it now. You posted it on 2009-11-18,
> > with Subject "emacs mode line suggestions".
>
> Do you mean "You will post it on 2009-11-18"?
No, sorry. I meant to say that Kevin was right that he posted it to
help-gnu-emacs on 2008-11-18. I just wanted to add the Subject line. But I
messed up the date.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-24 21:32 ` Juri Linkov
2009-09-24 22:01 ` Drew Adams
@ 2009-09-25 0:38 ` Stefan Monnier
2009-09-25 9:04 ` Juri Linkov
1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2009-09-25 0:38 UTC (permalink / raw
To: Juri Linkov; +Cc: 'Kevin Rodgers', Drew Adams, emacs-devel
> ***************
> *** 1190,1197 ****
> (set (make-local-variable 'icomplete-with-completion-tables)
> (cons rbts-completion-table
> icomplete-with-completion-tables))))
> ! (read-buffer prompt (other-buffer (current-buffer))
> ! (confirm-nonexistent-file-or-buffer)))))
> (defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
> "Select the buffer specified by BUFFER-OR-NAME in another window.
> --- 1190,1202 ----
> (set (make-local-variable 'icomplete-with-completion-tables)
> (cons rbts-completion-table
> icomplete-with-completion-tables))))
> ! (let ((buffer (read-buffer prompt (other-buffer (current-buffer))
> ! (confirm-nonexistent-file-or-buffer))))
> ! (unless (get-buffer buffer)
> ! (with-current-buffer (get-buffer-create buffer)
> ! (let ((buffer-file-name (buffer-name)))
> ! (normal-mode))))
> ! buffer))))
I'm not opposed to such a change but I think it would need to come
together with a cleanup of the "default-major-mode" thingy: currently,
the major-mode of a buffer is either set (in set-buffer-major-mode) as
(default-value 'major-mode) or (if that's nil) is inherited from the
major-mode of the current-buffer (unless that major-mode has the
`mode-class' property set to `special').
In practice, for 99% of the users, (default-value 'major-mode) is
fundamental-mode, so the rest is very rarely used, which can lead to
corner-case bugs, of course.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-25 0:38 ` Stefan Monnier
@ 2009-09-25 9:04 ` Juri Linkov
2009-09-25 14:16 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2009-09-25 9:04 UTC (permalink / raw
To: Stefan Monnier; +Cc: 'Kevin Rodgers', Drew Adams, emacs-devel
> I'm not opposed to such a change but I think it would need to come
> together with a cleanup of the "default-major-mode" thingy: currently,
> the major-mode of a buffer is either set (in set-buffer-major-mode) as
> (default-value 'major-mode) or (if that's nil) is inherited from the
> major-mode of the current-buffer (unless that major-mode has the
> `mode-class' property set to `special').
>
> In practice, for 99% of the users, (default-value 'major-mode) is
> fundamental-mode, so the rest is very rarely used, which can lead to
> corner-case bugs, of course.
Using (setq-default major-mode 'normal-mode) would be a good default.
Currently this runs into an infinite recursion. However, the following
succeeds:
(setq-default major-mode
(lambda () (let ((buffer-file-name (buffer-name)))
(set-auto-mode))))
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-25 9:04 ` Juri Linkov
@ 2009-09-25 14:16 ` Stefan Monnier
2009-09-29 23:11 ` Juri Linkov
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2009-09-25 14:16 UTC (permalink / raw
To: Juri Linkov; +Cc: 'Kevin Rodgers', Drew Adams, emacs-devel
>> I'm not opposed to such a change but I think it would need to come
>> together with a cleanup of the "default-major-mode" thingy: currently,
>> the major-mode of a buffer is either set (in set-buffer-major-mode) as
>> (default-value 'major-mode) or (if that's nil) is inherited from the
>> major-mode of the current-buffer (unless that major-mode has the
>> `mode-class' property set to `special').
>>
>> In practice, for 99% of the users, (default-value 'major-mode) is
>> fundamental-mode, so the rest is very rarely used, which can lead to
>> corner-case bugs, of course.
> Using (setq-default major-mode 'normal-mode) would be a good default.
> Currently this runs into an infinite recursion. However, the following
> succeeds:
> (setq-default major-mode
> (lambda () (let ((buffer-file-name (buffer-name)))
> (set-auto-mode))))
That's also an alternative, yes.
So how 'bout the following:
- we (setq-default major-mode ..) along the lines of the above proposal.
- we get rid of the special case "or (if that's nil) is inherited from
the major-mode of the current-buffer (unless that major-mode has the
`mode-class' property set to `special')."
- but we only do that for Emacs-24.
The reason why I want to delay it to Emacs-24, is because I'm worried
that it may introduce bugs in very rare corner cases which will only
show up after a long testing period.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
2009-09-25 14:16 ` Stefan Monnier
@ 2009-09-29 23:11 ` Juri Linkov
0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2009-09-29 23:11 UTC (permalink / raw
To: Stefan Monnier; +Cc: 'Kevin Rodgers', Drew Adams, emacs-devel
>> (setq-default major-mode
>> (lambda () (let ((buffer-file-name (buffer-name)))
>> (set-auto-mode))))
>
> That's also an alternative, yes.
> So how 'bout the following:
> - we (setq-default major-mode ..) along the lines of the above proposal.
> - we get rid of the special case "or (if that's nil) is inherited from
> the major-mode of the current-buffer (unless that major-mode has the
> `mode-class' property set to `special')."
> - but we only do that for Emacs-24.
>
> The reason why I want to delay it to Emacs-24, is because I'm worried
> that it may introduce bugs in very rare corner cases which will only
> show up after a long testing period.
For a long testing period we could make this change now, and remove it
before releasing the next version. How otherwise we can find all
corner cases. For instance, using the the setting above exposed
one weird case: during visiting a tar archive it proposes to revert
the just visited archive file. So visiting a file doesn't work correctly
with default modes besides the standard fundamental-mode. The following
default value would be better:
(setq-default major-mode
(lambda ()
(if buffer-file-name
'fundamental-mode
(let ((buffer-file-name (buffer-name)))
(set-auto-mode)))))
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2009-09-29 23:11 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-22 14:31 new buffer - should its mode reflect its name when the name matches auto-mode-alist? Drew Adams
2009-09-22 14:47 ` Deniz Dogan
2009-09-22 15:07 ` Drew Adams
2009-09-23 20:50 ` Mathias Dahl
2009-09-24 21:07 ` Juri Linkov
2009-09-24 2:31 ` Kevin Rodgers
2009-09-24 3:14 ` Drew Adams
2009-09-24 21:32 ` Juri Linkov
2009-09-24 22:01 ` Drew Adams
2009-09-25 0:38 ` Stefan Monnier
2009-09-25 9:04 ` Juri Linkov
2009-09-25 14:16 ` Stefan Monnier
2009-09-29 23:11 ` Juri Linkov
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.