From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thomas Lord Newsgroups: gmane.emacs.devel Subject: [PATCH] lisp/files.el and lisp/buf-menu.el Date: Thu, 16 Jul 2009 13:47:00 -0700 Message-ID: <1247777220.6302.56.camel@dell-desktop.example.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1247777241 18533 80.91.229.12 (16 Jul 2009 20:47:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jul 2009 20:47:21 +0000 (UTC) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 16 22:47:15 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MRXrG-00026T-3q for ged-emacs-devel@m.gmane.org; Thu, 16 Jul 2009 22:47:15 +0200 Original-Received: from localhost ([127.0.0.1]:36321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRXrF-00036E-GH for ged-emacs-devel@m.gmane.org; Thu, 16 Jul 2009 16:47:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MRXrB-00035g-0r for emacs-devel@gnu.org; Thu, 16 Jul 2009 16:47:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MRXr5-0002vI-50 for emacs-devel@gnu.org; Thu, 16 Jul 2009 16:47:07 -0400 Original-Received: from [199.232.76.173] (port=45440 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRXr4-0002v0-QN for emacs-devel@gnu.org; Thu, 16 Jul 2009 16:47:02 -0400 Original-Received: from smtp131.iad.emailsrvr.com ([207.97.245.131]:33572) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MRXr4-00082z-BO for emacs-devel@gnu.org; Thu, 16 Jul 2009 16:47:02 -0400 Original-Received: from relay23.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay23.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id A18C41B4019; Thu, 16 Jul 2009 16:47:01 -0400 (EDT) Original-Received: by relay23.relay.iad.mlsrvr.com (Authenticated sender: lord-AT-emf.net) with ESMTPSA id BFFAA1B4089; Thu, 16 Jul 2009 16:47:00 -0400 (EDT) X-Mailer: Evolution 2.22.3.1 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:112553 Archived-At: 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)