diff options
| author | Stefan Monnier | 2003-05-06 14:29:39 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-05-06 14:29:39 +0000 |
| commit | 6b09e9c8dad9bd63af0a1bc78f390fce5daaad5f (patch) | |
| tree | bb509ca8f60c3399cf1656a5132c0d645cba2531 | |
| parent | 2abd03067395fc6360e70cbd8e60c7b165b6a199 (diff) | |
| download | emacs-6b09e9c8dad9bd63af0a1bc78f390fce5daaad5f.tar.gz emacs-6b09e9c8dad9bd63af0a1bc78f390fce5daaad5f.zip | |
(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.
| -rw-r--r-- | lisp/uniquify.el | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/lisp/uniquify.el b/lisp/uniquify.el index f80e469feab..5b5145ad026 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el | |||
| @@ -166,6 +166,11 @@ contains the name of the directory which the buffer is visiting.") | |||
| 166 | ;; Internal variables used free | 166 | ;; Internal variables used free |
| 167 | (defvar uniquify-possibly-resolvable nil) | 167 | (defvar uniquify-possibly-resolvable nil) |
| 168 | 168 | ||
| 169 | (defvar uniquify-managed nil | ||
| 170 | "Non-nil if the name of this buffer is managed by uniquify.") | ||
| 171 | (make-variable-buffer-local 'uniquify-managed) | ||
| 172 | (put 'uniquify-managed 'permanent-local t) | ||
| 173 | |||
| 169 | ;;; Main entry point. | 174 | ;;; Main entry point. |
| 170 | 175 | ||
| 171 | (defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf) | 176 | (defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf) |
| @@ -184,6 +189,9 @@ Arguments NEWBUFFILE and NEWBUF cause only a subset of buffers to be renamed." | |||
| 184 | (when (and (not (and uniquify-ignore-buffers-re | 189 | (when (and (not (and uniquify-ignore-buffers-re |
| 185 | (string-match uniquify-ignore-buffers-re | 190 | (string-match uniquify-ignore-buffers-re |
| 186 | bufname))) | 191 | bufname))) |
| 192 | ;; Only try to rename buffers we actually manage. | ||
| 193 | (or (buffer-local-value 'uniquify-managed buffer) | ||
| 194 | (eq buffer newbuf)) | ||
| 187 | (setq bfn (if (eq buffer newbuf) newbuffile | 195 | (setq bfn (if (eq buffer newbuf) newbuffile |
| 188 | (uniquify-buffer-file-name buffer))) | 196 | (uniquify-buffer-file-name buffer))) |
| 189 | (setq rawname (file-name-nondirectory bfn)) | 197 | (setq rawname (file-name-nondirectory bfn)) |
| @@ -193,6 +201,10 @@ Arguments NEWBUFFILE and NEWBUF cause only a subset of buffers to be renamed." | |||
| 193 | (push (uniquify-make-item rawname bfn buffer | 201 | (push (uniquify-make-item rawname bfn buffer |
| 194 | (uniquify-get-proposed-name rawname bfn)) | 202 | (uniquify-get-proposed-name rawname bfn)) |
| 195 | fix-list)))) | 203 | fix-list)))) |
| 204 | ;; Mark the new buffer as managed. | ||
| 205 | (when newbuf | ||
| 206 | (with-current-buffer newbuf | ||
| 207 | (setq uniquify-managed t))) | ||
| 196 | ;; selects buffers whose names may need changing, and others that | 208 | ;; selects buffers whose names may need changing, and others that |
| 197 | ;; may conflict, then bring conflicting names together | 209 | ;; may conflict, then bring conflicting names together |
| 198 | (uniquify-rationalize-a-list fix-list))) | 210 | (uniquify-rationalize-a-list fix-list))) |
| @@ -322,7 +334,7 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." | |||
| 322 | (unless (equal newname (buffer-name buffer)) | 334 | (unless (equal newname (buffer-name buffer)) |
| 323 | (with-current-buffer buffer | 335 | (with-current-buffer buffer |
| 324 | (let ((uniquify-buffer-name-style nil)) ;Avoid hooks on rename-buffer. | 336 | (let ((uniquify-buffer-name-style nil)) ;Avoid hooks on rename-buffer. |
| 325 | ;; Pass the `unique' arg, just in case. | 337 | ;; Pass the `unique' arg, so the advice doesn't mark it as unmanaged. |
| 326 | (rename-buffer newname t)))))) | 338 | (rename-buffer newname t)))))) |
| 327 | 339 | ||
| 328 | ;;; Hooks from the rest of Emacs | 340 | ;;; Hooks from the rest of Emacs |
| @@ -344,17 +356,18 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." | |||
| 344 | 356 | ||
| 345 | (defadvice rename-buffer (after rename-buffer-uniquify activate) | 357 | (defadvice rename-buffer (after rename-buffer-uniquify activate) |
| 346 | "Uniquify buffer names with parts of directory name." | 358 | "Uniquify buffer names with parts of directory name." |
| 347 | (if (and uniquify-buffer-name-style | 359 | (if (null (ad-get-arg 1)) ; no UNIQUE argument. |
| 348 | ;; UNIQUE argument | 360 | ;; Mark this buffer so it won't be renamed by uniquify. |
| 349 | (ad-get-arg 1)) | 361 | (setq uniquify-managed nil) |
| 350 | (progn | 362 | (when uniquify-buffer-name-style |
| 351 | (if uniquify-after-kill-buffer-p | 363 | (if uniquify-after-kill-buffer-p |
| 352 | ;; call with no argument; rationalize vs. old name as well as new | 364 | ;; call with no argument; rationalize vs. old name as well as new |
| 353 | (uniquify-rationalize-file-buffer-names) | 365 | (progn (setq uniquify-managed t) |
| 354 | ;; call with argument: rationalize vs. new name only | 366 | (uniquify-rationalize-file-buffer-names)) |
| 355 | (uniquify-rationalize-file-buffer-names | 367 | ;; call with argument: rationalize vs. new name only |
| 356 | (uniquify-buffer-file-name (current-buffer)) (current-buffer))) | 368 | (uniquify-rationalize-file-buffer-names |
| 357 | (setq ad-return-value (buffer-name (current-buffer)))))) | 369 | (uniquify-buffer-file-name (current-buffer)) (current-buffer))) |
| 370 | (setq ad-return-value (buffer-name (current-buffer)))))) | ||
| 358 | 371 | ||
| 359 | (defadvice create-file-buffer (after create-file-buffer-uniquify activate) | 372 | (defadvice create-file-buffer (after create-file-buffer-uniquify activate) |
| 360 | "Uniquify buffer names with parts of directory name." | 373 | "Uniquify buffer names with parts of directory name." |
| @@ -375,7 +388,8 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." | |||
| 375 | (defun uniquify-delay-rationalize-file-buffer-names () | 388 | (defun uniquify-delay-rationalize-file-buffer-names () |
| 376 | "Add `delayed-uniquify-rationalize-file-buffer-names' to `post-command-hook'. | 389 | "Add `delayed-uniquify-rationalize-file-buffer-names' to `post-command-hook'. |
| 377 | For use on, eg, `kill-buffer-hook', to rationalize *after* buffer deletion." | 390 | For use on, eg, `kill-buffer-hook', to rationalize *after* buffer deletion." |
| 378 | (if (and uniquify-buffer-name-style | 391 | (if (and uniquify-managed |
| 392 | uniquify-buffer-name-style | ||
| 379 | uniquify-after-kill-buffer-p | 393 | uniquify-after-kill-buffer-p |
| 380 | ;; Rationalizing is costly, so don't do it for temp buffers. | 394 | ;; Rationalizing is costly, so don't do it for temp buffers. |
| 381 | (uniquify-buffer-file-name (current-buffer))) | 395 | (uniquify-buffer-file-name (current-buffer))) |