[Top][All Lists]

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

Re: new buffer - should its mode reflect its name when the name matches

From: Kevin Rodgers
Subject: Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
Date: Wed, 23 Sep 2009 20:31:45 -0600
User-agent: Thunderbird (Macintosh/20090812)

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

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))))
    (when (and (interactive-p)
               (null existing-buffer)
               (null buffer-file-name))
      (let ((buffer-file-name (expand-file-name (buffer-name))))

Not appropriate for src/buffer.c of course, but you get the idea.

Kevin Rodgers
Denver, Colorado, USA

reply via email to

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