Fix bug: under Linux you can not go upper for '/dir' like dir (that lie
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 14 Sep 2010 23:14:43 +0300
changeset 471 1d59b8a9d8a0
parent 470 f859726fcca9
child 473 1334dc79ea80
Fix bug: under Linux you can not go upper for '/dir' like dir (that lie directly in '/' root). Because substring last arg is exclusive index. Also rename local var.
.emacs-my
--- a/.emacs-my	Tue Sep 14 17:18:05 2010 +0300
+++ b/.emacs-my	Tue Sep 14 23:14:43 2010 +0300
@@ -465,15 +465,16 @@
 (defun my-dired-up-dir ()
   "'Reuse' buffer if enter to dir or open new buffer if enter to file."
   (interactive)
-  (let* ( (dir (dired-current-directory)) (i (- (length dir) 2)) newdir )
+  ;; (dired-current-directory) always end with trailing '/' char.
+  (let* ( (dir (dired-current-directory)) (i (- (length dir) 2)) upperdir )
     (while (and
             (>= i 0)
             (not (equal (aref dir i) ?/)) )
       (setq i (- i 1))
       )
-    (setq newdir (substring dir 0 (max 0 i)))
-    (when (file-directory-p newdir)
-      (find-alternate-file newdir)
+    (setq upperdir (substring dir 0 (+ i 1)))
+    (when (file-directory-p upperdir)
+      (find-alternate-file upperdir)
       (dired-goto-file dir)
       )
     ))