diff options
| author | Juri Linkov | 2013-12-20 22:20:39 +0200 |
|---|---|---|
| committer | Juri Linkov | 2013-12-20 22:20:39 +0200 |
| commit | 1d42e5b6396fd7234ff94e6fec7fd4f39d1faddb (patch) | |
| tree | 2824c1180224b4c3ff60e61a3a3585de197efdab | |
| parent | eea2cba48e1ad87992a896c75d6d2ed8afb24a30 (diff) | |
| download | emacs-1d42e5b6396fd7234ff94e6fec7fd4f39d1faddb.tar.gz emacs-1d42e5b6396fd7234ff94e6fec7fd4f39d1faddb.zip | |
* lisp/saveplace.el (save-place-to-alist): Add `dired-filename' as
a position when `dired-directory' is non-nil. Check integer
positions with `integerp'.
(toggle-save-place, save-places-to-alist): Add check for
`dired-directory'.
(save-place-find-file-hook): Check integer positions with
`integerp'.
(save-place-dired-hook): Use `dired-goto-file' when
`dired-filename' is found in the assoc list. Check integer
positions with `integerp'.
(dired-initial-position-hook): Rename from `dired-initial-point-hook'.
* lisp/dired.el (dired-initial-position-hook): Rename back from
`dired-initial-point-hook'.
(dired-initial-position): Rename `dired-initial-point-hook' to
`dired-initial-position-hook'.
(dired-file-name-at-point): Doc fix.
Fixes: debbugs:15329
| -rw-r--r-- | lisp/ChangeLog | 22 | ||||
| -rw-r--r-- | lisp/dired.el | 8 | ||||
| -rw-r--r-- | lisp/saveplace.el | 48 |
3 files changed, 61 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ca34fd6e482..17a3434cb19 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,25 @@ | |||
| 1 | 2013-12-20 Juri Linkov <juri@jurta.org> | 1 | 2013-12-20 Juri Linkov <juri@jurta.org> |
| 2 | 2 | ||
| 3 | * saveplace.el (save-place-to-alist): Add `dired-filename' as | ||
| 4 | a position when `dired-directory' is non-nil. Check integer | ||
| 5 | positions with `integerp'. | ||
| 6 | (toggle-save-place, save-places-to-alist): Add check for | ||
| 7 | `dired-directory'. | ||
| 8 | (save-place-find-file-hook): Check integer positions with | ||
| 9 | `integerp'. | ||
| 10 | (save-place-dired-hook): Use `dired-goto-file' when | ||
| 11 | `dired-filename' is found in the assoc list. Check integer | ||
| 12 | positions with `integerp'. | ||
| 13 | (dired-initial-position-hook): Rename from `dired-initial-point-hook'. | ||
| 14 | |||
| 15 | * dired.el (dired-initial-position-hook): Rename back from | ||
| 16 | `dired-initial-point-hook'. | ||
| 17 | (dired-initial-position): Rename `dired-initial-point-hook' to | ||
| 18 | `dired-initial-position-hook'. | ||
| 19 | (dired-file-name-at-point): Doc fix. (Bug#15329) | ||
| 20 | |||
| 21 | 2013-12-20 Juri Linkov <juri@jurta.org> | ||
| 22 | |||
| 3 | * replace.el (read-regexp-defaults-function): New defcustom (bug#14405). | 23 | * replace.el (read-regexp-defaults-function): New defcustom (bug#14405). |
| 4 | (read-regexp-suggestions): New function. | 24 | (read-regexp-suggestions): New function. |
| 5 | (read-regexp): Use `read-regexp-defaults-function' to get default values. | 25 | (read-regexp): Use `read-regexp-defaults-function' to get default values. |
| @@ -3814,7 +3834,7 @@ | |||
| 3814 | 3834 | ||
| 3815 | * subr.el (eval-after-load): Preserve evaluation order (bug#15389). | 3835 | * subr.el (eval-after-load): Preserve evaluation order (bug#15389). |
| 3816 | 3836 | ||
| 3817 | * abbrev.el (abbrev--check-chars): Fix thinko (bug#15329). | 3837 | * abbrev.el (abbrev--check-chars): Fix thinko (bug#15360). |
| 3818 | 3838 | ||
| 3819 | 2013-09-16 Stefan Monnier <monnier@iro.umontreal.ca> | 3839 | 2013-09-16 Stefan Monnier <monnier@iro.umontreal.ca> |
| 3820 | 3840 | ||
diff --git a/lisp/dired.el b/lisp/dired.el index 7e96bdfb87f..e971a70f20c 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -220,7 +220,7 @@ with the buffer narrowed to the listing." | |||
| 220 | ;; Note this can't simply be run inside function `dired-ls' as the hook | 220 | ;; Note this can't simply be run inside function `dired-ls' as the hook |
| 221 | ;; functions probably depend on the dired-subdir-alist to be OK. | 221 | ;; functions probably depend on the dired-subdir-alist to be OK. |
| 222 | 222 | ||
| 223 | (defcustom dired-initial-point-hook nil | 223 | (defcustom dired-initial-position-hook nil |
| 224 | "This hook is used to position the point. | 224 | "This hook is used to position the point. |
| 225 | It is run the function `dired-initial-position'." | 225 | It is run the function `dired-initial-position'." |
| 226 | :group 'dired | 226 | :group 'dired |
| @@ -733,7 +733,9 @@ Don't use that together with FILTER." | |||
| 733 | 733 | ||
| 734 | (defun dired-file-name-at-point () | 734 | (defun dired-file-name-at-point () |
| 735 | "Try to get a file name at point in the current dired buffer. | 735 | "Try to get a file name at point in the current dired buffer. |
| 736 | This hook is intended to be put in `file-name-at-point-functions'." | 736 | This hook is intended to be put in `file-name-at-point-functions'. |
| 737 | Note that it returns an abbreviated name that can't be used | ||
| 738 | as an argument to `dired-goto-file'." | ||
| 737 | (let ((filename (dired-get-filename nil t))) | 739 | (let ((filename (dired-get-filename nil t))) |
| 738 | (when filename | 740 | (when filename |
| 739 | (if (file-directory-p filename) | 741 | (if (file-directory-p filename) |
| @@ -2763,7 +2765,7 @@ It runs the hook `dired-initial-position-hook'." | |||
| 2763 | (and (featurep 'dired-x) dired-find-subdir | 2765 | (and (featurep 'dired-x) dired-find-subdir |
| 2764 | (dired-goto-subdir dirname)) | 2766 | (dired-goto-subdir dirname)) |
| 2765 | (if dired-trivial-filenames (dired-goto-next-nontrivial-file)) | 2767 | (if dired-trivial-filenames (dired-goto-next-nontrivial-file)) |
| 2766 | (run-hooks 'dired-initial-point-hook)) | 2768 | (run-hooks 'dired-initial-position-hook)) |
| 2767 | 2769 | ||
| 2768 | ;; These are hooks which make tree dired work. | 2770 | ;; These are hooks which make tree dired work. |
| 2769 | ;; They are in this file because other parts of dired need to call them. | 2771 | ;; 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 e070a7da489..8d8b58a4858 100644 --- a/lisp/saveplace.el +++ b/lisp/saveplace.el | |||
| @@ -152,8 +152,8 @@ file: | |||
| 152 | 152 | ||
| 153 | \(setq-default save-place t\)" | 153 | \(setq-default save-place t\)" |
| 154 | (interactive "P") | 154 | (interactive "P") |
| 155 | (if (not buffer-file-name) | 155 | (if (not (or buffer-file-name dired-directory)) |
| 156 | (message "Buffer `%s' not visiting a file" (buffer-name)) | 156 | (message "Buffer `%s' not visiting a file or directory" (buffer-name)) |
| 157 | (if (and save-place (or (not parg) (<= parg 0))) | 157 | (if (and save-place (or (not parg) (<= parg 0))) |
| 158 | (progn | 158 | (progn |
| 159 | (message "No place will be saved in this file") | 159 | (message "No place will be saved in this file") |
| @@ -161,6 +161,8 @@ file: | |||
| 161 | (message "Place will be saved") | 161 | (message "Place will be saved") |
| 162 | (setq save-place t)))) | 162 | (setq save-place t)))) |
| 163 | 163 | ||
| 164 | (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep)) | ||
| 165 | |||
| 164 | (defun save-place-to-alist () | 166 | (defun save-place-to-alist () |
| 165 | ;; put filename and point in a cons box and then cons that onto the | 167 | ;; put filename and point in a cons box and then cons that onto the |
| 166 | ;; front of the save-place-alist, if save-place is non-nil. | 168 | ;; front of the save-place-alist, if save-place is non-nil. |
| @@ -170,20 +172,29 @@ file: | |||
| 170 | ;; will be saved again when Emacs is killed. | 172 | ;; will be saved again when Emacs is killed. |
| 171 | (or save-place-loaded (load-save-place-alist-from-file)) | 173 | (or save-place-loaded (load-save-place-alist-from-file)) |
| 172 | (let ((item (or buffer-file-name | 174 | (let ((item (or buffer-file-name |
| 173 | (and dired-directory (expand-file-name dired-directory))))) | 175 | (and dired-directory |
| 176 | (if (consp dired-directory) | ||
| 177 | (expand-file-name (car dired-directory)) | ||
| 178 | (expand-file-name dired-directory)))))) | ||
| 174 | (when (and item | 179 | (when (and item |
| 175 | (or (not save-place-ignore-files-regexp) | 180 | (or (not save-place-ignore-files-regexp) |
| 176 | (not (string-match save-place-ignore-files-regexp | 181 | (not (string-match save-place-ignore-files-regexp |
| 177 | item)))) | 182 | item)))) |
| 178 | (let ((cell (assoc item save-place-alist)) | 183 | (let ((cell (assoc item save-place-alist)) |
| 179 | (position (if (not (eq major-mode 'hexl-mode)) | 184 | (position (cond ((eq major-mode 'hexl-mode) |
| 180 | (point) | 185 | (with-no-warnings |
| 181 | (with-no-warnings | 186 | (1+ (hexl-current-address)))) |
| 182 | (1+ (hexl-current-address)))))) | 187 | (dired-directory |
| 188 | (let ((filename (dired-get-filename nil t))) | ||
| 189 | (if filename | ||
| 190 | `((dired-filename . ,filename)) | ||
| 191 | (point)))) | ||
| 192 | (t (point))))) | ||
| 183 | (if cell | 193 | (if cell |
| 184 | (setq save-place-alist (delq cell save-place-alist))) | 194 | (setq save-place-alist (delq cell save-place-alist))) |
| 185 | (if (and save-place | 195 | (if (and save-place |
| 186 | (not (= position 1))) ;; Optimize out the degenerate case. | 196 | (not (and (integerp position) |
| 197 | (= position 1)))) ;; Optimize out the degenerate case. | ||
| 187 | (setq save-place-alist | 198 | (setq save-place-alist |
| 188 | (cons (cons item position) | 199 | (cons (cons item position) |
| 189 | save-place-alist))))))) | 200 | save-place-alist))))))) |
| @@ -290,7 +301,8 @@ may have changed\) back to `save-place-alist'." | |||
| 290 | (with-current-buffer (car buf-list) | 301 | (with-current-buffer (car buf-list) |
| 291 | ;; save-place checks buffer-file-name too, but we can avoid | 302 | ;; save-place checks buffer-file-name too, but we can avoid |
| 292 | ;; overhead of function call by checking here too. | 303 | ;; overhead of function call by checking here too. |
| 293 | (and buffer-file-name (save-place-to-alist)) | 304 | (and (or buffer-file-name dired-directory) |
| 305 | (save-place-to-alist)) | ||
| 294 | (setq buf-list (cdr buf-list)))))) | 306 | (setq buf-list (cdr buf-list)))))) |
| 295 | 307 | ||
| 296 | (defun save-place-find-file-hook () | 308 | (defun save-place-find-file-hook () |
| @@ -299,18 +311,27 @@ may have changed\) back to `save-place-alist'." | |||
| 299 | (if cell | 311 | (if cell |
| 300 | (progn | 312 | (progn |
| 301 | (or revert-buffer-in-progress-p | 313 | (or revert-buffer-in-progress-p |
| 302 | (goto-char (cdr cell))) | 314 | (and (integerp (cdr cell)) |
| 315 | (goto-char (cdr cell)))) | ||
| 303 | ;; and make sure it will be saved again for later | 316 | ;; and make sure it will be saved again for later |
| 304 | (setq save-place t))))) | 317 | (setq save-place t))))) |
| 305 | 318 | ||
| 319 | (declare-function dired-goto-file "dired" (file)) | ||
| 320 | |||
| 306 | (defun save-place-dired-hook () | 321 | (defun save-place-dired-hook () |
| 307 | "Position the point in a dired buffer." | 322 | "Position the point in a dired buffer." |
| 308 | (or save-place-loaded (load-save-place-alist-from-file)) | 323 | (or save-place-loaded (load-save-place-alist-from-file)) |
| 309 | (let ((cell (assoc (expand-file-name dired-directory) save-place-alist))) | 324 | (let ((cell (assoc (if (consp dired-directory) |
| 325 | (expand-file-name (car dired-directory)) | ||
| 326 | (expand-file-name dired-directory)) | ||
| 327 | save-place-alist))) | ||
| 310 | (if cell | 328 | (if cell |
| 311 | (progn | 329 | (progn |
| 312 | (or revert-buffer-in-progress-p | 330 | (or revert-buffer-in-progress-p |
| 313 | (goto-char (cdr cell))) | 331 | (if (integerp (cdr cell)) |
| 332 | (goto-char (cdr cell)) | ||
| 333 | (and (assq 'dired-filename (cdr cell)) | ||
| 334 | (dired-goto-file (cdr (assq 'dired-filename (cdr cell))))))) | ||
| 314 | ;; and make sure it will be saved again for later | 335 | ;; and make sure it will be saved again for later |
| 315 | (setq save-place t))))) | 336 | (setq save-place t))))) |
| 316 | 337 | ||
| @@ -324,7 +345,8 @@ may have changed\) back to `save-place-alist'." | |||
| 324 | 345 | ||
| 325 | (add-hook 'find-file-hook 'save-place-find-file-hook t) | 346 | (add-hook 'find-file-hook 'save-place-find-file-hook t) |
| 326 | 347 | ||
| 327 | (add-hook 'dired-initial-point-hook 'save-place-dired-hook) | 348 | (add-hook 'dired-initial-position-hook 'save-place-dired-hook) |
| 349 | |||
| 328 | (unless noninteractive | 350 | (unless noninteractive |
| 329 | (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook)) | 351 | (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook)) |
| 330 | 352 | ||