aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMartin Rudalics2018-12-08 09:18:28 +0100
committerMartin Rudalics2018-12-08 09:18:28 +0100
commit1d676aabca4bdba6948fb7a9d875ba63b51aed63 (patch)
treeee3ace39b0ddb7a57c561ce8f5d8219696083f22 /lisp
parent1fc73de597ba395b3575c70dae68b6c3e5b5a3b7 (diff)
downloademacs-1d676aabca4bdba6948fb7a9d875ba63b51aed63.tar.gz
emacs-1d676aabca4bdba6948fb7a9d875ba63b51aed63.zip
Adjust windows' previous buffers when reverting dired buffers (Bug#33458)
* lisp/dired.el (dired-save-positions, dired-restore-positions): For each window that showed the reverted buffer before, fix the point positions in its list of previously shown buffers the way these routines handle window point for all windows currently showing the buffer (Bug#33458).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dired.el44
1 files changed, 41 insertions, 3 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index cbd85fed91c..e5dc8623a49 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1478,12 +1478,36 @@ change; the point does."
1478 (list w 1478 (list w
1479 (dired-get-filename nil t) 1479 (dired-get-filename nil t)
1480 (line-number-at-pos (window-point w))))) 1480 (line-number-at-pos (window-point w)))))
1481 (get-buffer-window-list nil 0 t)))) 1481 (get-buffer-window-list nil 0 t))
1482 ;; For each window that showed the current buffer before, scan its
1483 ;; list of previous buffers. For each association thus found save
1484 ;; a triple <point, name, line> where 'point' is that window's
1485 ;; window-point marker stored in the window's list of previous
1486 ;; buffers, 'name' is the filename at the position of 'point' and
1487 ;; 'line' is the line number at the position of 'point'.
1488 (let ((buffer (current-buffer))
1489 prevs)
1490 (walk-windows
1491 (lambda (window)
1492 (let ((prev (assq buffer (window-prev-buffers window))))
1493 (when prev
1494 (with-current-buffer buffer
1495 (save-excursion
1496 (goto-char (nth 2 prev))
1497 (setq prevs
1498 (cons
1499 (list (nth 2 prev)
1500 (dired-get-filename nil t)
1501 (line-number-at-pos (point)))
1502 prevs)))))))
1503 'nomini t)
1504 prevs)))
1482 1505
1483(defun dired-restore-positions (positions) 1506(defun dired-restore-positions (positions)
1484 "Restore POSITIONS saved with `dired-save-positions'." 1507 "Restore POSITIONS saved with `dired-save-positions'."
1485 (let* ((buf-file-pos (nth 0 positions)) 1508 (let* ((buf-file-pos (nth 0 positions))
1486 (buffer (nth 0 buf-file-pos))) 1509 (buffer (nth 0 buf-file-pos))
1510 (prevs (nth 2 positions)))
1487 (unless (and (nth 1 buf-file-pos) 1511 (unless (and (nth 1 buf-file-pos)
1488 (dired-goto-file (nth 1 buf-file-pos))) 1512 (dired-goto-file (nth 1 buf-file-pos)))
1489 (goto-char (point-min)) 1513 (goto-char (point-min))
@@ -1497,7 +1521,21 @@ change; the point does."
1497 (dired-goto-file (nth 1 win-file-pos))) 1521 (dired-goto-file (nth 1 win-file-pos)))
1498 (goto-char (point-min)) 1522 (goto-char (point-min))
1499 (forward-line (1- (nth 2 win-file-pos))) 1523 (forward-line (1- (nth 2 win-file-pos)))
1500 (dired-move-to-filename))))))) 1524 (dired-move-to-filename)))))
1525 (when prevs
1526 (with-current-buffer buffer
1527 (save-excursion
1528 (dolist (prev prevs)
1529 (let ((point (nth 0 prev)))
1530 ;; Sanity check of the point marker.
1531 (when (and (markerp point)
1532 (eq (marker-buffer point) buffer))
1533 (unless (and (nth 0 prev)
1534 (dired-goto-file (nth 1 prev)))
1535 (goto-char (point-min))
1536 (forward-line (1- (nth 2 prev))))
1537 (dired-move-to-filename)
1538 (move-marker point (point) buffer)))))))))
1501 1539
1502(defun dired-remember-marks (beg end) 1540(defun dired-remember-marks (beg end)
1503 "Return alist of files and their marks, from BEG to END." 1541 "Return alist of files and their marks, from BEG to END."