Function: dired-save-positions

dired-save-positions is a byte-compiled function defined in dired.el.gz.

Signature

(dired-save-positions)

Documentation

Return current positions in the buffer and all windows with this directory.

The positions have the form (BUFFER-POSITION WINDOW-POSITIONS).

BUFFER-POSITION is the point position in the current Dired buffer. It has the form (BUFFER DIRED-FILENAME BUFFER-LINE-NUMBER).

WINDOW-POSITIONS are current positions in all windows displaying this dired buffer. The window positions have the form (WINDOW DIRED-FILENAME WINDOW-LINE-NUMBER).

We store line numbers instead of point positions because the header lines might change as well: when this happen the line number doesn't change; the point does.

Source Code

;; Defined in /usr/src/emacs/lisp/dired.el.gz
;; Subroutines of dired-revert
;; Some of these are also used when inserting subdirs.

(defun dired-save-positions ()
  "Return current positions in the buffer and all windows with this directory.
The positions have the form (BUFFER-POSITION WINDOW-POSITIONS).

BUFFER-POSITION is the point position in the current Dired buffer.
It has the form (BUFFER DIRED-FILENAME BUFFER-LINE-NUMBER).

WINDOW-POSITIONS are current positions in all windows displaying
this dired buffer.  The window positions have the form (WINDOW
DIRED-FILENAME WINDOW-LINE-NUMBER).

We store line numbers instead of point positions because the header
lines might change as well: when this happen the line number doesn't
change; the point does."
  (list
   (list (current-buffer) (dired-get-filename nil t) (line-number-at-pos))
   (mapcar (lambda (w)
	     (with-selected-window w
               (list w
		     (dired-get-filename nil t)
                     (line-number-at-pos (window-point w)))))
	   (get-buffer-window-list nil 0 t))
   ;; For each window that showed the current buffer before, scan its
   ;; list of previous buffers.  For each association thus found save
   ;; a triple <point, name, line> where 'point' is that window's
   ;; window-point marker stored in the window's list of previous
   ;; buffers, 'name' is the filename at the position of 'point' and
   ;; 'line' is the line number at the position of 'point'.
   (let ((buffer (current-buffer))
         prevs)
     (walk-windows
      (lambda (window)
        (let ((prev (assq buffer (window-prev-buffers window))))
          (when prev
            (with-current-buffer buffer
              (save-excursion
                (goto-char (nth 2 prev))
                (setq prevs
                      (cons
                       (list (nth 2 prev)
                             (dired-get-filename nil t)
                             (line-number-at-pos (point)))
                       prevs)))))))
      'nomini t)
     prevs)))