X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/b2529d56b5126319a1659dc1530d6fc102cc21d6..c65e95328190d327796ba5d5d26f58ae093a9b30:/lisp/uniquify.el diff --git a/lisp/uniquify.el b/lisp/uniquify.el index 8226c65cbb..492918c7f9 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el @@ -421,6 +421,23 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." ;;; Hooks from the rest of Emacs +;; Buffer deletion +;; Rerationalize after a buffer is killed, to reduce coinciding buffer names. +;; This mechanism uses `kill-buffer-hook', which runs *before* deletion, so +;; it calls `uniquify-rerationalize-w/o-cb' to rerationalize the buffer list +;; ignoring the current buffer (which is going to be deleted anyway). +(defun uniquify-maybe-rerationalize-w/o-cb () + "Re-rationalize buffer names, ignoring current buffer. +For use on `kill-buffer-hook'." + (if (and (cdr uniquify-managed) + uniquify-buffer-name-style + uniquify-after-kill-buffer-p) + (uniquify-rerationalize-w/o-cb uniquify-managed))) + +;; Ideally we'd like to add it buffer-locally, but that doesn't work +;; because kill-buffer-hook is not permanent-local :-( +(add-hook 'kill-buffer-hook 'uniquify-maybe-rerationalize-w/o-cb) + ;; The logical place to put all this code is in generate-new-buffer-name. ;; It's written in C, so we would add a generate-new-buffer-name-function ;; which, if non-nil, would be called instead of the C. One problem with @@ -458,28 +475,24 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." (file-name-nondirectory filename) (file-name-directory filename) ad-return-value)))) -;; Buffer deletion -;; Rerationalize after a buffer is killed, to reduce coinciding buffer names. -;; This mechanism uses `kill-buffer-hook', which runs *before* deletion. -;; That means that the kill-buffer-hook function cannot just delete the -;; buffer -- it has to set something to do the rationalization *later*. -;; It actually puts another function on `post-command-hook'. This other -;; function runs the rationalization and then removes itself from the hook. -;; Is there a better way to accomplish this? -;; (This ought to set some global variables so the work is done only for -;; buffers with names similar to the deleted buffer. -MDE) - -(defun uniquify-maybe-rerationalize-w/o-cb () - "Re-rationalize buffer names, ignoring current buffer. -For use on `kill-buffer-hook'." - (if (and (cdr uniquify-managed) - uniquify-buffer-name-style - uniquify-after-kill-buffer-p) - (uniquify-rerationalize-w/o-cb uniquify-managed))) - -;; Ideally we'd like to add it buffer-locally, but that doesn't work -;; because kill-buffer-hook is not permanent-local :-( -(add-hook 'kill-buffer-hook 'uniquify-maybe-rerationalize-w/o-cb) +;;; The End + +(defun uniquify-unload-function () + "Unload the uniquify library." + (save-current-buffer + (let ((buffers nil)) + (dolist (buf (buffer-list)) + (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)) + (dolist (buf buffers) + (set-buffer (car buf)) + (rename-buffer (cdr buf) t)))) + ;; continue standard uploading + nil) (provide 'uniquify)