diff options
author | Ivan Kanis <ivan@kanis.fr> | 2013-06-14 11:32:01 +0200 |
---|---|---|
committer | Ivan Kanis <ivan@kanis.fr> | 2013-06-14 11:32:01 +0200 |
commit | d4466a91f271db0b414a605ede1a7befd403b950 (patch) | |
tree | f1ef781262cdb850bf1ffda8a3b4a88a200ea6e0 /lisp/saveplace.el | |
parent | 7cb18056e648c086bd9710b12d17f4a2cfba9a29 (diff) | |
download | emacs-d4466a91f271db0b414a605ede1a7befd403b950.tar.gz |
Add support for dired in saveplace.
Diffstat (limited to 'lisp/saveplace.el')
-rw-r--r-- | lisp/saveplace.el | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/lisp/saveplace.el b/lisp/saveplace.el index 1b7efcec1b9..2ddac6d6c43 100644 --- a/lisp/saveplace.el +++ b/lisp/saveplace.el @@ -169,22 +169,24 @@ 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 + (and dired-directory (expand-file-name dired-directory))))) + (when (and item + (or (not save-place-ignore-files-regexp) + (not (string-match save-place-ignore-files-regexp + item)))) + (let ((cell (assoc item 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 item position) + save-place-alist))))))) (defun save-place-forget-unreadable-files () "Remove unreadable files from `save-place-alist'. @@ -300,6 +302,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-dired-hook () + "Position the point 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) @@ -310,6 +323,7 @@ may have changed\) back to `save-place-alist'." (add-hook 'find-file-hook 'save-place-find-file-hook t) +(add-hook 'dired-initial-point-hook 'save-place-dired-hook) (unless noninteractive (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook)) |