summaryrefslogtreecommitdiff
path: root/lisp/dired.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2009-11-12 22:37:58 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2009-11-12 22:37:58 +0000
commit054049883d9f0ea3e184ffd4a661a8f96eea9863 (patch)
treeb14addb188ddd33b8f1809e3623ec487b61a1344 /lisp/dired.el
parent5297bc10b012e75d28d18b73880ad0e2e01cb57c (diff)
downloademacs-054049883d9f0ea3e184ffd4a661a8f96eea9863.tar.gz
(dired-save-positions, dired-restore-positions): New funs.
(dired-revert): Use them (bug#4880).
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el26
1 files changed, 21 insertions, 5 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 9e2c65c5c47..cf78354ad8f 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1104,8 +1104,7 @@ Should not fail even on completely garbaged buffers.
Preserves old cursor, marks/flags, hidden-p."
(widen) ; just in case user narrowed
(let ((modflag (buffer-modified-p))
- (opoint (point))
- (ofile (dired-get-filename nil t))
+ (positions (dired-save-positions))
(mark-alist nil) ; save marked files
(hidden-subdirs (dired-remember-hidden))
(old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
@@ -1125,9 +1124,7 @@ Preserves old cursor, marks/flags, hidden-p."
;; ... run the hook for the whole buffer, and only after markers
;; have been reinserted (else omitting in dired-x would omit marked files)
(run-hooks 'dired-after-readin-hook) ; no need to narrow
- (or (and ofile (dired-goto-file ofile)) ; move cursor to where it
- (goto-char opoint)) ; was before
- (dired-move-to-filename)
+ (dired-restore-positions positions)
(save-excursion ; hide subdirs that were hidden
(dolist (dir hidden-subdirs)
(if (dired-goto-subdir dir)
@@ -1141,6 +1138,25 @@ Preserves old cursor, marks/flags, hidden-p."
;; Subroutines of dired-revert
;; Some of these are also used when inserting subdirs.
+(defun dired-save-positions ()
+ "Return the current positions in all windows displaying this dired buffer.
+The positions have the form (WINDOW FILENAME POINT)."
+ (mapcar (lambda (w)
+ (list w
+ (with-selected-window w
+ (dired-get-filename nil t))
+ (window-point w)))
+ (get-buffer-window-list nil 0 t)))
+
+(defun dired-restore-positions (positions)
+ "Restore POSITIONS saved with `dired-save-positions'."
+ (dolist (win-file-pos positions)
+ (with-selected-window (car win-file-pos)
+ (unless (and (nth 1 win-file-pos)
+ (dired-goto-file (nth 1 win-file-pos)))
+ (goto-char (nth 2 win-file-pos))
+ (dired-move-to-filename)))))
+
(defun dired-remember-marks (beg end)
"Return alist of files and their marks, from BEG to END."
(if selective-display ; must unhide to make this work.