uniquify.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. ;;; uniquify.el --- unique buffer names dependent on file name -*- lexical-binding: t -*-
  2. ;; Copyright (C) 1989, 1995-1997, 2001-2017 Free Software Foundation,
  3. ;; Inc.
  4. ;; Author: Dick King <king@reasoning.com>
  5. ;; Maintainer: emacs-devel@gnu.org
  6. ;; Keywords: files
  7. ;; Created: 15 May 86
  8. ;; Package: emacs
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; Emacs's traditional method for making buffer names unique adds <2>, <3>,
  22. ;; etc. to the end of (all but one of) the buffers. This file replaces
  23. ;; that behavior, for buffers visiting files and dired buffers, with a
  24. ;; uniquification that adds parts of the file name until the buffer names
  25. ;; are unique. For instance, buffers visiting /u/mernst/tmp/Makefile and
  26. ;; /usr/projects/zaphod/Makefile would be named Makefile|tmp and
  27. ;; Makefile|zaphod, respectively (instead of Makefile and Makefile<2>).
  28. ;; Other buffer name styles are also available.
  29. ;; To use this file, do (require 'uniquify)
  30. ;; and set uniquify-buffer-name-style to one of its non-nil alternative values.
  31. ;; For other options, see "User-visible variables", below.
  32. ;; A version of uniquify.el that works under Emacs 18, Emacs 19, XEmacs,
  33. ;; and InfoDock is available from the maintainer.
  34. ;;; Change Log:
  35. ;; Originally by Dick King <king@reasoning.com> 15 May 86
  36. ;; Converted for Emacs 18 by Stephen Gildea <gildea@stop.mail-abuse.org>
  37. ;; Make uniquify-min-dir-content 0 truly non-invasive. gildea 23 May 89
  38. ;; Some cleanup. uniquify-min-dir-content default 0. gildea 01 Jun 89
  39. ;; Don't rename to "". Michael Ernst <mernst@theory.lcs.mit.edu> 15 Jun 94
  40. ;; Add kill-buffer-hook. Kenneth Manheimer <ken.manheimer@nist.gov> 09 May 95
  41. ;; Add advice for rename-buffer and create-file-buffer, handle dired buffers,
  42. ;; kill-buffer-rationalize-buffer-names-p, documentation. mernst 24 May 95
  43. ;; Remove free variables, fix typos. mernst 5 Jun 95
  44. ;; Efficiently support Emacs 19.27 & earlier. ken.manheimer, mernst 10 Jun 95
  45. ;; Rename user options to "uniquify-...", add uniquify-reverse-dir-content-p,
  46. ;; add uniquify-ask-about-buffer-names-p. king, mernst 13 Jun 95
  47. ;; Prefix functions by "uniquify-..."; rename mnemonic-buffer-names to
  48. ;; uniquify-buffer-name-style; add 'forward and 'post-forward-angle-brackets
  49. ;; styles; remove uniquify-reverse-dir-content-p; add
  50. ;; uniquify-trailing-separator-p. mernst 4 Aug 95
  51. ;; Don't call expand-file-name on nil. mernst 7 Jan 96
  52. ;; Check whether list-buffers-directory is bound. mernst 11 Oct 96
  53. ;; Ignore non-file non-dired buffers. Colin Rafferty <craffert@ml.com> 3 Mar 97
  54. ;; Use last component, not "", for file name of directories. mernst 27 Jun 97
  55. ;; Use directory-file-name; code cleanup. mernst 6 Sep 97
  56. ;; Add uniquify-ignore-buffers-re.
  57. ;; Andre Srinivasan <andre@visigenic.com> 9 Sep 97
  58. ;; Add uniquify-list-buffers-directory-modes
  59. ;; Stefan Monnier <monnier@cs.yale.edu> 17 Nov 2000
  60. ;; Algorithm and data structure changed to reduce consing with lots of buffers
  61. ;; Francesco Potortì <pot@gnu.org> (ideas by rms and monnier) 2001-07-18
  62. ;; Valuable feedback was provided by
  63. ;; Paul Smith <psmith@baynetworks.com>,
  64. ;; Alastair Burt <burt@dfki.uni-kl.de>,
  65. ;; Bob Weiner <weiner@footloose.sps.mot.com>,
  66. ;; Albert L. Ting <alt@vlibs.com>,
  67. ;; gyro@reasoning.com,
  68. ;; Bryan O'Sullivan <bos@eng.sun.com>.
  69. ;;; Code:
  70. (eval-when-compile (require 'cl-lib))
  71. ;;; User-visible variables
  72. (defgroup uniquify nil
  73. "Unique buffer names dependent on file name."
  74. :group 'files)
  75. (defcustom uniquify-buffer-name-style 'post-forward-angle-brackets
  76. "How to construct unique buffer names for files with the same base name.
  77. The value can be one of: `forward', `reverse', `post-forward',
  78. `post-forward-angle-brackets', or nil.
  79. For example, the files `/foo/bar/mumble/name' and `/baz/quux/mumble/name'
  80. would have the following buffer names in the various styles:
  81. forward bar/mumble/name quux/mumble/name
  82. reverse name\\mumble\\bar name\\mumble\\quux
  83. post-forward name|bar/mumble name|quux/mumble
  84. post-forward-angle-brackets name<bar/mumble> name<quux/mumble>
  85. nil name name<2>
  86. The \"mumble\" part may be stripped as well, depending on the
  87. setting of `uniquify-strip-common-suffix'. For more options that
  88. you can set, browse the `uniquify' custom group."
  89. :type '(radio (const forward)
  90. (const reverse)
  91. (const post-forward)
  92. (const post-forward-angle-brackets)
  93. (const :tag "numeric suffixes" nil))
  94. :version "24.4"
  95. :require 'uniquify)
  96. (defcustom uniquify-after-kill-buffer-p t
  97. "If non-nil, rerationalize buffer names after a buffer has been killed."
  98. :type 'boolean)
  99. ;; The default value matches certain Gnus buffers.
  100. (defcustom uniquify-ignore-buffers-re nil
  101. "Regular expression matching buffer names that should not be uniquified.
  102. For instance, set this to \"^draft-[0-9]+$\" to avoid having uniquify rename
  103. draft buffers even if `uniquify-after-kill-buffer-p' is non-nil and the
  104. visited file name isn't the same as that of the buffer."
  105. :type '(choice (const :tag "Uniquify all buffers" nil) regexp))
  106. (defcustom uniquify-min-dir-content 0
  107. "Minimum number of directory name components included in buffer name."
  108. :type 'integer)
  109. (defcustom uniquify-separator nil
  110. "String separator for buffer name components.
  111. When `uniquify-buffer-name-style' is `post-forward', separates
  112. base file name from directory part in buffer names (default \"|\").
  113. When `uniquify-buffer-name-style' is `reverse', separates all
  114. file name components (default \"\\\")."
  115. :type '(choice (const nil) string))
  116. (defcustom uniquify-trailing-separator-p nil
  117. "If non-nil, add a file name separator to dired buffer names.
  118. If `uniquify-buffer-name-style' is `forward', add the separator at the end;
  119. if it is `reverse', add the separator at the beginning; otherwise, this
  120. variable is ignored."
  121. :type 'boolean)
  122. (defcustom uniquify-strip-common-suffix
  123. ;; Using it when uniquify-min-dir-content>0 doesn't make much sense.
  124. (eq 0 uniquify-min-dir-content)
  125. "If non-nil, strip common directory suffixes of conflicting files.
  126. E.g. if you open /a1/b/c/d and /a2/b/c/d, the buffer names will say
  127. \"d|a1\" and \"d|a2\" instead of \"d|a1/b/c\" and \"d|a2/b/c\".
  128. This can be handy when you have deep parallel hierarchies."
  129. :type 'boolean)
  130. (defvar uniquify-list-buffers-directory-modes '(dired-mode cvs-mode vc-dir-mode)
  131. "List of modes for which uniquify should obey `list-buffers-directory'.
  132. That means that when `buffer-file-name' is set to nil, `list-buffers-directory'
  133. contains the name of the directory which the buffer is visiting.")
  134. ;;; Utilities
  135. ;; uniquify-fix-list data structure
  136. (cl-defstruct (uniquify-item
  137. (:constructor nil) (:copier nil)
  138. (:constructor uniquify-make-item
  139. (base dirname buffer &optional proposed)))
  140. base dirname buffer proposed)
  141. ;; Internal variables used free
  142. (defvar uniquify-possibly-resolvable nil)
  143. (defvar-local uniquify-managed nil
  144. "Non-nil if the name of this buffer is managed by uniquify.
  145. It actually holds the list of `uniquify-item's corresponding to the conflict.")
  146. (put 'uniquify-managed 'permanent-local t)
  147. ;; Used in desktop.el to save the non-uniquified buffer name
  148. (defun uniquify-buffer-base-name ()
  149. "Return the base name of the current buffer.
  150. Return nil if the buffer is not managed by uniquify."
  151. (and uniquify-managed
  152. (uniquify-item-base (car uniquify-managed))))
  153. ;;; Main entry point.
  154. (defun uniquify-rationalize-file-buffer-names (base dirname newbuf)
  155. "Make file buffer names unique by adding segments from file name.
  156. If `uniquify-min-dir-content' > 0, always pulls that many
  157. file name elements.
  158. Arguments BASE, DIRNAME, and NEWBUF specify the new buffer that causes
  159. this rationalization."
  160. (interactive
  161. (list (if uniquify-managed
  162. (uniquify-item-base (car uniquify-managed)) (buffer-name))
  163. (uniquify-buffer-file-name (current-buffer))
  164. (current-buffer)))
  165. ;; Make sure we don't get confused by outdated uniquify-managed info in
  166. ;; this buffer.
  167. (with-current-buffer newbuf (setq uniquify-managed nil))
  168. (when dirname
  169. (setq dirname (expand-file-name (directory-file-name dirname)))
  170. (let ((fix-list (list (uniquify-make-item base dirname newbuf)))
  171. items)
  172. (dolist (buffer (buffer-list))
  173. (when (and (not (and uniquify-ignore-buffers-re
  174. (string-match uniquify-ignore-buffers-re
  175. (buffer-name buffer))))
  176. ;; Only try to rename buffers we actually manage.
  177. (setq items (buffer-local-value 'uniquify-managed buffer))
  178. (equal base (uniquify-item-base (car items)))
  179. ;; Don't re-add stuff we already have. Actually this
  180. ;; whole `and' test should only match at most once.
  181. (not (memq (car items) fix-list)))
  182. (unless (cdr items)
  183. ;; If there was no conflict, the buffer-name is equal to the
  184. ;; base-name and we may have missed a rename-buffer because
  185. ;; of code like in set-visited-file-name:
  186. ;; (or (string= new-name (buffer-name)) (rename-buffer new-name t))
  187. ;; So we need to refresh the dirname of the uniquify-item.
  188. (setf (uniquify-item-dirname (car items))
  189. (uniquify-buffer-file-name
  190. (uniquify-item-buffer (car items))))
  191. ;; This shouldn't happen, but maybe there's no dirname any more.
  192. (unless (uniquify-item-dirname (car items))
  193. (with-current-buffer (uniquify-item-buffer (car items))
  194. (setq uniquify-managed nil))
  195. (setq items nil)))
  196. ;; In case we missed some calls to kill-buffer, there may be dead
  197. ;; buffers in uniquify-managed, so filter them out.
  198. (setq items
  199. (delq nil (mapcar
  200. (lambda (item)
  201. (if (buffer-live-p (uniquify-item-buffer item))
  202. item))
  203. items)))
  204. (setq fix-list (append fix-list items))))
  205. ;; selects buffers whose names may need changing, and others that
  206. ;; may conflict, then bring conflicting names together
  207. (uniquify-rationalize fix-list))))
  208. ;; uniquify's version of buffer-file-name; result never contains trailing slash
  209. (defun uniquify-buffer-file-name (buffer)
  210. "Return name of directory, file BUFFER is visiting, or nil if none.
  211. Works on ordinary file-visiting buffers and buffers whose mode is mentioned
  212. in `uniquify-list-buffers-directory-modes', otherwise returns nil."
  213. (with-current-buffer buffer
  214. (let ((filename
  215. (or buffer-file-name
  216. (if (memq major-mode uniquify-list-buffers-directory-modes)
  217. list-buffers-directory))))
  218. (when filename
  219. (directory-file-name
  220. (file-name-directory
  221. (expand-file-name
  222. (directory-file-name filename))))))))
  223. (defun uniquify-rerationalize-w/o-cb (fix-list)
  224. "Re-rationalize the buffers in FIX-LIST, but ignoring `current-buffer'."
  225. (let ((new-fix-list nil))
  226. (dolist (item fix-list)
  227. (let ((buf (uniquify-item-buffer item)))
  228. (unless (or (eq buf (current-buffer)) (not (buffer-live-p buf)))
  229. (push item new-fix-list))))
  230. (when new-fix-list
  231. (uniquify-rationalize new-fix-list))))
  232. (defun uniquify-rationalize (fix-list)
  233. ;; Set up uniquify to re-rationalize after killing/renaming
  234. ;; if there is a conflict.
  235. (dolist (item fix-list)
  236. (with-current-buffer (uniquify-item-buffer item)
  237. ;; Refresh the dirnames and proposed names.
  238. (setf (uniquify-item-proposed item)
  239. (uniquify-get-proposed-name (uniquify-item-base item)
  240. (uniquify-item-dirname item)))
  241. (setq uniquify-managed fix-list)))
  242. ;; Strip any shared last directory names of the dirname.
  243. (when (and (cdr fix-list) uniquify-strip-common-suffix)
  244. (let ((strip t))
  245. (while (let* ((base (file-name-nondirectory
  246. (uniquify-item-dirname (car fix-list))))
  247. (items fix-list))
  248. (when (> (length base) 0)
  249. (while (and strip items)
  250. (unless (equal base (file-name-nondirectory
  251. (uniquify-item-dirname (pop items))))
  252. (setq strip nil)))
  253. strip))
  254. ;; It's all the same => strip.
  255. (dolist (item (prog1 fix-list (setq fix-list nil)))
  256. ;; Create new items because the old ones are kept (with the true
  257. ;; `dirname') for later rerationalizing.
  258. (push (uniquify-make-item (uniquify-item-base item)
  259. (let ((f (file-name-directory
  260. (uniquify-item-dirname item))))
  261. (and f (directory-file-name f)))
  262. (uniquify-item-buffer item)
  263. (uniquify-item-proposed item))
  264. fix-list)))))
  265. ;; If uniquify-min-dir-content is 0, this will end up just
  266. ;; passing fix-list to uniquify-rationalize-conflicting-sublist.
  267. (uniquify-rationalize-a-list fix-list))
  268. (defun uniquify-item-greaterp (item1 item2)
  269. (string-lessp (uniquify-item-proposed item2)
  270. (uniquify-item-proposed item1)))
  271. (defun uniquify-rationalize-a-list (fix-list &optional depth)
  272. (unless depth (setq depth uniquify-min-dir-content))
  273. (let (conflicting-sublist ; all elements have the same proposed name
  274. (old-proposed "")
  275. proposed)
  276. ;; Divide fix-list into items with same proposed names and pass them
  277. ;; to uniquify-rationalize-conflicting-sublist.
  278. (dolist (item (sort (copy-sequence fix-list) 'uniquify-item-greaterp))
  279. (setq proposed (uniquify-item-proposed item))
  280. (unless (equal proposed old-proposed)
  281. (uniquify-rationalize-conflicting-sublist conflicting-sublist
  282. old-proposed depth)
  283. (setq conflicting-sublist nil))
  284. (push item conflicting-sublist)
  285. (setq old-proposed proposed))
  286. (uniquify-rationalize-conflicting-sublist conflicting-sublist
  287. old-proposed depth)))
  288. (defun uniquify-get-proposed-name (base dirname &optional depth)
  289. (unless depth (setq depth uniquify-min-dir-content))
  290. (cl-assert (equal (directory-file-name dirname) dirname)) ;No trailing slash.
  291. ;; Distinguish directories by adding extra separator.
  292. (if (and uniquify-trailing-separator-p
  293. (file-directory-p (expand-file-name base dirname))
  294. (not (string-equal base "")))
  295. (cond ((eq uniquify-buffer-name-style 'forward)
  296. (setq base (file-name-as-directory base)))
  297. ;; (setq base (concat base "/")))
  298. ((eq uniquify-buffer-name-style 'reverse)
  299. (setq base (concat (or uniquify-separator "\\") base)))))
  300. (let ((extra-string nil)
  301. (n depth))
  302. (while (and (> n 0) dirname)
  303. (let ((file (file-name-nondirectory dirname)))
  304. (when (setq dirname (file-name-directory dirname))
  305. (setq dirname (directory-file-name dirname)))
  306. (setq n (1- n))
  307. (push (if (zerop (length file)) ;nil or "".
  308. (prog1 (or (file-remote-p dirname) "")
  309. (setq dirname nil)) ;Could be `dirname' iso "".
  310. file)
  311. extra-string)))
  312. (when (zerop n)
  313. (if (and dirname extra-string
  314. (equal dirname (file-name-directory dirname)))
  315. ;; We're just before the root. Let's add the leading / already.
  316. ;; With "/a/b"+"/c/d/b" this leads to "/a/b" and "d/b" but with
  317. ;; "/a/b"+"/c/a/b" this leads to "/a/b" and "a/b".
  318. (push "" extra-string))
  319. (setq uniquify-possibly-resolvable t))
  320. (cond
  321. ((null extra-string) base)
  322. ((string-equal base "") ;Happens for dired buffers on the root directory.
  323. (mapconcat 'identity extra-string "/"))
  324. ((eq uniquify-buffer-name-style 'reverse)
  325. (mapconcat 'identity
  326. (cons base (nreverse extra-string))
  327. (or uniquify-separator "\\")))
  328. ((eq uniquify-buffer-name-style 'forward)
  329. (mapconcat 'identity (nconc extra-string (list base))
  330. "/"))
  331. ((eq uniquify-buffer-name-style 'post-forward)
  332. (concat base (or uniquify-separator "|")
  333. (mapconcat 'identity extra-string "/")))
  334. ((eq uniquify-buffer-name-style 'post-forward-angle-brackets)
  335. (concat base "<" (mapconcat 'identity extra-string "/")
  336. ">"))
  337. (t (error "Bad value for uniquify-buffer-name-style: %s"
  338. uniquify-buffer-name-style)))))
  339. ;; Deal with conflicting-sublist, all of whose elements have identical
  340. ;; "base" components.
  341. (defun uniquify-rationalize-conflicting-sublist (conf-list old-name depth)
  342. (when conf-list
  343. (if (or (cdr conf-list)
  344. ;; Check that the proposed name doesn't conflict with some
  345. ;; existing buffer.
  346. (let ((buf (get-buffer old-name)))
  347. (and buf (not (eq buf (uniquify-item-buffer (car conf-list)))))))
  348. (when uniquify-possibly-resolvable
  349. (setq uniquify-possibly-resolvable nil
  350. depth (1+ depth))
  351. (dolist (item conf-list)
  352. (setf (uniquify-item-proposed item)
  353. (uniquify-get-proposed-name
  354. (uniquify-item-base item)
  355. (uniquify-item-dirname item)
  356. depth)))
  357. (uniquify-rationalize-a-list conf-list depth))
  358. (unless (string= old-name "")
  359. (uniquify-rename-buffer (car conf-list) old-name)))))
  360. (defun uniquify-rename-buffer (item newname)
  361. (let ((buffer (uniquify-item-buffer item)))
  362. (unless (equal newname (buffer-name buffer))
  363. (with-current-buffer buffer
  364. (let ((uniquify-buffer-name-style nil)) ;Avoid hooks on rename-buffer.
  365. ;; Pass the `unique' arg, so the advice doesn't mark it as unmanaged.
  366. (rename-buffer newname t))))))
  367. ;;; Hooks from the rest of Emacs
  368. (defun uniquify-maybe-rerationalize-w/o-cb ()
  369. "Re-rationalize buffer names, ignoring current buffer."
  370. (and (cdr uniquify-managed)
  371. uniquify-buffer-name-style
  372. (uniquify-rerationalize-w/o-cb uniquify-managed)))
  373. ;; Buffer deletion
  374. ;; Rerationalize after a buffer is killed, to reduce coinciding buffer names.
  375. ;; This mechanism uses `kill-buffer-hook', which runs *before* deletion, so
  376. ;; it calls `uniquify-rerationalize-w/o-cb' to rerationalize the buffer list
  377. ;; ignoring the current buffer (which is going to be deleted anyway).
  378. (defun uniquify-kill-buffer-function ()
  379. "Re-rationalize buffer names, ignoring current buffer.
  380. For use on `kill-buffer-hook'."
  381. (and uniquify-after-kill-buffer-p
  382. (uniquify-maybe-rerationalize-w/o-cb)))
  383. ;; Ideally we'd like to add it buffer-locally, but that doesn't work
  384. ;; because kill-buffer-hook is not permanent-local :-(
  385. ;; FIXME kill-buffer-hook _is_ permanent-local in 22+.
  386. (add-hook 'kill-buffer-hook 'uniquify-kill-buffer-function)
  387. ;; The logical place to put all this code is in generate-new-buffer-name.
  388. ;; It's written in C, so we would add a generate-new-buffer-name-function
  389. ;; which, if non-nil, would be called instead of the C. One problem with
  390. ;; that is that generate-new-buffer-name takes a potential buffer name as
  391. ;; its argument -- not other information, such as what file the buffer will
  392. ;; visit.
  393. ;; The below solution works because generate-new-buffer-name is called
  394. ;; only by rename-buffer (which, as of 19.29, is never called from C) and
  395. ;; generate-new-buffer, which is called only by Lisp functions
  396. ;; create-file-buffer and rename-uniquely. Rename-uniquely generally
  397. ;; isn't used for buffers visiting files, so it's sufficient to hook
  398. ;; rename-buffer and create-file-buffer. (Setting find-file-hook isn't
  399. ;; sufficient.)
  400. (advice-add 'rename-buffer :around #'uniquify--rename-buffer-advice)
  401. (defun uniquify--rename-buffer-advice (rb-fun newname &optional unique &rest args)
  402. "Uniquify buffer names with parts of directory name."
  403. (let ((retval (apply rb-fun newname unique args)))
  404. (uniquify-maybe-rerationalize-w/o-cb)
  405. (if (null unique)
  406. ;; Mark this buffer so it won't be renamed by uniquify.
  407. (setq uniquify-managed nil)
  408. (when uniquify-buffer-name-style
  409. ;; Rerationalize w.r.t the new name.
  410. (uniquify-rationalize-file-buffer-names
  411. newname
  412. (uniquify-buffer-file-name (current-buffer))
  413. (current-buffer))
  414. (setq retval (buffer-name (current-buffer)))))
  415. retval))
  416. (advice-add 'create-file-buffer :around #'uniquify--create-file-buffer-advice)
  417. (defun uniquify--create-file-buffer-advice (cfb-fun filename &rest args)
  418. "Uniquify buffer names with parts of directory name."
  419. (let ((retval (apply cfb-fun filename args)))
  420. (if uniquify-buffer-name-style
  421. (let ((filename (expand-file-name (directory-file-name filename))))
  422. (uniquify-rationalize-file-buffer-names
  423. (file-name-nondirectory filename)
  424. (file-name-directory filename) retval)))
  425. retval))
  426. ;;; The End
  427. (defun uniquify-unload-function ()
  428. "Unload the uniquify library."
  429. (save-current-buffer
  430. (let ((buffers nil))
  431. (dolist (buf (buffer-list))
  432. (set-buffer buf)
  433. (when uniquify-managed
  434. (push (cons buf (uniquify-item-base (car uniquify-managed))) buffers)))
  435. (advice-remove 'rename-buffer #'uniquify--rename-buffer-advice)
  436. (advice-remove 'create-file-buffer #'uniquify--create-file-buffer-advice)
  437. (dolist (buf buffers)
  438. (set-buffer (car buf))
  439. (rename-buffer (cdr buf) t))))
  440. ;; continue standard unloading
  441. nil)
  442. (provide 'uniquify)
  443. ;;; uniquify.el ends here