aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Kanis2013-06-14 11:32:01 +0200
committerIvan Kanis2013-06-14 11:32:01 +0200
commitd4466a91f271db0b414a605ede1a7befd403b950 (patch)
treef1ef781262cdb850bf1ffda8a3b4a88a200ea6e0
parent7cb18056e648c086bd9710b12d17f4a2cfba9a29 (diff)
downloademacs-d4466a91f271db0b414a605ede1a7befd403b950.tar.gz
emacs-d4466a91f271db0b414a605ede1a7befd403b950.zip
Add support for dired in saveplace.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/dired.el13
-rw-r--r--lisp/saveplace.el46
3 files changed, 49 insertions, 18 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 38b4d7b7854..e7b797b0f8d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12013-06-99 Ivan Kanis <ivan@kanis.fr>
2
3 Add support for dired in saveplace.
4 * dired.el (dired-initial-position-hook): New variable.
5 (dired-initial-position): Call hook to place cursor position.
6 * saveplace.el (save-place-to-alist): Add dired position.
7 (save-place-dired-hook): New function.
8
12013-06-14 Stefan Monnier <monnier@iro.umontreal.ca> 92013-06-14 Stefan Monnier <monnier@iro.umontreal.ca>
2 10
3 * subr.el (eval-after-load, set-temporary-overlay-map): Use indirection 11 * subr.el (eval-after-load, set-temporary-overlay-map): Use indirection
diff --git a/lisp/dired.el b/lisp/dired.el
index 5b6a78759db..0f2b0973986 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -217,6 +217,13 @@ with the buffer narrowed to the listing."
217;; Note this can't simply be run inside function `dired-ls' as the hook 217;; Note this can't simply be run inside function `dired-ls' as the hook
218;; functions probably depend on the dired-subdir-alist to be OK. 218;; functions probably depend on the dired-subdir-alist to be OK.
219 219
220(defcustom dired-initial-point-hook nil
221 "This hook is used to position the point.
222It is run the function `dired-initial-position'."
223 :group 'dired
224 :type 'hook
225 :version "24.4")
226
220(defcustom dired-dnd-protocol-alist 227(defcustom dired-dnd-protocol-alist
221 '(("^file:///" . dired-dnd-handle-local-file) 228 '(("^file:///" . dired-dnd-handle-local-file)
222 ("^file://" . dired-dnd-handle-file) 229 ("^file://" . dired-dnd-handle-file)
@@ -2758,11 +2765,13 @@ as returned by `dired-get-filename'. LIMIT is the search limit."
2758;; FIXME document whatever dired-x is doing. 2765;; FIXME document whatever dired-x is doing.
2759(defun dired-initial-position (dirname) 2766(defun dired-initial-position (dirname)
2760 "Where point should go in a new listing of DIRNAME. 2767 "Where point should go in a new listing of DIRNAME.
2761Point assumed at beginning of new subdir line." 2768Point assumed at beginning of new subdir line.
2769It runs the hook `dired-initial-position-hook'."
2762 (end-of-line) 2770 (end-of-line)
2763 (and (featurep 'dired-x) dired-find-subdir 2771 (and (featurep 'dired-x) dired-find-subdir
2764 (dired-goto-subdir dirname)) 2772 (dired-goto-subdir dirname))
2765 (if dired-trivial-filenames (dired-goto-next-nontrivial-file))) 2773 (if dired-trivial-filenames (dired-goto-next-nontrivial-file))
2774 (run-hooks 'dired-initial-point-hook))
2766 2775
2767;; These are hooks which make tree dired work. 2776;; These are hooks which make tree dired work.
2768;; They are in this file because other parts of dired need to call them. 2777;; 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 1b7efcec1b9..2ddac6d6c43 100644
--- a/lisp/saveplace.el
+++ b/lisp/saveplace.el
@@ -169,22 +169,24 @@ file:
169 ;; file. If not, do so, then feel free to modify the alist. It 169 ;; file. If not, do so, then feel free to modify the alist. It
170 ;; will be saved again when Emacs is killed. 170 ;; will be saved again when Emacs is killed.
171 (or save-place-loaded (load-save-place-alist-from-file)) 171 (or save-place-loaded (load-save-place-alist-from-file))
172 (when (and buffer-file-name 172 (let ((item (or buffer-file-name
173 (or (not save-place-ignore-files-regexp) 173 (and dired-directory (expand-file-name dired-directory)))))
174 (not (string-match save-place-ignore-files-regexp 174 (when (and item
175 buffer-file-name)))) 175 (or (not save-place-ignore-files-regexp)
176 (let ((cell (assoc buffer-file-name save-place-alist)) 176 (not (string-match save-place-ignore-files-regexp
177 (position (if (not (eq major-mode 'hexl-mode)) 177 item))))
178 (point) 178 (let ((cell (assoc item save-place-alist))
179 (with-no-warnings 179 (position (if (not (eq major-mode 'hexl-mode))
180 (1+ (hexl-current-address)))))) 180 (point)
181 (if cell 181 (with-no-warnings
182 (setq save-place-alist (delq cell save-place-alist))) 182 (1+ (hexl-current-address))))))
183 (if (and save-place 183 (if cell
184 (not (= position 1))) ;; Optimize out the degenerate case. 184 (setq save-place-alist (delq cell save-place-alist)))
185 (setq save-place-alist 185 (if (and save-place
186 (cons (cons buffer-file-name position) 186 (not (= position 1))) ;; Optimize out the degenerate case.
187 save-place-alist)))))) 187 (setq save-place-alist
188 (cons (cons item position)
189 save-place-alist)))))))
188 190
189(defun save-place-forget-unreadable-files () 191(defun save-place-forget-unreadable-files ()
190 "Remove unreadable files from `save-place-alist'. 192 "Remove unreadable files from `save-place-alist'.
@@ -300,6 +302,17 @@ may have changed\) back to `save-place-alist'."
300 ;; and make sure it will be saved again for later 302 ;; and make sure it will be saved again for later
301 (setq save-place t))))) 303 (setq save-place t)))))
302 304
305(defun save-place-dired-hook ()
306 "Position the point in a dired buffer."
307 (or save-place-loaded (load-save-place-alist-from-file))
308 (let ((cell (assoc (expand-file-name dired-directory) save-place-alist)))
309 (if cell
310 (progn
311 (or revert-buffer-in-progress-p
312 (goto-char (cdr cell)))
313 ;; and make sure it will be saved again for later
314 (setq save-place t)))))
315
303(defun save-place-kill-emacs-hook () 316(defun save-place-kill-emacs-hook ()
304 ;; First update the alist. This loads the old save-place-file if nec. 317 ;; First update the alist. This loads the old save-place-file if nec.
305 (save-places-to-alist) 318 (save-places-to-alist)
@@ -310,6 +323,7 @@ may have changed\) back to `save-place-alist'."
310 323
311(add-hook 'find-file-hook 'save-place-find-file-hook t) 324(add-hook 'find-file-hook 'save-place-find-file-hook t)
312 325
326(add-hook 'dired-initial-point-hook 'save-place-dired-hook)
313(unless noninteractive 327(unless noninteractive
314 (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook)) 328 (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook))
315 329