emacs-devel
[Top][All Lists]
Advanced

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

[PATCH] lisp/files.el and lisp/buf-menu.el


From: Thomas Lord
Subject: [PATCH] lisp/files.el and lisp/buf-menu.el
Date: Thu, 16 Jul 2009 13:47:00 -0700

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)






reply via email to

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