all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#15329: saveplace restores dired positions to random places
@ 2013-09-10 20:45 Juri Linkov
  2013-09-11 20:45 ` Juri Linkov
  2013-09-11 20:45 ` Juri Linkov
  0 siblings, 2 replies; 17+ messages in thread
From: Juri Linkov @ 2013-09-10 20:45 UTC (permalink / raw)
  To: 15329

Tags: patch

Remembering dired positions is a good feature, but
unfortunately in its current implementation is useless.

The problem is that often the position of point in Dired
is restored to random places because in Dired buffers
it depends on many irrelevant ever-changing factors
such as the total size of all files in the directory
and available space (thus the line with this information
changes its length), sizes of each file above the restored
file in the Dired buffer also accounts to the incorrect position
of point, also added/deleted files in Dired change the restored
position to random places, different sorting order, etc.

An obvious solution to this problem is to save the
current file name in Dired instead of its point.

It seems saving information other than point doesn't contradict
the purpose of saveplace.el that automatically saves places where
visiting them later automatically moves point to the saved position.
Also elements of `save-place-alist' are (FILENAME . POSITION),
not more limited (FILENAME . POINT).  So saving a string to
POSITION would be consistent with the design of saveplace.el.

=== modified file 'lisp/saveplace.el'
--- lisp/saveplace.el	2013-06-14 09:32:01 +0000
+++ lisp/saveplace.el	2013-09-10 20:44:01 +0000
@@ -176,14 +178,17 @@ (defun save-place-to-alist ()
                    (not (string-match save-place-ignore-files-regexp
                                       item))))
       (let ((cell (assoc item save-place-alist))
-            (position (if (not (eq major-mode 'hexl-mode))
-                          (point)
-                        (with-no-warnings
-                          (1+ (hexl-current-address))))))
+            (position (cond ((eq major-mode 'hexl-mode)
+			     (with-no-warnings
+			       (1+ (hexl-current-address))))
+			    ((derived-mode-p 'dired-mode)
+			     (or (dired-get-filename nil t) (point)))
+			    (t (point)))))
         (if cell
             (setq save-place-alist (delq cell save-place-alist)))
         (if (and save-place
-                 (not (= position 1)))  ;; Optimize out the degenerate case.
+                 (not (and (integerp position)
+			   (= position 1)))) ;; Optimize out the degenerate case.
             (setq save-place-alist
                   (cons (cons item position)
                         save-place-alist)))))))
@@ -298,7 +304,8 @@ (defun save-place-find-file-hook ()
     (if cell
 	(progn
 	  (or revert-buffer-in-progress-p
-	      (goto-char (cdr cell)))
+	      (and (integerp (cdr cell))
+		   (goto-char (cdr cell))))
           ;; and make sure it will be saved again for later
           (setq save-place t)))))
 
@@ -309,7 +318,10 @@ (defun save-place-dired-hook ()
     (if cell
         (progn
           (or revert-buffer-in-progress-p
-              (goto-char (cdr cell)))
+              (cond ((integerp (cdr cell))
+		     (goto-char (cdr cell)))
+		    ((stringp (cdr cell))
+		     (dired-goto-file (cdr cell)))))
           ;; and make sure it will be saved again for later
           (setq save-place t)))))
 





^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2013-12-21  2:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-10 20:45 bug#15329: saveplace restores dired positions to random places Juri Linkov
2013-09-11 20:45 ` Juri Linkov
2013-09-11 20:45 ` Juri Linkov
2013-09-12 16:12   ` Karl Fogel
2013-09-12 19:13     ` Stefan Monnier
2013-09-12 19:13     ` Stefan Monnier
2013-09-12 20:52     ` Juri Linkov
2013-09-12 20:52     ` Juri Linkov
2013-10-03 21:37       ` Karl Fogel
2013-12-15 20:20         ` Juri Linkov
2013-12-15 21:43           ` Drew Adams
2013-12-16 20:58             ` Juri Linkov
2013-12-16 21:15               ` Drew Adams
2013-12-20 20:20           ` Juri Linkov
2013-12-21  2:09             ` Karl Fogel
2013-10-03 21:37       ` Karl Fogel
2013-09-12 16:12   ` Karl Fogel

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.