Mercurial > emacs
comparison lisp/bookmark.el @ 10994:d173d21f14e2
Removed C-v bindings; they were inconsistent.
Defvarred some variables to nil, solely to avoid compilation warnings.
Use "Author's Update Number:" instead of "Version:".
(bookmark-history): new var.
(bookmark-completing-read): use `bookmark-history'.
(bookmark-historicize-string): new macro.
Use this everywhere `bookmark-completing-read' is used, because
`completing-read' won't get a chance to add to `bookmark-history' if
we were invoked via a menu.
(bookmark-rename): use `bookmark-history' when reading the new name.
No need for the strange C-o binding anymore.
author | Karl Fogel <kfogel@red-bean.com> |
---|---|
date | Mon, 13 Mar 1995 22:50:35 +0000 |
parents | d6d3905ec550 |
children | 83b6c53268c3 |
comparison
equal
deleted
inserted
replaced
10993:e72bd65cab70 | 10994:d173d21f14e2 |
---|---|
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation | 3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation |
4 | 4 |
5 ;; Author: Karl Fogel <kfogel@cyclic.com> | 5 ;; Author: Karl Fogel <kfogel@cyclic.com> |
6 ;; Maintainer: Karl Fogel <kfogel@cyclic.com> | 6 ;; Maintainer: Karl Fogel <kfogel@cyclic.com> |
7 ;; Created: July, 1993 | 7 ;; Created: July, 1993 |
8 ;; Version: 2.6.6 | 8 ;; Author's Update Number: 2.6.8 |
9 ;; Keywords: bookmarks, placeholders, annotations | 9 ;; Keywords: bookmarks, placeholders, annotations |
10 | 10 |
11 ;;; Summary: | 11 ;;; Summary: |
12 ;; This package is for setting "bookmarks" in files. A bookmark | 12 ;; This package is for setting "bookmarks" in files. A bookmark |
13 ;; associates a string with a location in a certain file. Thus, you | 13 ;; associates a string with a location in a certain file. Thus, you |
62 ;; Buckets of gratitude to John Grabowski <johng@media.mit.edu> for | 62 ;; Buckets of gratitude to John Grabowski <johng@media.mit.edu> for |
63 ;; thinking up the annotations feature and implementing it so well. | 63 ;; thinking up the annotations feature and implementing it so well. |
64 | 64 |
65 ;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad | 65 ;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad |
66 ;; <olstad@msc.edu>. | 66 ;; <olstad@msc.edu>. |
67 | |
68 ;; LCD Archive Entry: | |
69 ;; bookmark|Karl Fogel|kfogel@cyclic.com| | |
70 ;; Setting bookmarks in files or directories, jumping to them later.| | |
71 ;; 06-March-1995|Version: 2.6.6|~/misc/bookmark.el.Z| | |
72 | 67 |
73 ;; Enough with the credits already, get on to the good stuff: | 68 ;; Enough with the credits already, get on to the good stuff: |
74 | 69 |
75 ;; FAVORITE CHINESE RESTAURANT: | 70 ;; FAVORITE CHINESE RESTAURANT: |
76 ;; Boy, that's a tough one. Probably Hong Min, or maybe Emperor's | 71 ;; Boy, that's a tough one. Probably Hong Min, or maybe Emperor's |
223 | 218 |
224 (defconst bookmark-old-default-file "~/.emacs-bkmrks" | 219 (defconst bookmark-old-default-file "~/.emacs-bkmrks" |
225 "*The .emacs.bmk file used to be called this.") | 220 "*The .emacs.bmk file used to be called this.") |
226 | 221 |
227 | 222 |
223 ;; defvarred to avoid a compilation warning: | |
224 (defvar bookmark-file nil | |
225 "Old name for `bookmark-default-file'.") | |
226 | |
228 (defvar bookmark-default-file | 227 (defvar bookmark-default-file |
229 (if (and (boundp 'bookmark-file) bookmark-file) | 228 (if bookmark-file |
230 ;; In case user set `bookmark-file' in her .emacs: | 229 ;; In case user set `bookmark-file' in her .emacs: |
231 bookmark-file | 230 bookmark-file |
232 (if (eq system-type 'ms-dos) | 231 (if (eq system-type 'ms-dos) |
233 "~/emacs.bmk" ; Cannot have initial dot [Yuck!] | 232 "~/emacs.bmk" ; Cannot have initial dot [Yuck!] |
234 "~/.emacs.bmk")) | 233 "~/.emacs.bmk")) |
382 (if cell | 381 (if cell |
383 (setcdr cell node) | 382 (setcdr cell node) |
384 (nconc (bookmark-get-bookmark-record bookmark) | 383 (nconc (bookmark-get-bookmark-record bookmark) |
385 (list (cons 'info-node node)))))) | 384 (list (cons 'info-node node)))))) |
386 | 385 |
386 | |
387 (defvar bookmark-history nil | |
388 "The history list for bookmark functions.") | |
389 | |
387 | 390 |
388 (defun bookmark-completing-read (prompt &optional default) | 391 (defun bookmark-completing-read (prompt &optional default) |
389 "Prompting with PROMPT, read a bookmark name in completion. | 392 "Prompting with PROMPT, read a bookmark name in completion. |
390 PROMPT will get a \": \" stuck on the end no matter what, so you | 393 PROMPT will get a \": \" stuck on the end no matter what, so you |
391 probably don't want to include one yourself. | 394 probably don't want to include one yourself. |
399 (concat prompt ": "))) | 402 (concat prompt ": "))) |
400 (str | 403 (str |
401 (completing-read prompt | 404 (completing-read prompt |
402 bookmark-alist | 405 bookmark-alist |
403 nil | 406 nil |
404 0))) | 407 0 |
408 nil | |
409 'bookmark-history))) | |
405 (if (string-equal "" str) | 410 (if (string-equal "" str) |
406 (list default) | 411 (list default) |
407 (list str)))) | 412 (list str)))) |
413 | |
414 | |
415 (defmacro bookmark-maybe-historicize-string (string) | |
416 "Put STRING into the bookmark prompt history, if caller non-interactive. | |
417 We need this because sometimes bookmark functions are invoked from | |
418 menus, so `completing-read' never gets a chance to set `bookmark-history'." | |
419 (` (or | |
420 (interactive-p) | |
421 (setq bookmark-history (cons (, string) bookmark-history))))) | |
408 | 422 |
409 | 423 |
410 (defun bookmark-make (str &optional annotation overwrite) | 424 (defun bookmark-make (str &optional annotation overwrite) |
411 "Make a bookmark named NAME. | 425 "Make a bookmark named NAME. |
412 Optional second arg ANNOTATION gives it an annotation. | 426 Optional second arg ANNOTATION gives it an annotation. |
640 | 654 |
641 To yank words from the text of the buffer and use them as part of the | 655 To yank words from the text of the buffer and use them as part of the |
642 bookmark name, type C-w while setting a bookmark. Successive C-w's | 656 bookmark name, type C-w while setting a bookmark. Successive C-w's |
643 yank successive words. | 657 yank successive words. |
644 | 658 |
645 Typing C-v inserts the name of the current file being visited. Typing | 659 Typing C-u inserts the name of the last bookmark used in the buffer |
646 C-u inserts the name of the last bookmark used in the buffer \(as an | 660 \(as an aid in using a single bookmark name to track your progress |
647 aid in using a single bookmark name to track your progress through a | 661 through a large file\). If no bookmark was used, then C-u inserts the |
648 large file\). If no bookmark was used, then C-u behaves like C-v and | 662 name of the file being visited. |
649 inserts the name of the file being visited. | |
650 | 663 |
651 Use \\[bookmark-delete] to remove bookmarks \(you give it a name, | 664 Use \\[bookmark-delete] to remove bookmarks \(you give it a name, |
652 and it removes only the first instance of a bookmark with that name from | 665 and it removes only the first instance of a bookmark with that name from |
653 the list of bookmarks.\)" | 666 the list of bookmarks.\)" |
654 (interactive "P") | 667 (interactive "P") |
669 (format "Set bookmark (%s): " default) | 682 (format "Set bookmark (%s): " default) |
670 nil | 683 nil |
671 (let ((now-map (copy-keymap minibuffer-local-map))) | 684 (let ((now-map (copy-keymap minibuffer-local-map))) |
672 (progn (define-key now-map "\C-w" | 685 (progn (define-key now-map "\C-w" |
673 'bookmark-yank-word) | 686 'bookmark-yank-word) |
674 (define-key now-map "\C-v" | |
675 'bookmark-insert-buffer-name) | |
676 (define-key now-map "\C-u" | 687 (define-key now-map "\C-u" |
677 'bookmark-insert-current-bookmark)) | 688 'bookmark-insert-current-bookmark)) |
678 now-map))) | 689 now-map))) |
679 (annotation nil)) | 690 (annotation nil)) |
680 (and (string-equal str "") (setq str default)) | 691 (and (string-equal str "") (setq str default)) |
697 Does not affect the kill-ring." | 708 Does not affect the kill-ring." |
698 (let ((eol (save-excursion (end-of-line) (point)))) | 709 (let ((eol (save-excursion (end-of-line) (point)))) |
699 (delete-region (point) eol) | 710 (delete-region (point) eol) |
700 (if (and newline-too (looking-at "\n")) | 711 (if (and newline-too (looking-at "\n")) |
701 (delete-char 1)))) | 712 (delete-char 1)))) |
713 | |
714 | |
715 ;; Defvars to avoid compilation warnings: | |
716 (defvar bookmark-annotation-paragraph nil) | |
717 (defvar bookmark-annotation-name nil) | |
718 (defvar bookmark-annotation-buffer nil) | |
719 (defvar bookmark-annotation-file nil) | |
720 (defvar bookmark-annotation-point nil) | |
702 | 721 |
703 | 722 |
704 (defun bookmark-send-annotation () | 723 (defun bookmark-send-annotation () |
705 "After remove lines beginning with '#', use the contents of this buffer | 724 "After remove lines beginning with '#', use the contents of this buffer |
706 as the annotation for a bookmark, and store it in the bookmark list with | 725 as the annotation for a bookmark, and store it in the bookmark list with |
954 if you wish to give the bookmark a new location, and bookmark-jump | 973 if you wish to give the bookmark a new location, and bookmark-jump |
955 will then jump to the new location, as well as recording it in place | 974 will then jump to the new location, as well as recording it in place |
956 of the old one in the permanent bookmark record." | 975 of the old one in the permanent bookmark record." |
957 (interactive | 976 (interactive |
958 (bookmark-completing-read "Jump to bookmark" bookmark-current-bookmark)) | 977 (bookmark-completing-read "Jump to bookmark" bookmark-current-bookmark)) |
978 (bookmark-maybe-historicize-string str) | |
959 (let ((cell (bookmark-jump-noselect str))) | 979 (let ((cell (bookmark-jump-noselect str))) |
960 (and cell | 980 (and cell |
961 (switch-to-buffer (car cell)) | 981 (switch-to-buffer (car cell)) |
962 (goto-char (cdr cell)) | 982 (goto-char (cdr cell)) |
963 ;; if there is an annotation for this bookmark, | 983 ;; if there is an annotation for this bookmark, |
1037 "Relocate BOOKMARK -- prompts for a filename, and makes an already | 1057 "Relocate BOOKMARK -- prompts for a filename, and makes an already |
1038 existing bookmark point to that file, instead of the one it used to | 1058 existing bookmark point to that file, instead of the one it used to |
1039 point at. Useful when a file has been renamed after a bookmark was | 1059 point at. Useful when a file has been renamed after a bookmark was |
1040 set in it." | 1060 set in it." |
1041 (interactive (bookmark-completing-read "Bookmark to relocate")) | 1061 (interactive (bookmark-completing-read "Bookmark to relocate")) |
1062 (bookmark-maybe-historicize-string str) | |
1042 (bookmark-maybe-load-default-file) | 1063 (bookmark-maybe-load-default-file) |
1043 (let* ((bmrk-filename (bookmark-get-filename str)) | 1064 (let* ((bmrk-filename (bookmark-get-filename str)) |
1044 (newloc (expand-file-name | 1065 (newloc (expand-file-name |
1045 (read-file-name | 1066 (read-file-name |
1046 (format "Relocate %s to: " str) | 1067 (format "Relocate %s to: " str) |
1047 (file-name-directory bmrk-filename))))) | 1068 (file-name-directory bmrk-filename))))) |
1048 (bookmark-set-filename str newloc))) | 1069 (bookmark-set-filename str newloc))) |
1049 | 1070 |
1050 | 1071 |
1051 ;;;###autoload | 1072 ;;;###autoload |
1052 (defun bookmark-insert-location (str) | 1073 (defun bookmark-insert-location (str &optional no-history) |
1053 "Insert the name of the file associated with BOOKMARK." | 1074 "Insert the name of the file associated with BOOKMARK. |
1075 Optional second arg NO-HISTORY means don't record this in the | |
1076 minibuffer history list `bookmark-history'." | |
1054 (interactive (bookmark-completing-read "Insert bookmark location")) | 1077 (interactive (bookmark-completing-read "Insert bookmark location")) |
1078 (or no-history (bookmark-maybe-historicize-string str)) | |
1055 (insert (bookmark-location str))) | 1079 (insert (bookmark-location str))) |
1056 | 1080 |
1057 | 1081 |
1058 (defun bookmark-location (str) | 1082 (defun bookmark-location (str) |
1059 "Return the name of the file associated with BOOKMARK." | 1083 "Return the name of the file associated with BOOKMARK." |
1071 passed as an argument. If called with two strings, then no prompting | 1095 passed as an argument. If called with two strings, then no prompting |
1072 is done. You must pass at least OLD-BOOKMARK when calling from Lisp. | 1096 is done. You must pass at least OLD-BOOKMARK when calling from Lisp. |
1073 | 1097 |
1074 While you are entering the new name, consecutive C-w's insert | 1098 While you are entering the new name, consecutive C-w's insert |
1075 consectutive words from the text of the buffer into the new bookmark | 1099 consectutive words from the text of the buffer into the new bookmark |
1076 name. | 1100 name." |
1077 C-v inserts the name of the file. | |
1078 C-o inserts the old name of the bookmark; this is helpful when you | |
1079 just want to make minor changes to the old name." | |
1080 (interactive (bookmark-completing-read "Old bookmark name")) | 1101 (interactive (bookmark-completing-read "Old bookmark name")) |
1102 (bookmark-maybe-historicize-string old) | |
1081 (bookmark-maybe-load-default-file) | 1103 (bookmark-maybe-load-default-file) |
1082 (progn | 1104 (progn |
1083 (setq bookmark-current-point (point)) | 1105 (setq bookmark-current-point (point)) |
1084 (setq bookmark-yank-point (point)) | 1106 (setq bookmark-yank-point (point)) |
1085 (setq bookmark-current-buffer (current-buffer)) | 1107 (setq bookmark-current-buffer (current-buffer)) |
1086 (let ((newname | 1108 (let ((newname |
1087 (or new ; use second arg, if non-nil | 1109 (or new ; use second arg, if non-nil |
1088 (read-from-minibuffer | 1110 (read-from-minibuffer |
1089 "New name: " | 1111 "New name: " |
1090 nil | 1112 nil |
1091 (let ((now-map (copy-keymap minibuffer-local-map))) | 1113 (let ((now-map (copy-keymap minibuffer-local-map))) |
1092 (progn (define-key now-map "\C-w" | 1114 (define-key now-map "\C-w" 'bookmark-yank-word) |
1093 'bookmark-yank-word) | 1115 now-map) |
1094 (define-key now-map "\C-o" | 1116 nil |
1095 (lambda () | 1117 'bookmark-history)))) |
1096 (interactive) | |
1097 (insert old))) | |
1098 (define-key now-map "\C-v" | |
1099 'bookmark-insert-buffer-name)) | |
1100 now-map))))) | |
1101 (progn | 1118 (progn |
1102 (bookmark-set-name old newname) | 1119 (bookmark-set-name old newname) |
1103 (setq bookmark-current-bookmark newname) | 1120 (setq bookmark-current-bookmark newname) |
1104 (bookmark-bmenu-surreptitiously-rebuild-list) | 1121 (bookmark-bmenu-surreptitiously-rebuild-list) |
1105 (setq bookmark-alist-modification-count | 1122 (setq bookmark-alist-modification-count |
1114 You may have a problem using this function if the value of variable | 1131 You may have a problem using this function if the value of variable |
1115 `bookmark-alist' is nil. If that happens, you need to load in some | 1132 `bookmark-alist' is nil. If that happens, you need to load in some |
1116 bookmarks. See help on function `bookmark-load' for more about | 1133 bookmarks. See help on function `bookmark-load' for more about |
1117 this." | 1134 this." |
1118 (interactive (bookmark-completing-read "Insert bookmark contents")) | 1135 (interactive (bookmark-completing-read "Insert bookmark contents")) |
1136 (bookmark-maybe-historicize-string str) | |
1119 (bookmark-maybe-load-default-file) | 1137 (bookmark-maybe-load-default-file) |
1120 (let ((orig-point (point)) | 1138 (let ((orig-point (point)) |
1121 (str-to-insert | 1139 (str-to-insert |
1122 (save-excursion | 1140 (save-excursion |
1123 (set-buffer (car (bookmark-jump-noselect str))) | 1141 (set-buffer (car (bookmark-jump-noselect str))) |
1136 one most recently used in this file, if any\). | 1154 one most recently used in this file, if any\). |
1137 Optional second arg BATCH means don't update the bookmark list buffer, | 1155 Optional second arg BATCH means don't update the bookmark list buffer, |
1138 probably because we were called from there." | 1156 probably because we were called from there." |
1139 (interactive | 1157 (interactive |
1140 (bookmark-completing-read "Delete bookmark" bookmark-current-bookmark)) | 1158 (bookmark-completing-read "Delete bookmark" bookmark-current-bookmark)) |
1159 (bookmark-maybe-historicize-string bookmark) | |
1141 (bookmark-maybe-load-default-file) | 1160 (bookmark-maybe-load-default-file) |
1142 (let ((will-go (bookmark-get-bookmark bookmark))) | 1161 (let ((will-go (bookmark-get-bookmark bookmark))) |
1143 (setq bookmark-alist (delq will-go bookmark-alist)) | 1162 (setq bookmark-alist (delq will-go bookmark-alist)) |
1144 ;; Added by db, nil bookmark-current-bookmark if the last | 1163 ;; Added by db, nil bookmark-current-bookmark if the last |
1145 ;; occurence has been deleted | 1164 ;; occurence has been deleted |
1489 (setq bookmark-bmenu-hidden-bookmarks | 1508 (setq bookmark-bmenu-hidden-bookmarks |
1490 (cons bmrk bookmark-bmenu-hidden-bookmarks)) | 1509 (cons bmrk bookmark-bmenu-hidden-bookmarks)) |
1491 (move-to-column bookmark-bmenu-file-column t) | 1510 (move-to-column bookmark-bmenu-file-column t) |
1492 (delete-region (point) (progn (end-of-line) (point))) | 1511 (delete-region (point) (progn (end-of-line) (point))) |
1493 (insert " ") | 1512 (insert " ") |
1494 (bookmark-insert-location bmrk) | 1513 ;; Pass the NO-HISTORY arg: |
1514 (bookmark-insert-location bmrk t) | |
1495 (forward-line 1)))))))) | 1515 (forward-line 1)))))))) |
1496 | 1516 |
1497 | 1517 |
1498 (defun bookmark-bmenu-hide-filenames (&optional force) | 1518 (defun bookmark-bmenu-hide-filenames (&optional force) |
1499 (if (and (not force) bookmark-bmenu-toggle-filenames) | 1519 (if (and (not force) bookmark-bmenu-toggle-filenames) |
1960 passed as an argument. If called with two strings, then no prompting | 1980 passed as an argument. If called with two strings, then no prompting |
1961 is done. You must pass at least OLD-BOOKMARK when calling from Lisp. | 1981 is done. You must pass at least OLD-BOOKMARK when calling from Lisp. |
1962 | 1982 |
1963 While you are entering the new name, consecutive C-w's insert | 1983 While you are entering the new name, consecutive C-w's insert |
1964 consectutive words from the text of the buffer into the new bookmark | 1984 consectutive words from the text of the buffer into the new bookmark |
1965 name, and C-v inserts the name of the file." | 1985 name." |
1966 (interactive "e") | 1986 (interactive "e") |
1967 (bookmark-popup-menu-and-apply-function | 1987 (bookmark-popup-menu-and-apply-function |
1968 'bookmark-rename "Rename Bookmark" event)) | 1988 'bookmark-rename "Rename Bookmark" event)) |
1969 | 1989 |
1970 | 1990 |