Mercurial > emacs
changeset 50844:86903fed9f75
(uniquify-managed): New var.
(uniquify-rationalize-file-buffer-names, rename-buffer): Use it and set
it to prevent accidental renaming of unrelated buffers.
(uniquify-delay-rationalize-file-buffer-names): Use it to avoid
the cost of uniquify when killing unrelated buffers.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 06 May 2003 14:29:39 +0000 |
parents | bc3a5a6b96ab |
children | ac2120f868b9 |
files | lisp/uniquify.el |
diffstat | 1 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/uniquify.el Tue May 06 14:06:34 2003 +0000 +++ b/lisp/uniquify.el Tue May 06 14:29:39 2003 +0000 @@ -166,6 +166,11 @@ ;; Internal variables used free (defvar uniquify-possibly-resolvable nil) +(defvar uniquify-managed nil + "Non-nil if the name of this buffer is managed by uniquify.") +(make-variable-buffer-local 'uniquify-managed) +(put 'uniquify-managed 'permanent-local t) + ;;; Main entry point. (defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf) @@ -184,6 +189,9 @@ (when (and (not (and uniquify-ignore-buffers-re (string-match uniquify-ignore-buffers-re bufname))) + ;; Only try to rename buffers we actually manage. + (or (buffer-local-value 'uniquify-managed buffer) + (eq buffer newbuf)) (setq bfn (if (eq buffer newbuf) newbuffile (uniquify-buffer-file-name buffer))) (setq rawname (file-name-nondirectory bfn)) @@ -193,6 +201,10 @@ (push (uniquify-make-item rawname bfn buffer (uniquify-get-proposed-name rawname bfn)) fix-list)))) + ;; Mark the new buffer as managed. + (when newbuf + (with-current-buffer newbuf + (setq uniquify-managed t))) ;; selects buffers whose names may need changing, and others that ;; may conflict, then bring conflicting names together (uniquify-rationalize-a-list fix-list))) @@ -322,7 +334,7 @@ (unless (equal newname (buffer-name buffer)) (with-current-buffer buffer (let ((uniquify-buffer-name-style nil)) ;Avoid hooks on rename-buffer. - ;; Pass the `unique' arg, just in case. + ;; Pass the `unique' arg, so the advice doesn't mark it as unmanaged. (rename-buffer newname t)))))) ;;; Hooks from the rest of Emacs @@ -344,17 +356,18 @@ (defadvice rename-buffer (after rename-buffer-uniquify activate) "Uniquify buffer names with parts of directory name." - (if (and uniquify-buffer-name-style - ;; UNIQUE argument - (ad-get-arg 1)) - (progn - (if uniquify-after-kill-buffer-p - ;; call with no argument; rationalize vs. old name as well as new - (uniquify-rationalize-file-buffer-names) - ;; call with argument: rationalize vs. new name only - (uniquify-rationalize-file-buffer-names - (uniquify-buffer-file-name (current-buffer)) (current-buffer))) - (setq ad-return-value (buffer-name (current-buffer)))))) + (if (null (ad-get-arg 1)) ; no UNIQUE argument. + ;; Mark this buffer so it won't be renamed by uniquify. + (setq uniquify-managed nil) + (when uniquify-buffer-name-style + (if uniquify-after-kill-buffer-p + ;; call with no argument; rationalize vs. old name as well as new + (progn (setq uniquify-managed t) + (uniquify-rationalize-file-buffer-names)) + ;; call with argument: rationalize vs. new name only + (uniquify-rationalize-file-buffer-names + (uniquify-buffer-file-name (current-buffer)) (current-buffer))) + (setq ad-return-value (buffer-name (current-buffer)))))) (defadvice create-file-buffer (after create-file-buffer-uniquify activate) "Uniquify buffer names with parts of directory name." @@ -375,7 +388,8 @@ (defun uniquify-delay-rationalize-file-buffer-names () "Add `delayed-uniquify-rationalize-file-buffer-names' to `post-command-hook'. For use on, eg, `kill-buffer-hook', to rationalize *after* buffer deletion." - (if (and uniquify-buffer-name-style + (if (and uniquify-managed + uniquify-buffer-name-style uniquify-after-kill-buffer-p ;; Rationalizing is costly, so don't do it for temp buffers. (uniquify-buffer-file-name (current-buffer)))