Commit 2e31777b authored by Stefan Monnier's avatar Stefan Monnier

* lisp/uniquify.el (uniquify-managed): Use defvar-local.

(rename-buffer, create-file-buffer): Advise with advice-add.
(uniquify-unload-function): Unadvise accordingly.
parent 8b62d742
2012-11-20 Stefan Monnier <monnier@iro.umontreal.ca>
* uniquify.el (uniquify-managed): Use defvar-local.
(rename-buffer, create-file-buffer): Advise with advice-add.
(uniquify-unload-function): Unadvise accordingly.
* emacs-lisp/trace.el: Rewrite, use nadvice and lexical-binding.
(trace-buffer): Don't purecopy.
(trace-entry-message, trace-exit-message): Add `context' arg.
......
......@@ -183,10 +183,9 @@ contains the name of the directory which the buffer is visiting.")
;; Internal variables used free
(defvar uniquify-possibly-resolvable nil)
(defvar uniquify-managed nil
(defvar-local uniquify-managed nil
"Non-nil if the name of this buffer is managed by uniquify.
It actually holds the list of `uniquify-item's corresponding to the conflict.")
(make-variable-buffer-local 'uniquify-managed)
(put 'uniquify-managed 'permanent-local t)
;; Used in desktop.el to save the non-uniquified buffer name
......@@ -464,27 +463,34 @@ For use on `kill-buffer-hook'."
;; rename-buffer and create-file-buffer. (Setting find-file-hook isn't
;; sufficient.)
(defadvice rename-buffer (after rename-buffer-uniquify activate)
(advice-add 'rename-buffer :around #'uniquify--rename-buffer-advice)
(defun uniquify--rename-buffer-advice (rb-fun newname &optional unique &rest args)
"Uniquify buffer names with parts of directory name."
(let ((retval (apply rb-fun newname unique args)))
(uniquify-maybe-rerationalize-w/o-cb)
(if (null (ad-get-arg 1)) ; no UNIQUE argument.
(if (null unique)
;; Mark this buffer so it won't be renamed by uniquify.
(setq uniquify-managed nil)
(when uniquify-buffer-name-style
;; Rerationalize w.r.t the new name.
(uniquify-rationalize-file-buffer-names
(ad-get-arg 0)
newname
(uniquify-buffer-file-name (current-buffer))
(current-buffer))
(setq ad-return-value (buffer-name (current-buffer))))))
(setq retval (buffer-name (current-buffer)))))
retval))
(defadvice create-file-buffer (after create-file-buffer-uniquify activate)
(advice-add 'create-file-buffer :around #'uniquify--create-file-buffer-advice)
(defun uniquify--create-file-buffer-advice (cfb-fun filename &rest args)
"Uniquify buffer names with parts of directory name."
(let ((retval (apply cfb-fun filename args)))
(if uniquify-buffer-name-style
(let ((filename (expand-file-name (directory-file-name (ad-get-arg 0)))))
(let ((filename (expand-file-name (directory-file-name filename))))
(uniquify-rationalize-file-buffer-names
(file-name-nondirectory filename)
(file-name-directory filename) ad-return-value))))
(file-name-directory filename) retval)))
retval))
;;; The End
......@@ -496,9 +502,8 @@ For use on `kill-buffer-hook'."
(set-buffer buf)
(when uniquify-managed
(push (cons buf (uniquify-item-base (car uniquify-managed))) buffers)))
(dolist (fun '(rename-buffer create-file-buffer))
(ad-remove-advice fun 'after (intern (concat (symbol-name fun) "-uniquify")))
(ad-update fun))
(advice-remove 'rename-buffer #'uniquify--rename-buffer-advice)
(advice-remove 'create-file-buffer #'uniquify--create-file-buffer-advice)
(dolist (buf buffers)
(set-buffer (car buf))
(rename-buffer (cdr buf) t))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment