mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-25 07:28:20 +00:00
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.
This commit is contained in:
parent
0f9ec379eb
commit
1a724cc2d2
@ -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."
|
||||
|
@ -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))))
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user