aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancesco Potortì2001-08-01 19:07:33 +0000
committerFrancesco Potortì2001-08-01 19:07:33 +0000
commit57749acfbde0b39099ca29632a2875937faf8314 (patch)
treedeab840846f8b5fc2ba77bbbc57e37c1ec311b8c
parentfc10ed8c9d24ebec1ce224aeea951a0130ac35e9 (diff)
downloademacs-57749acfbde0b39099ca29632a2875937faf8314.tar.gz
emacs-57749acfbde0b39099ca29632a2875937faf8314.zip
These changes correct a corner case that the old code managed correctly.
Precisely when you have a buffer visiting a file in the root directory and then revert it to a file with the same name in a different directory. (uniquify-fix-item-proposed): Renamed from uniquify-fix-item-min-proposed. (uniquify-set-proposed): New function. (uniquify-rationalize-file-buffer-names): Code reshuffled for clarity and speed. (uniquify-item-greaterp): Substitutes uniquify-item-lessp. This is equivalent to what the old code did. (uniquify-rationalize-a-list): Never recompute the proposed name. Sort the conflicting sublist before rationalising it: this is equivalent to what the old code did, but one directory element at a time, and only when necessary. (uniquify-rationalize-conflicting-sublist): Recompute here the proposed name.
-rw-r--r--lisp/uniquify.el62
1 files changed, 31 insertions, 31 deletions
diff --git a/lisp/uniquify.el b/lisp/uniquify.el
index 4159151e458..0979cfaa0e5 100644
--- a/lisp/uniquify.el
+++ b/lisp/uniquify.el
@@ -74,7 +74,7 @@
74;; Andre Srinivasan <andre@visigenic.com> 9 Sep 97 74;; Andre Srinivasan <andre@visigenic.com> 9 Sep 97
75;; Add uniquify-list-buffers-directory-modes 75;; Add uniquify-list-buffers-directory-modes
76;; Stefan Monnier <monnier@cs.yale.edu> 17 Nov 2000 76;; Stefan Monnier <monnier@cs.yale.edu> 17 Nov 2000
77;; Cleanup of uniquify-*-lessp reduced consing when using lots of buffers 77;; Algorithm change reduced consing when using lots of buffers
78;; Francesco Potortì <pot@gnu.org> (ideas by rms and monnier) 2001-07-18 78;; Francesco Potortì <pot@gnu.org> (ideas by rms and monnier) 2001-07-18
79 79
80;; Valuable feedback was provided by 80;; Valuable feedback was provided by
@@ -176,7 +176,8 @@ contains the name of the directory which the buffer is visiting.")
176(defalias 'uniquify-fix-item-base 'car) 176(defalias 'uniquify-fix-item-base 'car)
177(defalias 'uniquify-fix-item-filename 'cadr) 177(defalias 'uniquify-fix-item-filename 'cadr)
178(defsubst uniquify-fix-item-buffer (x) (car (cdr (cdr x)))) 178(defsubst uniquify-fix-item-buffer (x) (car (cdr (cdr x))))
179(defsubst uniquify-fix-item-min-proposed (x) (nth 3 x)) 179(defsubst uniquify-fix-item-proposed (x) (nth 3 x))
180(defsubst uniquify-set-proposed (x p) (setcar (nthcdr 3 x) p))
180 181
181;; Internal variables used free 182;; Internal variables used free
182(defvar uniquify-non-file-buffer-names nil) 183(defvar uniquify-non-file-buffer-names nil)
@@ -195,9 +196,8 @@ file name elements. Arguments cause only a subset of buffers to be renamed."
195 (uniquify-file-name-nondirectory newbuffile)))) 196 (uniquify-file-name-nondirectory newbuffile))))
196 (dolist (buffer (buffer-list)) 197 (dolist (buffer (buffer-list))
197 (let ((bufname (buffer-name buffer)) 198 (let ((bufname (buffer-name buffer))
198 bfn rawname min-proposed) 199 bfn rawname proposed)
199 (if (and (not (string= " **lose**" bufname)) 200 (if (and (not (and uniquify-ignore-buffers-re
200 (not (and uniquify-ignore-buffers-re
201 (string-match uniquify-ignore-buffers-re 201 (string-match uniquify-ignore-buffers-re
202 bufname))) 202 bufname)))
203 (setq bfn (if (eq buffer newbuf) 203 (setq bfn (if (eq buffer newbuf)
@@ -210,14 +210,12 @@ file name elements. Arguments cause only a subset of buffers to be renamed."
210 (setq rawname (uniquify-file-name-nondirectory bfn)) 210 (setq rawname (uniquify-file-name-nondirectory bfn))
211 (or (not newbuffile) 211 (or (not newbuffile)
212 (equal rawname newbuffile-nd)) 212 (equal rawname newbuffile-nd))
213 (setq min-proposed (uniquify-get-proposed-name 213 (setq proposed (uniquify-get-proposed-name
214 rawname bfn uniquify-min-dir-content))) 214 rawname bfn uniquify-min-dir-content)))
215 (push (list rawname bfn buffer min-proposed) fix-list) 215 (push (list rawname bfn buffer proposed) fix-list)
216 (push (list bufname) uniquify-non-file-buffer-names)))) 216 (push (list bufname) uniquify-non-file-buffer-names))))
217 ;; selects buffers whose names may need changing, and others that 217 ;; selects buffers whose names may need changing, and others that
218 ;; may conflict. 218 ;; may conflict, then bring conflicting names together
219 (setq fix-list (sort fix-list 'uniquify-item-lessp))
220 ;; bringing conflicting names together
221 (uniquify-rationalize-a-list fix-list uniquify-min-dir-content))) 219 (uniquify-rationalize-a-list fix-list uniquify-min-dir-content)))
222 220
223;; uniquify's version of buffer-file-name; result never contains trailing slash 221;; uniquify's version of buffer-file-name; result never contains trailing slash
@@ -240,21 +238,16 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil."
240 (car dired-directory) 238 (car dired-directory)
241 dired-directory))))))))) 239 dired-directory)))))))))
242 240
243(defun uniquify-item-lessp (item1 item2) 241(defun uniquify-item-greaterp (item1 item2)
244 (string-lessp (uniquify-fix-item-min-proposed item1) 242 (string-lessp (uniquify-fix-item-proposed item2)
245 (uniquify-fix-item-min-proposed item2))) 243 (uniquify-fix-item-proposed item1)))
246 244
247(defun uniquify-rationalize-a-list (fix-list depth) 245(defun uniquify-rationalize-a-list (fix-list depth)
248 (let (conflicting-sublist ; all elements have the same proposed name 246 (let (conflicting-sublist ; all elements have the same proposed name
249 (old-name "") 247 (old-name "")
250 proposed-name) 248 proposed-name)
251 (dolist (item fix-list) 249 (dolist (item (sort fix-list 'uniquify-item-greaterp))
252 (setq proposed-name 250 (setq proposed-name (uniquify-fix-item-proposed item))
253 (if (= depth uniquify-min-dir-content)
254 (uniquify-fix-item-min-proposed item)
255 (uniquify-get-proposed-name (uniquify-fix-item-base item)
256 (uniquify-fix-item-filename item)
257 depth)))
258 (unless (equal proposed-name old-name) 251 (unless (equal proposed-name old-name)
259 (uniquify-rationalize-conflicting-sublist conflicting-sublist 252 (uniquify-rationalize-conflicting-sublist conflicting-sublist
260 old-name depth) 253 old-name depth)
@@ -322,16 +315,23 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil."
322 315
323;; Deal with conflicting-sublist, all of whose elements have identical 316;; Deal with conflicting-sublist, all of whose elements have identical
324;; "base" components. 317;; "base" components.
325(defun uniquify-rationalize-conflicting-sublist (conflicting-sublist old-name depth) 318(defun uniquify-rationalize-conflicting-sublist (conf-list old-name depth)
326 (or (null conflicting-sublist) 319 (when conf-list
327 (and (null (cdr conflicting-sublist)) 320 (if (or (cdr conf-list)
328 (not (assoc old-name uniquify-non-file-buffer-names)) 321 (assoc old-name uniquify-non-file-buffer-names))
329 (or (and (not (string= old-name "")) 322 (when uniquify-possibly-resolvable
330 (uniquify-rename-buffer (car conflicting-sublist) old-name)) 323 (setq uniquify-possibly-resolvable nil
331 t)) 324 depth (1+ depth))
332 (when uniquify-possibly-resolvable 325 (dolist (item conf-list)
333 (setq uniquify-possibly-resolvable nil) 326 (uniquify-set-proposed
334 (uniquify-rationalize-a-list conflicting-sublist (1+ depth))))) 327 item (uniquify-get-proposed-name
328 (uniquify-fix-item-base item)
329 (uniquify-fix-item-filename item)
330 depth)))
331 (uniquify-rationalize-a-list conf-list depth))
332 (unless (string= old-name "")
333 (uniquify-rename-buffer (car conf-list) old-name)))))
334
335 335
336(defun uniquify-rename-buffer (item newname) 336(defun uniquify-rename-buffer (item newname)
337 (let ((buffer (uniquify-fix-item-buffer item))) 337 (let ((buffer (uniquify-fix-item-buffer item)))