diff options
| author | Juri Linkov | 2009-12-05 23:22:03 +0000 |
|---|---|---|
| committer | Juri Linkov | 2009-12-05 23:22:03 +0000 |
| commit | 065543e754725e54e7b24add15ae7fd28afd6262 (patch) | |
| tree | af5b238663d7ee3942a42acf0cbe95571fc168aa | |
| parent | 426ac9499e082e4ab83a18639fd45b720584f347 (diff) | |
| download | emacs-065543e754725e54e7b24add15ae7fd28afd6262.tar.gz emacs-065543e754725e54e7b24add15ae7fd28afd6262.zip | |
Save and restore dired buffer's point positions too. (Bug#4880)
(dired-save-positions): Return in the first element
buffer's position in format (BUFFER DIRED-FILENAME BUFFER-POINT).
Doc fix.
(dired-restore-positions): First restore buffer's position.
While restoring window's positions, check if window still displays
the original buffer.
| -rw-r--r-- | lisp/ChangeLog | 11 | ||||
| -rw-r--r-- | lisp/dired.el | 45 |
2 files changed, 42 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9ff951b09a3..04203266058 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2009-12-05 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | Save and restore dired buffer's point positions too. (Bug#4880) | ||
| 4 | |||
| 5 | * dired.el (dired-save-positions): Return in the first element | ||
| 6 | buffer's position in format (BUFFER DIRED-FILENAME BUFFER-POINT). | ||
| 7 | Doc fix. | ||
| 8 | (dired-restore-positions): First restore buffer's position. | ||
| 9 | While restoring window's positions, check if window still displays | ||
| 10 | the original buffer. | ||
| 11 | |||
| 1 | 2009-12-05 Chong Yidong <cyd@stupidchicken.com> | 12 | 2009-12-05 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 13 | ||
| 3 | * bindings.el (complete-symbol): Call semantic-ia-complete-symbol | 14 | * bindings.el (complete-symbol): Call semantic-ia-complete-symbol |
diff --git a/lisp/dired.el b/lisp/dired.el index c34ff4ec3f7..3f165812c97 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -1169,23 +1169,40 @@ Preserves old cursor, marks/flags, hidden-p." | |||
| 1169 | ;; Some of these are also used when inserting subdirs. | 1169 | ;; Some of these are also used when inserting subdirs. |
| 1170 | 1170 | ||
| 1171 | (defun dired-save-positions () | 1171 | (defun dired-save-positions () |
| 1172 | "Return the current positions in all windows displaying this dired buffer. | 1172 | "Return current positions in the buffer and all windows with this directory. |
| 1173 | The positions have the form (WINDOW FILENAME POINT)." | 1173 | The positions have the form (BUFFER-POSITION WINDOW-POSITIONS). |
| 1174 | (mapcar (lambda (w) | 1174 | |
| 1175 | (list w | 1175 | BUFFER-POSITION is the point position in the current dired buffer. |
| 1176 | (with-selected-window w | 1176 | The buffer position have the form (BUFFER DIRED-FILENAME BUFFER-POINT). |
| 1177 | (dired-get-filename nil t)) | 1177 | |
| 1178 | (window-point w))) | 1178 | WINDOW-POSITIONS are current positions in all windows displaying |
| 1179 | (get-buffer-window-list nil 0 t))) | 1179 | this dired buffer. The window positions have the form (WINDOW |
| 1180 | DIRED-FILENAME WINDOW-POINT)." | ||
| 1181 | (list | ||
| 1182 | (list (current-buffer) (dired-get-filename nil t) (point)) | ||
| 1183 | (mapcar (lambda (w) | ||
| 1184 | (list w | ||
| 1185 | (with-selected-window w | ||
| 1186 | (dired-get-filename nil t)) | ||
| 1187 | (window-point w))) | ||
| 1188 | (get-buffer-window-list nil 0 t)))) | ||
| 1180 | 1189 | ||
| 1181 | (defun dired-restore-positions (positions) | 1190 | (defun dired-restore-positions (positions) |
| 1182 | "Restore POSITIONS saved with `dired-save-positions'." | 1191 | "Restore POSITIONS saved with `dired-save-positions'." |
| 1183 | (dolist (win-file-pos positions) | 1192 | (let* ((buf-file-pos (nth 0 positions)) |
| 1184 | (with-selected-window (car win-file-pos) | 1193 | (buffer (nth 0 buf-file-pos))) |
| 1185 | (unless (and (nth 1 win-file-pos) | 1194 | (unless (and (nth 1 buf-file-pos) |
| 1186 | (dired-goto-file (nth 1 win-file-pos))) | 1195 | (dired-goto-file (nth 1 buf-file-pos))) |
| 1187 | (goto-char (nth 2 win-file-pos)) | 1196 | (goto-char (nth 2 buf-file-pos)) |
| 1188 | (dired-move-to-filename))))) | 1197 | (dired-move-to-filename)) |
| 1198 | (dolist (win-file-pos (nth 1 positions)) | ||
| 1199 | ;; Ensure that window still displays the original buffer. | ||
| 1200 | (when (eq (window-buffer (nth 0 win-file-pos)) buffer) | ||
| 1201 | (with-selected-window (nth 0 win-file-pos) | ||
| 1202 | (unless (and (nth 1 win-file-pos) | ||
| 1203 | (dired-goto-file (nth 1 win-file-pos))) | ||
| 1204 | (goto-char (nth 2 win-file-pos)) | ||
| 1205 | (dired-move-to-filename))))))) | ||
| 1189 | 1206 | ||
| 1190 | (defun dired-remember-marks (beg end) | 1207 | (defun dired-remember-marks (beg end) |
| 1191 | "Return alist of files and their marks, from BEG to END." | 1208 | "Return alist of files and their marks, from BEG to END." |