diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bec5a55..1cdec70 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-06-99 Ivan Kanis + Add support for dired in saveplace. + * dired.el (dired-initial-position): Call cursor motion in + saveplace. + * saveplace.el (save-place-to-alist): Add dired position + (save-place-position-dired-cursor): New function + 2013-06-05 Leo Liu Re-implement smie matching block highlight using diff --git a/lisp/dired.el b/lisp/dired.el index 5b6a787..84f2be7 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2755,6 +2755,9 @@ as returned by `dired-get-filename'. LIMIT is the search limit." (defvar dired-find-subdir) +;; saveplace support +(eval-when-compile (require 'saveplace)) + ;; FIXME document whatever dired-x is doing. (defun dired-initial-position (dirname) "Where point should go in a new listing of DIRNAME. @@ -2762,7 +2765,8 @@ Point assumed at beginning of new subdir line." (end-of-line) (and (featurep 'dired-x) dired-find-subdir (dired-goto-subdir dirname)) - (if dired-trivial-filenames (dired-goto-next-nontrivial-file))) + (if dired-trivial-filenames (dired-goto-next-nontrivial-file)) + (if (featurep 'saveplace) (save-place-position-dired-cursor))) ;; These are hooks which make tree dired work. ;; They are in this file because other parts of dired need to call them. diff --git a/lisp/saveplace.el b/lisp/saveplace.el index 1b7efce..d4af2bc 100644 --- a/lisp/saveplace.el +++ b/lisp/saveplace.el @@ -169,22 +169,25 @@ file: ;; file. If not, do so, then feel free to modify the alist. It ;; will be saved again when Emacs is killed. (or save-place-loaded (load-save-place-alist-from-file)) - (when (and buffer-file-name - (or (not save-place-ignore-files-regexp) - (not (string-match save-place-ignore-files-regexp - buffer-file-name)))) - (let ((cell (assoc buffer-file-name save-place-alist)) - (position (if (not (eq major-mode 'hexl-mode)) - (point) - (with-no-warnings - (1+ (hexl-current-address)))))) - (if cell - (setq save-place-alist (delq cell save-place-alist))) - (if (and save-place - (not (= position 1))) ;; Optimize out the degenerate case. - (setq save-place-alist - (cons (cons buffer-file-name position) - save-place-alist)))))) + (let ((item (or buffer-file-name + (when dired-directory (expand-file-name dired-directory)))) + cell position) + (when (and item + (or (not save-place-ignore-files-regexp) + (not (string-match save-place-ignore-files-regexp + item)))) + (setq cell (assoc item save-place-alist) + position (if (not (eq major-mode 'hexl-mode)) + (point) + (with-no-warnings + (1+ (hexl-current-address))))) + (when cell + (setq save-place-alist (delq cell save-place-alist))) + (when (and save-place + (not (= position 1))) ;; Optimize out the degenerate case. + (setq save-place-alist + (cons (cons item position) + save-place-alist)))))) (defun save-place-forget-unreadable-files () "Remove unreadable files from `save-place-alist'. @@ -300,6 +303,17 @@ may have changed\) back to `save-place-alist'." ;; and make sure it will be saved again for later (setq save-place t))))) +(defun save-place-position-dired-cursor () + "Position the cursor in a dired buffer." + (or save-place-loaded (load-save-place-alist-from-file)) + (let ((cell (assoc (expand-file-name dired-directory) save-place-alist))) + (if cell + (progn + (or revert-buffer-in-progress-p + (goto-char (cdr cell))) + ;; and make sure it will be saved again for later + (setq save-place t))))) + (defun save-place-kill-emacs-hook () ;; First update the alist. This loads the old save-place-file if nec. (save-places-to-alist)