;;; uniquify.el --- unique buffer names dependent on file name
-;; Copyright (c) 1989, 1995, 1996, 1997, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 1989, 1995, 1996, 1997, 2001, 2002, 2003,
+;; 2004, 2005, 2006 Free Software Foundation, Inc.
;; Author: Dick King <king@reasoning.com>
;; Maintainer: FSF
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;; User-visible variables
(defgroup uniquify nil
- "Unique buffer names dependent on file name"
+ "Unique buffer names dependent on file name."
:group 'applications)
(const post-forward)
(const post-forward-angle-brackets)
(const :tag "standard Emacs behavior (nil)" nil))
- :require 'uniquify)
+ :require 'uniquify
+ :group 'uniquify)
-(defcustom uniquify-after-kill-buffer-p nil
+(defcustom uniquify-after-kill-buffer-p t
"If non-nil, rerationalize buffer names after a buffer has been killed."
- :type 'boolean)
+ :type 'boolean
+ :group 'uniquify)
(defcustom uniquify-ask-about-buffer-names-p nil
"*If non-nil, permit user to choose names for buffers with same base file.
If the user chooses to name a buffer, uniquification is preempted and no
other buffer names are changed."
- :type 'boolean)
+ :type 'boolean
+ :group 'uniquify)
;; The default value matches certain Gnus buffers.
-(defcustom uniquify-ignore-buffers-re "^\\*\\(un\\)?sent "
+(defcustom uniquify-ignore-buffers-re nil
"*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 '(choice (const :tag "Uniquify all buffers" nil) regexp))
+ :type '(choice (const :tag "Uniquify all buffers" nil) regexp)
+ :group 'uniquify)
(defcustom uniquify-min-dir-content 0
"*Minimum number of directory name components included in buffer name."
- :type 'integer)
+ :type 'integer
+ :group 'uniquify)
(defcustom uniquify-separator nil
"*String separator for buffer name components.
base file name from directory part in buffer names (default \"|\").
When `uniquify-buffer-name-style' is `reverse', separates all
file name components (default \"\\\")."
- :type '(choice (const nil) string))
+ :type '(choice (const nil) string)
+ :group 'uniquify)
(defcustom uniquify-trailing-separator-p nil
"*If non-nil, add a file name separator to dired buffer names.
If `uniquify-buffer-name-style' is `forward', add the separator at the end;
if it is `reverse', add the separator at the beginning; otherwise, this
variable is ignored."
- :type 'boolean)
+ :type 'boolean
+ :group 'uniquify)
(defcustom uniquify-strip-common-suffix
;; Using it when uniquify-min-dir-content>0 doesn't make much sense.
E.g. if you open /a1/b/c/d and /a2/b/c/d, the buffer names will say
\"d|a1\" and \"d|a2\" instead of \"d|a1/b/c\" and \"d|a2/b/c\".
This can be handy when you have deep parallel hierarchies."
- :type 'boolean)
+ :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'.
"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 NEWBUFFILE and NEWBUF cause only a subset of buffers to be renamed."
- (interactive)
- (if (null dirname)
- (with-current-buffer newbuf (setq uniquify-managed nil))
+Arguments BASE, DIRNAME, and NEWBUF specify the new buffer that causes
+this rationalization."
+ (interactive
+ (list (if uniquify-managed
+ (uniquify-item-base (car uniquify-managed)) (buffer-name))
+ (uniquify-buffer-file-name (current-buffer))
+ (current-buffer)))
+ ;; Make sure we don't get confused by outdated uniquify-managed info in
+ ;; this buffer.
+ (with-current-buffer newbuf (setq uniquify-managed nil))
+ (when dirname
(setq dirname (expand-file-name (directory-file-name dirname)))
(let ((fix-list (list (uniquify-make-item base dirname newbuf)))
items)
;; Don't re-add stuff we already have. Actually this
;; whole `and' test should only match at most once.
(not (memq (car items) fix-list)))
+ (unless (cdr items)
+ ;; If there was no conflict, the buffer-name is equal to the
+ ;; base-name and we may have missed a rename-buffer because
+ ;; of code like in set-visited-file-name:
+ ;; (or (string= new-name (buffer-name)) (rename-buffer new-name t))
+ ;; So we need to refresh the dirname of the uniquify-item.
+ (setf (uniquify-item-dirname (car items))
+ (uniquify-buffer-file-name
+ (uniquify-item-buffer (car items))))
+ ;; This shouldn't happen, but maybe there's no dirname any more.
+ (unless (uniquify-item-dirname (car items))
+ (with-current-buffer (uniquify-item-buffer (car items))
+ (setq uniquify-managed nil))
+ (setq items nil)))
(setq fix-list (append fix-list items))))
;; selects buffers whose names may need changing, and others that
;; may conflict, then bring conflicting names together
(if (memq major-mode uniquify-list-buffers-directory-modes)
list-buffers-directory))))
(when filename
- (file-name-directory (expand-file-name (directory-file-name filename)))))))
+ (directory-file-name
+ (file-name-directory
+ (expand-file-name
+ (directory-file-name filename))))))))
(defun uniquify-rerationalize-w/o-cb (fix-list)
"Re-rationalize the buffers in FIX-LIST, but ignoring current-buffer."
;; if there is a conflict.
(dolist (item fix-list)
(with-current-buffer (uniquify-item-buffer item)
- ;; Reset the proposed names.
+ ;; Refresh the dirnames and proposed names.
(setf (uniquify-item-proposed item)
(uniquify-get-proposed-name (uniquify-item-base item)
(uniquify-item-dirname item)))
(add-hook 'kill-buffer-hook 'uniquify-maybe-rerationalize-w/o-cb)
(provide 'uniquify)
+
+;; arch-tag: e763faa3-56c9-4903-8eb8-26e1c45a0065
;;; uniquify.el ends here