From 1a724cc2d2e7f08b9fcad569c8cacf126ad55791 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 27 Dec 2021 19:47:23 -0500 Subject: [PATCH] Replace uniquify.el's advice with direct calls This fixes bug#1338. * src/buffer.c (Frename_buffer): Call `uniquify--rename-buffer-advice`. * lisp/files.el (create-file-buffer): Call`uniquify--create-file-buffer-advice`. * lisp/uniquify.el (uniquify--rename-buffer-advice) (uniquify--create-file-buffer-advice): Don't add them as advice any more. Adjust their calling convention accordingly. --- lisp/files.el | 14 ++++++++------ lisp/uniquify.el | 34 +++++++++++++++------------------- src/buffer.c | 5 ++++- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 9ed63a60f81..81e91567d08 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2010,12 +2010,14 @@ otherwise a string <2> or <3> or ... is appended to get an unused name. Emacs treats buffers whose names begin with a space as internal buffers. To avoid confusion when visiting a file whose name begins with a space, this function prepends a \"|\" to the final result if necessary." - (let ((lastname (file-name-nondirectory filename))) - (if (string= lastname "") - (setq lastname filename)) - (generate-new-buffer (if (string-prefix-p " " lastname) - (concat "|" lastname) - lastname)))) + (let* ((lastname (file-name-nondirectory filename)) + (lastname (if (string= lastname "") + filename lastname)) + (buf (generate-new-buffer (if (string-prefix-p " " lastname) + (concat "|" lastname) + lastname)))) + (uniquify--create-file-buffer-advice buf filename) + buf)) (defcustom automount-dir-prefix (purecopy "^/tmp_mnt/") "Regexp to match the automounter prefix in a directory name." diff --git a/lisp/uniquify.el b/lisp/uniquify.el index ffb5ecc9024..b9a4c3c6835 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el @@ -476,34 +476,32 @@ For use on `kill-buffer-hook'." ;; rename-buffer and create-file-buffer. (Setting find-file-hook isn't ;; sufficient.) -(advice-add 'rename-buffer :around #'uniquify--rename-buffer-advice) -(defun uniquify--rename-buffer-advice (rb-fun newname &optional unique &rest args) +;; (advice-add 'rename-buffer :around #'uniquify--rename-buffer-advice) +(defun uniquify--rename-buffer-advice (newname &optional unique) + ;; BEWARE: This is called directly from `buffer.c'! "Uniquify buffer names with parts of directory name." - (let ((retval (apply rb-fun newname unique args))) (uniquify-maybe-rerationalize-w/o-cb) - (if (null unique) + (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 - newname + newname (uniquify-buffer-file-name (current-buffer)) - (current-buffer)) - (setq retval (buffer-name (current-buffer))))) - retval)) + (current-buffer))))) -(advice-add 'create-file-buffer :around #'uniquify--create-file-buffer-advice) -(defun uniquify--create-file-buffer-advice (cfb-fun filename &rest args) +;; (advice-add 'create-file-buffer :around #'uniquify--create-file-buffer-advice) +(defun uniquify--create-file-buffer-advice (buf filename) + ;; BEWARE: This is called directly from `files.el'! "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 filename)))) - (uniquify-rationalize-file-buffer-names - (file-name-nondirectory filename) - (file-name-directory filename) retval))) - retval)) + (when uniquify-buffer-name-style + (let ((filename (expand-file-name (directory-file-name filename)))) + (uniquify-rationalize-file-buffer-names + (file-name-nondirectory filename) + (file-name-directory filename) + buf)))) (defun uniquify-unload-function () "Unload the uniquify library." @@ -513,8 +511,6 @@ For use on `kill-buffer-hook'." (set-buffer buf) (when uniquify-managed (push (cons buf (uniquify-item-base (car uniquify-managed))) buffers))) - (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)))) diff --git a/src/buffer.c b/src/buffer.c index 9d8892a797a..a2fd0a83bce 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1552,7 +1552,7 @@ This does not change the name of the visited file (if any). */) /* Catch redisplay's attention. Unless we do this, the mode lines for any windows displaying current_buffer will stay unchanged. */ - update_mode_lines = 11; + bset_update_mode_line (current_buffer); XSETBUFFER (buf, current_buffer); Fsetcar (Frassq (buf, Vbuffer_alist), newname); @@ -1562,6 +1562,9 @@ This does not change the name of the visited file (if any). */) run_buffer_list_update_hook (current_buffer); + call2 (intern ("uniquify--rename-buffer-advice"), + BVAR (current_buffer, name), unique); + /* Refetch since that last call may have done GC. */ return BVAR (current_buffer, name); } -- 2.39.2