diff options
| author | Stefan Monnier | 2012-11-20 14:32:20 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2012-11-20 14:32:20 -0500 |
| commit | 2e31777bd1354d22319cf6de4085ccc362cff42c (patch) | |
| tree | 5468719d22cecd1271ea3f90a67bb8e7c5fa0715 | |
| parent | 8b62d7427e12bbf07ab3454cc061a6b43ded56dd (diff) | |
| download | emacs-2e31777bd1354d22319cf6de4085ccc362cff42c.tar.gz emacs-2e31777bd1354d22319cf6de4085ccc362cff42c.zip | |
* lisp/uniquify.el (uniquify-managed): Use defvar-local.
(rename-buffer, create-file-buffer): Advise with advice-add.
(uniquify-unload-function): Unadvise accordingly.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/uniquify.el | 29 |
2 files changed, 21 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c2d1b58b6ec..3e35c8a9fcb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2012-11-20 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2012-11-20 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * uniquify.el (uniquify-managed): Use defvar-local. | ||
| 4 | (rename-buffer, create-file-buffer): Advise with advice-add. | ||
| 5 | (uniquify-unload-function): Unadvise accordingly. | ||
| 6 | |||
| 3 | * emacs-lisp/trace.el: Rewrite, use nadvice and lexical-binding. | 7 | * emacs-lisp/trace.el: Rewrite, use nadvice and lexical-binding. |
| 4 | (trace-buffer): Don't purecopy. | 8 | (trace-buffer): Don't purecopy. |
| 5 | (trace-entry-message, trace-exit-message): Add `context' arg. | 9 | (trace-entry-message, trace-exit-message): Add `context' arg. |
diff --git a/lisp/uniquify.el b/lisp/uniquify.el index 3619d499419..2b4794c9cc2 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el | |||
| @@ -183,10 +183,9 @@ contains the name of the directory which the buffer is visiting.") | |||
| 183 | ;; Internal variables used free | 183 | ;; Internal variables used free |
| 184 | (defvar uniquify-possibly-resolvable nil) | 184 | (defvar uniquify-possibly-resolvable nil) |
| 185 | 185 | ||
| 186 | (defvar uniquify-managed nil | 186 | (defvar-local uniquify-managed nil |
| 187 | "Non-nil if the name of this buffer is managed by uniquify. | 187 | "Non-nil if the name of this buffer is managed by uniquify. |
| 188 | It actually holds the list of `uniquify-item's corresponding to the conflict.") | 188 | It actually holds the list of `uniquify-item's corresponding to the conflict.") |
| 189 | (make-variable-buffer-local 'uniquify-managed) | ||
| 190 | (put 'uniquify-managed 'permanent-local t) | 189 | (put 'uniquify-managed 'permanent-local t) |
| 191 | 190 | ||
| 192 | ;; Used in desktop.el to save the non-uniquified buffer name | 191 | ;; Used in desktop.el to save the non-uniquified buffer name |
| @@ -464,27 +463,34 @@ For use on `kill-buffer-hook'." | |||
| 464 | ;; rename-buffer and create-file-buffer. (Setting find-file-hook isn't | 463 | ;; rename-buffer and create-file-buffer. (Setting find-file-hook isn't |
| 465 | ;; sufficient.) | 464 | ;; sufficient.) |
| 466 | 465 | ||
| 467 | (defadvice rename-buffer (after rename-buffer-uniquify activate) | 466 | (advice-add 'rename-buffer :around #'uniquify--rename-buffer-advice) |
| 467 | (defun uniquify--rename-buffer-advice (rb-fun newname &optional unique &rest args) | ||
| 468 | "Uniquify buffer names with parts of directory name." | 468 | "Uniquify buffer names with parts of directory name." |
| 469 | (let ((retval (apply rb-fun newname unique args))) | ||
| 469 | (uniquify-maybe-rerationalize-w/o-cb) | 470 | (uniquify-maybe-rerationalize-w/o-cb) |
| 470 | (if (null (ad-get-arg 1)) ; no UNIQUE argument. | 471 | (if (null unique) |
| 471 | ;; Mark this buffer so it won't be renamed by uniquify. | 472 | ;; Mark this buffer so it won't be renamed by uniquify. |
| 472 | (setq uniquify-managed nil) | 473 | (setq uniquify-managed nil) |
| 473 | (when uniquify-buffer-name-style | 474 | (when uniquify-buffer-name-style |
| 474 | ;; Rerationalize w.r.t the new name. | 475 | ;; Rerationalize w.r.t the new name. |
| 475 | (uniquify-rationalize-file-buffer-names | 476 | (uniquify-rationalize-file-buffer-names |
| 476 | (ad-get-arg 0) | 477 | newname |
| 477 | (uniquify-buffer-file-name (current-buffer)) | 478 | (uniquify-buffer-file-name (current-buffer)) |
| 478 | (current-buffer)) | 479 | (current-buffer)) |
| 479 | (setq ad-return-value (buffer-name (current-buffer)))))) | 480 | (setq retval (buffer-name (current-buffer))))) |
| 481 | retval)) | ||
| 480 | 482 | ||
| 481 | (defadvice create-file-buffer (after create-file-buffer-uniquify activate) | 483 | |
| 484 | (advice-add 'create-file-buffer :around #'uniquify--create-file-buffer-advice) | ||
| 485 | (defun uniquify--create-file-buffer-advice (cfb-fun filename &rest args) | ||
| 482 | "Uniquify buffer names with parts of directory name." | 486 | "Uniquify buffer names with parts of directory name." |
| 487 | (let ((retval (apply cfb-fun filename args))) | ||
| 483 | (if uniquify-buffer-name-style | 488 | (if uniquify-buffer-name-style |
| 484 | (let ((filename (expand-file-name (directory-file-name (ad-get-arg 0))))) | 489 | (let ((filename (expand-file-name (directory-file-name filename)))) |
| 485 | (uniquify-rationalize-file-buffer-names | 490 | (uniquify-rationalize-file-buffer-names |
| 486 | (file-name-nondirectory filename) | 491 | (file-name-nondirectory filename) |
| 487 | (file-name-directory filename) ad-return-value)))) | 492 | (file-name-directory filename) retval))) |
| 493 | retval)) | ||
| 488 | 494 | ||
| 489 | ;;; The End | 495 | ;;; The End |
| 490 | 496 | ||
| @@ -496,9 +502,8 @@ For use on `kill-buffer-hook'." | |||
| 496 | (set-buffer buf) | 502 | (set-buffer buf) |
| 497 | (when uniquify-managed | 503 | (when uniquify-managed |
| 498 | (push (cons buf (uniquify-item-base (car uniquify-managed))) buffers))) | 504 | (push (cons buf (uniquify-item-base (car uniquify-managed))) buffers))) |
| 499 | (dolist (fun '(rename-buffer create-file-buffer)) | 505 | (advice-remove 'rename-buffer #'uniquify--rename-buffer-advice) |
| 500 | (ad-remove-advice fun 'after (intern (concat (symbol-name fun) "-uniquify"))) | 506 | (advice-remove 'create-file-buffer #'uniquify--create-file-buffer-advice) |
| 501 | (ad-update fun)) | ||
| 502 | (dolist (buf buffers) | 507 | (dolist (buf buffers) |
| 503 | (set-buffer (car buf)) | 508 | (set-buffer (car buf)) |
| 504 | (rename-buffer (cdr buf) t)))) | 509 | (rename-buffer (cdr buf) t)))) |