emacs-devel
[Top][All Lists]
Advanced

[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: Juri Linkov
Subject: Re: new buffer - should its mode reflect its name when the name matches auto-mode-alist?
Date: Fri, 25 Sep 2009 00:32:18 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

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




reply via email to

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