Mercurial > emacs
comparison lisp/saveplace.el @ 6700:db2292ce4894
(save-place-find-file-hook, save-place-kill-emacs-hook): New functions.
(hooks for find-file-hooks,kill-emacs-hook): Use those new functions.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 06 Apr 1994 05:04:40 +0000 |
parents | bc7bc2a395c6 |
children | 6347a8d838c8 |
comparison
equal
deleted
inserted
replaced
6699:59e74bc34228 | 6700:db2292ce4894 |
---|---|
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Karl Fogel <kfogel@cs.oberlin.edu> | 5 ;; Author: Karl Fogel <kfogel@cs.oberlin.edu> |
6 ;; Maintainer: FSF | 6 ;; Maintainer: FSF |
7 ;; Created: July, 1993 | 7 ;; Created: July, 1993 |
8 ;; Version: 1.1 | 8 ;; Version: 1.2 |
9 ;; Keywords: bookmarks, placeholders | 9 ;; Keywords: bookmarks, placeholders |
10 | 10 |
11 ;; This file is part of GNU Emacs. | 11 ;; This file is part of GNU Emacs. |
12 | 12 |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | 13 ;; GNU Emacs is free software; you can redistribute it and/or modify |
30 ;; value of buffer-local variable save-place to determine whether to | 30 ;; value of buffer-local variable save-place to determine whether to |
31 ;; save position or not. | 31 ;; save position or not. |
32 ;; | 32 ;; |
33 ;; Thanks to Stefan Schoef, who sent a patch with the | 33 ;; Thanks to Stefan Schoef, who sent a patch with the |
34 ;; `save-place-version-control' stuff in it. | 34 ;; `save-place-version-control' stuff in it. |
35 ;; | |
36 ;; Don't autoload this, rather, load it, since it modifies | |
37 ;; find-file-hooks and other hooks. | |
38 | 35 |
39 ;; this is what I was using during testing: | 36 ;; this is what I was using during testing: |
40 ;; (define-key ctl-x-map "p" 'toggle-save-place) | 37 ;; (define-key ctl-x-map "p" 'toggle-save-place) |
41 | 38 |
42 (defvar save-place-alist nil | 39 (defvar save-place-alist nil |
173 (set-buffer (car buf-list)) | 170 (set-buffer (car buf-list)) |
174 ;; save-place checks buffer-file-name too, but we can avoid | 171 ;; save-place checks buffer-file-name too, but we can avoid |
175 ;; overhead of function call by checking here too. | 172 ;; overhead of function call by checking here too. |
176 (and buffer-file-name (save-place-to-alist)) | 173 (and buffer-file-name (save-place-to-alist)) |
177 (setq buf-list (cdr buf-list)))))) | 174 (setq buf-list (cdr buf-list)))))) |
178 | |
179 (add-hook | |
180 'find-file-hooks | |
181 (function | |
182 (lambda () | |
183 (or save-place-loaded (load-save-place-alist-from-file)) | |
184 (let ((cell (assoc buffer-file-name save-place-alist))) | |
185 (if cell | |
186 (progn | |
187 (goto-char (cdr cell)) | |
188 ;; and make sure it will be saved again for later. | |
189 (setq save-place t)))))) | |
190 t) | |
191 | 175 |
192 (add-hook 'kill-emacs-hook | 176 (defun save-place-find-file-hook () |
193 (function | 177 (or save-place-loaded (load-save-place-alist-from-file)) |
194 (lambda () | 178 (let ((cell (assoc buffer-file-name save-place-alist))) |
195 (progn | 179 (if cell |
196 (save-places-to-alist) | 180 (progn |
197 (save-place-alist-to-file))))) | 181 (goto-char (cdr cell)) |
182 ;; and make sure it will be saved again for later | |
183 (setq save-place t))))) | |
184 | |
185 (defun save-place-kill-emacs-hook | |
186 (save-places-to-alist) | |
187 (save-place-alist-to-file)) | |
188 | |
189 (add-hook 'find-file-hooks 'save-place-find-file-hook t) | |
190 | |
191 (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook) | |
198 | 192 |
199 (add-hook 'kill-buffer-hook 'save-place-to-alist) | 193 (add-hook 'kill-buffer-hook 'save-place-to-alist) |
200 | 194 |
201 (provide 'saveplace) ; why not... | 195 (provide 'saveplace) ; why not... |
202 | 196 |
203 ;;; saveplace.el ends here | 197 ;;; saveplace.el ends here |
198 |