184 |
(defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf) |
(defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf) |
185 |
"Make file buffer names unique by adding segments from file name. |
"Make file buffer names unique by adding segments from file name. |
186 |
If `uniquify-min-dir-content' > 0, always pulls that many |
If `uniquify-min-dir-content' > 0, always pulls that many |
187 |
file name elements. Arguments cause only a subset of buffers to be renamed." |
file name elements. |
188 |
|
Arguments NEWBUFFILE and NEWBUF cause only a subset of buffers to be renamed." |
189 |
(interactive) |
(interactive) |
190 |
(let (fix-list |
(let (fix-list |
191 |
uniquify-non-file-buffer-names |
uniquify-non-file-buffer-names |
291 |
(cond |
(cond |
292 |
((null extra-string) base) |
((null extra-string) base) |
293 |
((string-equal base "") ;Happens for dired buffers on the root directory. |
((string-equal base "") ;Happens for dired buffers on the root directory. |
294 |
(mapconcat 'identity extra-string (string directory-sep-char))) |
(mapconcat 'identity extra-string "/")) |
295 |
((eq uniquify-buffer-name-style 'reverse) |
((eq uniquify-buffer-name-style 'reverse) |
296 |
(let ((dirsep (string directory-sep-char))) |
(mapconcat 'identity |
297 |
(mapconcat 'identity |
(cons base (nreverse extra-string)) |
298 |
(cons base (nreverse extra-string)) |
(or uniquify-separator "\\"))) |
|
(or uniquify-separator "\\")))) |
|
299 |
((eq uniquify-buffer-name-style 'forward) |
((eq uniquify-buffer-name-style 'forward) |
300 |
(mapconcat 'identity (nconc extra-string (list base)) |
(mapconcat 'identity (nconc extra-string (list base)) |
301 |
(string directory-sep-char))) |
"/")) |
302 |
((eq uniquify-buffer-name-style 'post-forward) |
((eq uniquify-buffer-name-style 'post-forward) |
303 |
(concat base (or uniquify-separator "|") |
(concat base (or uniquify-separator "|") |
304 |
(mapconcat 'identity extra-string (string directory-sep-char)))) |
(mapconcat 'identity extra-string "/"))) |
305 |
((eq uniquify-buffer-name-style 'post-forward-angle-brackets) |
((eq uniquify-buffer-name-style 'post-forward-angle-brackets) |
306 |
(concat base "<" (mapconcat 'identity extra-string |
(concat base "<" (mapconcat 'identity extra-string "/") |
307 |
(string directory-sep-char)) ">")) |
">")) |
308 |
(t (error "Bad value for uniquify-buffer-name-style: %s" |
(t (error "Bad value for uniquify-buffer-name-style: %s" |
309 |
uniquify-buffer-name-style))))) |
uniquify-buffer-name-style))))) |
310 |
|
|
352 |
;; generate-new-buffer, which is called only by Lisp functions |
;; generate-new-buffer, which is called only by Lisp functions |
353 |
;; create-file-buffer and rename-uniquely. Rename-uniquely generally |
;; create-file-buffer and rename-uniquely. Rename-uniquely generally |
354 |
;; isn't used for buffers visiting files, so it's sufficient to hook |
;; isn't used for buffers visiting files, so it's sufficient to hook |
355 |
;; rename-buffer and create-file-buffer. (Setting find-file-hooks isn't |
;; rename-buffer and create-file-buffer. (Setting find-file-hook isn't |
356 |
;; sufficient.) |
;; sufficient.) |
357 |
|
|
358 |
(defadvice rename-buffer (after rename-buffer-uniquify activate) |
(defadvice rename-buffer (after rename-buffer-uniquify activate) |
385 |
;; (This ought to set some global variables so the work is done only for |
;; (This ought to set some global variables so the work is done only for |
386 |
;; buffers with names similar to the deleted buffer. -MDE) |
;; buffers with names similar to the deleted buffer. -MDE) |
387 |
|
|
388 |
(defun delay-uniquify-rationalize-file-buffer-names () |
(defun uniquify-delay-rationalize-file-buffer-names () |
389 |
"Add `delayed-uniquify-rationalize-file-buffer-names' to `post-command-hook'. |
"Add `delayed-uniquify-rationalize-file-buffer-names' to `post-command-hook'. |
390 |
For use on, eg, `kill-buffer-hook', to rationalize *after* buffer deletion." |
For use on, eg, `kill-buffer-hook', to rationalize *after* buffer deletion." |
391 |
(if (and uniquify-buffer-name-style |
(if (and uniquify-buffer-name-style |
392 |
uniquify-after-kill-buffer-p) |
uniquify-after-kill-buffer-p |
393 |
|
;; Rationalizing is costly, so don't do it for temp buffers. |
394 |
|
(uniquify-buffer-file-name (current-buffer))) |
395 |
(add-hook 'post-command-hook |
(add-hook 'post-command-hook |
396 |
'delayed-uniquify-rationalize-file-buffer-names))) |
'uniquify-delayed-rationalize-file-buffer-names))) |
397 |
|
|
398 |
(defun delayed-uniquify-rationalize-file-buffer-names () |
(defun uniquify-delayed-rationalize-file-buffer-names () |
399 |
"Rerationalize buffer names and remove self from `post-command-hook'. |
"Rerationalize buffer names and remove self from `post-command-hook'. |
400 |
See also `delay-rationalize-file-buffer-names' for hook setter." |
See also `delay-rationalize-file-buffer-names' for hook setter." |
401 |
(uniquify-rationalize-file-buffer-names) |
(uniquify-rationalize-file-buffer-names) |
402 |
(remove-hook 'post-command-hook |
(remove-hook 'post-command-hook |
403 |
'delayed-uniquify-rationalize-file-buffer-names)) |
'uniquify-delayed-rationalize-file-buffer-names)) |
404 |
|
|
405 |
(add-hook 'kill-buffer-hook 'delay-uniquify-rationalize-file-buffer-names) |
(add-hook 'kill-buffer-hook 'uniquify-delay-rationalize-file-buffer-names) |
406 |
|
|
407 |
;;; uniquify.el ends here |
;;; uniquify.el ends here |