summaryrefslogtreecommitdiff
path: root/lisp/saveplace.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/saveplace.el')
-rw-r--r--lisp/saveplace.el31
1 files changed, 24 insertions, 7 deletions
diff --git a/lisp/saveplace.el b/lisp/saveplace.el
index c088facb3c3..3830e4b16cf 100644
--- a/lisp/saveplace.el
+++ b/lisp/saveplace.el
@@ -290,7 +290,11 @@ may have changed) back to `save-place-alist'."
;; adding hooks to it.
(with-current-buffer (get-buffer-create " *Saved Places*")
(delete-region (point-min) (point-max))
- (insert-file-contents file)
+ ;; Make sure our 'coding:' cookie in the save-place
+ ;; file will take effect, in case the caller binds
+ ;; coding-system-for-read.
+ (let (coding-system-for-read)
+ (insert-file-contents file))
(goto-char (point-min))
(setq save-place-alist
(with-demoted-errors "Error reading save-place-file: %S"
@@ -328,14 +332,26 @@ may have changed) back to `save-place-alist'."
(with-current-buffer (car buf-list)
;; save-place checks buffer-file-name too, but we can avoid
;; overhead of function call by checking here too.
- (and (or buffer-file-name (and (derived-mode-p 'dired-mode)
- (boundp 'dired-subdir-alist)
- dired-subdir-alist
- (dired-current-directory)))
- (save-place-to-alist))
+ (when (and (or buffer-file-name
+ (and (derived-mode-p 'dired-mode)
+ (boundp 'dired-subdir-alist)
+ dired-subdir-alist
+ (dired-current-directory)))
+ ;; Don't save place in literally-visited file
+ ;; because this will commonly differ from the place
+ ;; when visiting literally (and
+ ;; `find-file-literally' always places point at the
+ ;; start of the buffer).
+ (not find-file-literally))
+ (save-place-to-alist))
(setq buf-list (cdr buf-list))))))
+(defvar save-place-after-find-file-hook nil
+ "Hook run at the end of `save-place-find-file-hook'.")
+
(defun save-place-find-file-hook ()
+ "Function added to `find-file-hook' by `save-place-mode'.
+It runs the hook `save-place-after-find-file-hook'."
(or save-place-loaded (load-save-place-alist-from-file))
(let ((cell (assoc buffer-file-name save-place-alist)))
(if cell
@@ -344,7 +360,8 @@ may have changed) back to `save-place-alist'."
(and (integerp (cdr cell))
(goto-char (cdr cell))))
;; and make sure it will be saved again for later
- (setq save-place-mode t)))))
+ (setq save-place-mode t))))
+ (run-hooks 'save-place-after-find-file-hook))
(declare-function dired-goto-file "dired" (file))