aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2001-10-05 09:27:29 +0000
committerGerd Moellmann2001-10-05 09:27:29 +0000
commit1c549bbe5655fef730dc2ca7bd6a30a60fd289a0 (patch)
tree1f71fe5d9ddc7e7a2bf0cc8c5dab09fe6a903444
parente5da45fda7e205a900dfa62236afa239bfcb534a (diff)
downloademacs-1c549bbe5655fef730dc2ca7bd6a30a60fd289a0.tar.gz
emacs-1c549bbe5655fef730dc2ca7bd6a30a60fd289a0.zip
(uniquify-get-proposed-name): Don't assume dirsep is /.
(uniquify-reverse-components): Remove.
-rw-r--r--lisp/uniquify.el126
1 files changed, 54 insertions, 72 deletions
diff --git a/lisp/uniquify.el b/lisp/uniquify.el
index 72e3d7893bf..361fae2ea17 100644
--- a/lisp/uniquify.el
+++ b/lisp/uniquify.el
@@ -43,11 +43,6 @@
43;; A version of uniquify.el that works under Emacs 18, Emacs 19, XEmacs, 43;; A version of uniquify.el that works under Emacs 18, Emacs 19, XEmacs,
44;; and InfoDock is available from the maintainer. 44;; and InfoDock is available from the maintainer.
45 45
46;; Doesn't work under NT when backslash is used as a path separator (forward
47;; slash path separator works fine). To fix, check system-type against
48;; 'windows-nt, write a routine that breaks paths down into components.
49;; (Surprisingly, there isn't one built in.)
50
51;;; Change Log: 46;;; Change Log:
52 47
53;; Originally by Dick King <king@reasoning.com> 15 May 86 48;; Originally by Dick King <king@reasoning.com> 15 May 86
@@ -259,59 +254,61 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil."
259 old-proposed depth))) 254 old-proposed depth)))
260 255
261(defun uniquify-get-proposed-name (base filename depth) 256(defun uniquify-get-proposed-name (base filename depth)
262 (let (index 257 (assert (equal base (uniquify-file-name-nondirectory filename)))
263 (extra-string "") 258 (assert (equal (directory-file-name filename) filename))
264 (fn filename) 259
260 ;; Distinguish directories by adding extra separator.
261 (if (and uniquify-trailing-separator-p
262 (file-directory-p filename)
263 (not (string-equal base "")))
264 (cond ((eq uniquify-buffer-name-style 'forward)
265 (setq base (file-name-as-directory base)))
266 ;; (setq base (concat base "/")))
267 ((eq uniquify-buffer-name-style 'reverse)
268 (setq base (concat (or uniquify-separator "\\") base)))))
269
270 (let ((extra-string nil)
265 (n depth)) 271 (n depth))
266 (while (and (> n 0) 272 (while (and (> n 0) filename
267 (setq index (string-match 273 (setq filename (file-name-directory filename))
268 (concat "\\(^\\|/[^/]*\\)/" 274 (setq filename (directory-file-name filename)))
269 (regexp-quote extra-string) 275 (let ((file (file-name-nondirectory filename)))
270 (regexp-quote base) 276 (setq n (1- n))
271 "\\'") 277 (push (if (zerop (length file)) ;nil or "".
272 fn))) 278 (prog1 "" (setq filename nil)) ;Could be `filename' iso "".
273 (setq extra-string (substring fn 279 file)
274 (if (zerop index) 0 (1+ index)) 280 extra-string)))
275 ;; (- (length base)) fails for base = "". 281 (when (zerop n)
276 ;; Equivalently, we could have used 282 (if (and filename
277 ;; (apply 'substring ... 283 (setq filename (file-name-directory filename))
278 ;; (and (not (string= "" base)) 284 (equal filename
279 ;; (list (- (length base))))) 285 (file-name-directory (directory-file-name filename))))
280 (- (length fn) (length base))) 286 ;; We're just before the root. Let's add the leading / already.
281 n (1- n))) 287 ;; With "/a/b"+"/c/d/b" this leads to "/a/b" and "d/b" but with
282 (if (zerop n) (setq uniquify-possibly-resolvable t)) 288 ;; "/a/b"+"/c/a/b" this leads to "/a/b" and "a/b".
283 289 (push "" extra-string))
284 290 (setq uniquify-possibly-resolvable t))
285 ;; Distinguish directories by adding extra separator. 291
286 (if (and uniquify-trailing-separator-p 292 (cond
287 (file-directory-p fn) 293 ((null extra-string) base)
288 (not (string-equal base ""))) 294 ((string-equal base "") ;Happens for dired buffers on the root directory.
289 (cond ((eq uniquify-buffer-name-style 'forward) 295 (mapconcat 'identity extra-string (string directory-sep-char)))
290 (setq base (concat base "/"))) 296 ((eq uniquify-buffer-name-style 'reverse)
291 ((eq uniquify-buffer-name-style 'reverse) 297 (let ((dirsep (string directory-sep-char)))
292 (setq base (concat (or uniquify-separator "\\") base))))) 298 (mapconcat 'identity
293 299 (cons base (nreverse extra-string))
294 ;; Trim trailing separator on directory part 300 (or uniquify-separator "\\"))))
295 (if (and (not (string-equal extra-string "")) 301 ((eq uniquify-buffer-name-style 'forward)
296 (or (eq uniquify-buffer-name-style 'post-forward) 302 (mapconcat 'identity (nconc extra-string (list base))
297 (eq uniquify-buffer-name-style 'post-forward-angle-brackets))) 303 (string directory-sep-char)))
298 (setq extra-string (substring extra-string 0 304 ((eq uniquify-buffer-name-style 'post-forward)
299 (- (length extra-string) 1)))) 305 (concat base (or uniquify-separator "|")
300 306 (mapconcat 'identity extra-string (string directory-sep-char))))
301 (cond ((string-equal extra-string "") 307 ((eq uniquify-buffer-name-style 'post-forward-angle-brackets)
302 base) 308 (concat base "<" (mapconcat 'identity extra-string
303 ((string-equal base "") 309 (string directory-sep-char)) ">"))
304 extra-string) 310 (t (error "Bad value for uniquify-buffer-name-style: %s"
305 ((eq uniquify-buffer-name-style 'forward) 311 uniquify-buffer-name-style)))))
306 (concat extra-string base))
307 ((eq uniquify-buffer-name-style 'reverse)
308 (concat base (uniquify-reverse-components extra-string)))
309 ((eq uniquify-buffer-name-style 'post-forward)
310 (concat base (or uniquify-separator "|") extra-string))
311 ((eq uniquify-buffer-name-style 'post-forward-angle-brackets)
312 (concat base "<" extra-string ">"))
313 (t (error "Bad value for uniquify-buffer-name-style: %s"
314 uniquify-buffer-name-style)))))
315 312
316 313
317;; Deal with conflicting-sublist, all of whose elements have identical 314;; Deal with conflicting-sublist, all of whose elements have identical
@@ -343,21 +340,6 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil."
343 (rename-buffer newname) 340 (rename-buffer newname)
344 (set-buffer unset))))) 341 (set-buffer unset)))))
345 342
346(defun uniquify-reverse-components (instring)
347 (let ((sofar '())
348 (cursor 0)
349 (len (length instring))
350 (sep (or uniquify-separator "\\")))
351 (while (< cursor len)
352 (if (= (aref instring cursor) ?/)
353 (setq sofar (cons sep sofar)
354 cursor (1+ cursor))
355 (let ((first-slash (or (string-match "/" instring cursor) len)))
356 (setq sofar (cons (substring instring cursor first-slash) sofar)
357 cursor first-slash))))
358 (apply (function concat) sofar)))
359
360
361;;; Hooks from the rest of Emacs 343;;; Hooks from the rest of Emacs
362 344
363;; The logical place to put all this code is in generate-new-buffer-name. 345;; The logical place to put all this code is in generate-new-buffer-name.