help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs mode line suggestions


From: Alan Mackenzie
Subject: Re: emacs mode line suggestions
Date: Tue, 18 Nov 2008 09:58:22 +0000
User-agent: Mutt/1.5.9i

Hi, Kevin!

On Tue, Nov 18, 2008 at 02:32:00AM -0700, Kevin Rodgers wrote:
> Alan Mackenzie wrote:
> >>Usually, creating a new file with C-x C-f already switches on the
> >>right mode.  And even if Emacs somehow gets this wrong, it's a
> >>one-time event for that buffer.

> >However, if I create a new buffer with C-x C-b foo.c, it starts in
> >Fundamental Mode, not C Mode.  Is there a good reason for this, or did
> >it just happen?  It irritates me quite a bit, but not quite enough to
> >bring me to fixing it.  ;-)

> I think the reason is that auto-mode-alist applies only to file names.
> I suppose it is arguable whether that is a good reason or not, but
> "fixing" it to apply to buffer names would be a pretty far-reaching
> change.

OK.  It's one of these things which is just "so obviously" the only Right
Thing.  Like other such things, it's regarded differently by other
people.

> Maybe this would work for you:

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

Hey, Kevin, you're a true gentleman!  Many thanks!

> Kevin Rodgers

-- 
Alan Mackenzie (Nuremberg, Germany).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]