unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] lisp/files.el and lisp/buf-menu.el
@ 2009-07-16 20:47 Thomas Lord
  2009-07-17  3:08 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Lord @ 2009-07-16 20:47 UTC (permalink / raw)
  To: emacs-devel

As earlier explained, I have the case of creating
a buffer with no visited file, yet I would like 
to use (normal-mode) to set the mode AS IF the 
name of the visited file was a particular string.

It was also pointed out to me that I should make
sure "list-buffers-noselect" puts something helpful
where a file name would usually go.

I have accordingly patched lisp/files.el and lisp/buf-menu.el.

First, I'll just walk through the simple patches.
Then I'll include the patches at the end without 
the narrative.

To lisp/files.el:

$ diff -c files.el.~1.1052.~ files.el
*** files.el.~1.1052.~	2009-06-22 00:02:08.000000000 -0700
--- files.el	2009-07-16 13:21:21.000000000 -0700
***************
*** 2428,2433 ****
--- 2428,2437 ----
    "Upper limit on `magic-mode-alist' regexp matches.
  Also applies to `magic-fallback-mode-alist'.")
  
+ (defvar buffer-automode-file-name ()
+   "If not nil, use this rather than `buffer-file-name' for automode.")
+ (make-variable-buffer-local 'buffer-automode-file-name)
+ 
  (defun set-auto-mode (&optional keep-mode-if-same)
    "Select major mode appropriate for current buffer.



If that variable is dynamically bound, it overrides
BUFFER-FILE-NAME in SET-AUTO-MODE.

A typical use is:

    (let ((automode-file-name my-name-for-mode-purposes))
      (normal-mode))


And here is how that works in SET-AUTO-MODE:

  
***************
*** 2515,2523 ****
  	  (set-auto-mode-0 done keep-mode-if-same)))
      ;; Next compare the filename against the entries in
auto-mode-alist.
      (unless done
!       (if buffer-file-name
! 	  (let ((name buffer-file-name)
! 		(remote-id (file-remote-p buffer-file-name)))
  	    ;; Remove remote file name identification.
  	    (when (and (stringp remote-id)
  		       (string-match (regexp-quote remote-id) name))
--- 2519,2527 ----
  	  (set-auto-mode-0 done keep-mode-if-same)))
      ;; Next compare the filename against the entries in
auto-mode-alist.
      (unless done
!       (if (or buffer-automode-file-name buffer-file-name)
! 	  (let ((name (or buffer-automode-file-name buffer-file-name))
! 		(remote-id (and (not buffer-automode-file-name) (file-remote-p
buffer-file-name))))
  	    ;; Remove remote file name identification.
  	    (when (and (stringp remote-id)
  		       (string-match (regexp-quote remote-id) name))




Next, I would like to customize the string that
appears in the "file column" of a buffer menu:


$ diff -c buff-menu.el.~1.125.~ buff-menu.el
*** buff-menu.el.~1.125.~	2009-01-15 08:46:09.000000000 -0800
--- buff-menu.el	2009-07-16 13:29:51.000000000 -0700
***************
*** 755,760 ****
--- 755,764 ----
  	      'mouse-face 'highlight
  	      'keymap Buffer-menu-sort-button-map))
  
+ (defvar list-buffers-description ()
+   "If not nil, use in place of a file name in a buffer menu.")
+ (make-variable-buffer-local 'list-buffers-description)
+ 
  (defun list-buffers-noselect (&optional files-only buffer-list)
    "Create and return a buffer with a list of names of existing
buffers.
  The buffer is named `*Buffer List*'.



That new variable works EXACTLY LIKE the existing
variable LIST-BUFFERS-DIRECTORY except that the new
variable has a more general name, has a doc string,
and takes precedence over LIST-BUFFERS-DIRECTORY


It works trivially (in LIST-BUFFERS-NOSELECT):


***************
*** 842,848 ****
  		  ;; No visited file.  Check local value of
  		  ;; list-buffers-directory and, for Info buffers,
  		  ;; Info-current-file.
! 		  (cond ((and (boundp 'list-buffers-directory)
  			      list-buffers-directory)
  			 (setq file list-buffers-directory))
  			((eq major-mode 'Info-mode)
--- 846,855 ----
  		  ;; No visited file.  Check local value of
  		  ;; list-buffers-directory and, for Info buffers,
  		  ;; Info-current-file.
! 		  (cond ((and (boundp 'list-buffers-description)
!                               list-buffers-description)
!                          (setq file list-buffers-description))
!                         ((and (boundp 'list-buffers-directory)
  			      list-buffers-directory)
  			 (setq file list-buffers-directory))
  			((eq major-mode 'Info-mode)




-t

The patches without interruption:


$ diff -c files.el.~1.1052.~ files.el
*** files.el.~1.1052.~	2009-06-22 00:02:08.000000000 -0700
--- files.el	2009-07-16 13:21:21.000000000 -0700
***************
*** 2428,2433 ****
--- 2428,2437 ----
    "Upper limit on `magic-mode-alist' regexp matches.
  Also applies to `magic-fallback-mode-alist'.")
  
+ (defvar buffer-automode-file-name ()
+   "If not nil, use this rather than `buffer-file-name' for automode.")
+ (make-variable-buffer-local 'buffer-automode-file-name)
+ 
  (defun set-auto-mode (&optional keep-mode-if-same)
    "Select major mode appropriate for current buffer.
  
***************
*** 2515,2523 ****
  	  (set-auto-mode-0 done keep-mode-if-same)))
      ;; Next compare the filename against the entries in
auto-mode-alist.
      (unless done
!       (if buffer-file-name
! 	  (let ((name buffer-file-name)
! 		(remote-id (file-remote-p buffer-file-name)))
  	    ;; Remove remote file name identification.
  	    (when (and (stringp remote-id)
  		       (string-match (regexp-quote remote-id) name))
--- 2519,2527 ----
  	  (set-auto-mode-0 done keep-mode-if-same)))
      ;; Next compare the filename against the entries in
auto-mode-alist.
      (unless done
!       (if (or buffer-automode-file-name buffer-file-name)
! 	  (let ((name (or buffer-automode-file-name buffer-file-name))
! 		(remote-id (and (not buffer-automode-file-name) (file-remote-p
buffer-file-name))))
  	    ;; Remove remote file name identification.
  	    (when (and (stringp remote-id)
  		       (string-match (regexp-quote remote-id) name))





$ diff -c buff-menu.el.~1.125.~ buff-menu.el
*** buff-menu.el.~1.125.~	2009-01-15 08:46:09.000000000 -0800
--- buff-menu.el	2009-07-16 13:29:51.000000000 -0700
***************
*** 755,760 ****
--- 755,764 ----
  	      'mouse-face 'highlight
  	      'keymap Buffer-menu-sort-button-map))
  
+ (defvar list-buffers-description ()
+   "If not nil, use in place of a file name in a buffer menu.")
+ (make-variable-buffer-local 'list-buffers-description)
+ 
  (defun list-buffers-noselect (&optional files-only buffer-list)
    "Create and return a buffer with a list of names of existing
buffers.
  The buffer is named `*Buffer List*'.
***************
*** 842,848 ****
  		  ;; No visited file.  Check local value of
  		  ;; list-buffers-directory and, for Info buffers,
  		  ;; Info-current-file.
! 		  (cond ((and (boundp 'list-buffers-directory)
  			      list-buffers-directory)
  			 (setq file list-buffers-directory))
  			((eq major-mode 'Info-mode)
--- 846,855 ----
  		  ;; No visited file.  Check local value of
  		  ;; list-buffers-directory and, for Info buffers,
  		  ;; Info-current-file.
! 		  (cond ((and (boundp 'list-buffers-description)
!                               list-buffers-description)
!                          (setq file list-buffers-description))
!                         ((and (boundp 'list-buffers-directory)
  			      list-buffers-directory)
  			 (setq file list-buffers-directory))
  			((eq major-mode 'Info-mode)






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

end of thread, other threads:[~2009-07-17 22:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-16 20:47 [PATCH] lisp/files.el and lisp/buf-menu.el Thomas Lord
2009-07-17  3:08 ` Stefan Monnier
2009-07-17  4:56   ` Thomas Lord
2009-07-17 15:46     ` Stefan Monnier
2009-07-17 17:56       ` Thomas Lord
2009-07-17 22:22         ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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