;; Copyright (c) 1989, 1995, 1996, 1997 Free Software Foundation, Inc.
;; Author: Dick King <king@reasoning.com>
-;; Maintainer: Michael Ernst <mernst@alum.mit.edu>
+;; Maintainer: FSF
;; Created: 15 May 86
;; This file is part of GNU Emacs.
;; Use directory-file-name; code cleanup. mernst 6 Sep 97
;; Add uniquify-ignore-buffers-re.
;; Andre Srinivasan <andre@visigenic.com> 9 Sep 97
+;; Add uniquify-list-buffers-directory-modes
+;; Stefan Monnier <monnier@cs.yale.edu> 17 Nov 2000
;; Valuable feedback was provided by
;; Paul Smith <psmith@baynetworks.com>,
;;; Code:
(provide 'uniquify)
+(eval-when-compile (require 'cl))
;;; User-visible variables
(defcustom uniquify-buffer-name-style nil
"*If non-nil, buffer names are uniquified with parts of directory name.
The value determines the buffer name style and is one of `forward',
-`reverse', `post-forward' (the default), or `post-forward-angle-brackets'.
+`reverse', `post-forward', or `post-forward-angle-brackets'.
For example, files `/foo/bar/mumble/name' and `/baz/quux/mumble/name'
would have the following buffer names in the various styles:
forward bar/mumble/name quux/mumble/name
:group 'uniquify)
(defcustom uniquify-ignore-buffers-re nil
- "*Regular expression matching buffer names that should not be uniqified.
+ "*Regular expression matching buffer names that should not be uniquified.
For instance, set this to \"^draft-[0-9]+$\" to avoid having uniquify rename
draft buffers even if `uniquify-after-kill-buffer-p' is non-nil and the
visited file name isn't the same as that of the buffer."
- :type 'boolean
+ :type '(choice (const :tag "Uniquify all buffers" nil) regexp)
:group 'uniquify)
(defcustom uniquify-min-dir-content 0
:type 'boolean
:group 'uniquify)
+(defvar uniquify-list-buffers-directory-modes '(dired-mode cvs-mode)
+ "List of modes for which uniquify should obey `list-buffers-directory'.
+That means that when `buffer-file-name' is set to nil, `list-buffers-directory'
+contains the name of the directory which the buffer is visiting.")
;;; Utilities
-(defmacro uniquify-push (item list)
- (` (setq (, list) (cons (, item) (, list)))))
-
;; For directories, return the last component, not the empty string.
(defun uniquify-file-name-nondirectory (file-name)
(file-name-nondirectory (directory-file-name file-name)))
;; uniquify-fix-list data structure
(defmacro uniquify-fix-item-base (a)
- (` (car (, a))))
+ `(car ,a))
(defmacro uniquify-fix-item-filename (a)
- (` (car (cdr (, a)))))
+ `(car (cdr ,a)))
(defmacro uniquify-fix-item-buffer (a)
- (` (car (cdr (cdr (, a))))))
+ `(car (cdr (cdr ,a))))
;; Not a macro: passed to mapcar.
(defun uniquify-fix-item-unrationalized-buffer (item)
(or (car (cdr (cdr (cdr item)))) nil)) ;maybe better in the future
;;; Main entry point.
(defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf)
- "Makes file buffer names unique by adding segments from file name.
+ "Make file buffer names unique by adding segments from file name.
If `uniquify-min-dir-content' > 0, always pulls that many
file name elements. Arguments cause only a subset of buffers to be renamed."
(interactive)
(equal rawname
(uniquify-file-name-nondirectory newbuffile))))))
(if deserving
- (uniquify-push (list rawname bfn buffer nil) fix-list)
- (uniquify-push (list (buffer-name buffer))
- uniquify-non-file-buffer-names)))
+ (push (list rawname bfn buffer nil) fix-list)
+ (push (list (buffer-name buffer))
+ uniquify-non-file-buffer-names)))
(setq buffers (cdr buffers))))
;; selects buffers whose names may need changing, and others that
;; may conflict.
;; uniquify's version of buffer-file-name; result never contains trailing slash
(defun uniquify-buffer-file-name (buffer)
"Return name of file BUFFER is visiting, or nil if none.
-Works on dired buffers and ordinary file-visiting buffers, but no others."
+Works on ordinary file-visiting buffers and buffers whose mode is mentioned
+in `uniquify-list-buffers-directory-modes', otherwise returns nil."
(or (buffer-file-name buffer)
- (and (featurep 'dired)
- (save-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(and
- (eq major-mode 'dired-mode) ; do nothing if not a dired buffer
+ (memq major-mode uniquify-list-buffers-directory-modes)
(if (boundp 'list-buffers-directory) ; XEmacs mightn't define this
(and list-buffers-directory
(directory-file-name list-buffers-directory))
(directory-file-name
(if (consp dired-directory)
(car dired-directory)
- dired-directory))))))))))
+ dired-directory)))))))))
;; This examines the filename components in reverse order.
(defun uniquify-filename-lessp (s1 s2)
(uniquify-rationalize-conflicting-sublist
conflicting-sublist old-name depth)
(setq conflicting-sublist nil)))
- (uniquify-push item conflicting-sublist)
+ (push item conflicting-sublist)
(setq old-name proposed-name))
(setq fix-list (cdr fix-list)))
(uniquify-rationalize-conflicting-sublist