diff options
| author | Stefan Monnier | 2008-03-09 21:16:26 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-03-09 21:16:26 +0000 |
| commit | a7e83b26f856eeec1f7fbd6bf4c2374cf3db8c1a (patch) | |
| tree | 2e7987dc6fceac2d8c25f1468612c8585eba13af | |
| parent | fc22668d50f2c2d153fea1ec56cdb4f66a17370c (diff) | |
| download | emacs-a7e83b26f856eeec1f7fbd6bf4c2374cf3db8c1a.tar.gz emacs-a7e83b26f856eeec1f7fbd6bf4c2374cf3db8c1a.zip | |
(bookmark-set): Make the bookmark before reading annotations.
I.e. use bookmark-edit-annotation rather than bookmark-read-annotation.
(bookmark-read-annotation-mode-map, bookmark-annotation-paragraph)
(bookmark-annotation-buffer, bookmark-annotation-file)
(bookmark-annotation-point, bookmark-send-annotation)
(bookmark-read-annotation-mode, bookmark-read-annotation): Remove.
(bookmark-edit-annotation-text-func): Rename from
bookmark-read-annotation-text-func. Keep old name as an obsolete alias.
(bookmark-edit-annotation-mode-map): Move initialization into declaration.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/bookmark.el | 113 |
2 files changed, 29 insertions, 94 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index aa81a3d0780..be3980298ca 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,15 @@ | |||
| 1 | 2008-03-09 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2008-03-09 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * bookmark.el (bookmark-set): Make the bookmark before reading annotations. | ||
| 4 | I.e. use bookmark-edit-annotation rather than bookmark-read-annotation. | ||
| 5 | (bookmark-read-annotation-mode-map, bookmark-annotation-paragraph) | ||
| 6 | (bookmark-annotation-buffer, bookmark-annotation-file) | ||
| 7 | (bookmark-annotation-point, bookmark-send-annotation) | ||
| 8 | (bookmark-read-annotation-mode, bookmark-read-annotation): Remove. | ||
| 9 | (bookmark-edit-annotation-text-func): Rename from | ||
| 10 | bookmark-read-annotation-text-func. Keep old name as an obsolete alias. | ||
| 11 | (bookmark-edit-annotation-mode-map): Move initialization into declaration. | ||
| 12 | |||
| 3 | * bookmark.el: Add spurious * in docstrings. | 13 | * bookmark.el: Add spurious * in docstrings. |
| 4 | (bookmark-minibuffer-read-name-map): New var. | 14 | (bookmark-minibuffer-read-name-map): New var. |
| 5 | (bookmark-set): Use it. Also pass the default value as it should. | 15 | (bookmark-set): Use it. Also pass the default value as it should. |
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index ada3f034580..aaeed359d9d 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -249,14 +249,6 @@ functions have a binding in this keymap.") | |||
| 249 | 249 | ||
| 250 | ;;;###autoload (fset 'bookmark-map bookmark-map) | 250 | ;;;###autoload (fset 'bookmark-map bookmark-map) |
| 251 | 251 | ||
| 252 | ;;; The annotation maps. | ||
| 253 | (defvar bookmark-read-annotation-mode-map | ||
| 254 | (let ((map (make-sparse-keymap))) | ||
| 255 | (set-keymap-parent map text-mode-map) | ||
| 256 | (define-key map "\C-c\C-c" 'bookmark-send-annotation) | ||
| 257 | map) | ||
| 258 | "Keymap for composing an annotation for a bookmark.") | ||
| 259 | |||
| 260 | 252 | ||
| 261 | ;;; Core variables and data structures: | 253 | ;;; Core variables and data structures: |
| 262 | (defvar bookmark-alist () | 254 | (defvar bookmark-alist () |
| @@ -749,15 +741,15 @@ the list of bookmarks.\)" | |||
| 749 | (format "Set bookmark (%s): " default) | 741 | (format "Set bookmark (%s): " default) |
| 750 | nil | 742 | nil |
| 751 | bookmark-minibuffer-read-name-map | 743 | bookmark-minibuffer-read-name-map |
| 752 | nil nil default))) | 744 | nil nil default)))) |
| 753 | (annotation nil)) | ||
| 754 | (and (string-equal str "") (setq str default)) | 745 | (and (string-equal str "") (setq str default)) |
| 746 | ;; Make the bookmark. | ||
| 747 | (bookmark-make str nil parg) | ||
| 748 | (setq bookmark-current-bookmark str) | ||
| 749 | (bookmark-bmenu-surreptitiously-rebuild-list) | ||
| 755 | ;; Ask for an annotation buffer for this bookmark | 750 | ;; Ask for an annotation buffer for this bookmark |
| 756 | (if bookmark-use-annotations | 751 | (if bookmark-use-annotations |
| 757 | (bookmark-read-annotation parg str) | 752 | (bookmark-edit-annotation str) |
| 758 | (bookmark-make str annotation parg) | ||
| 759 | (setq bookmark-current-bookmark str) | ||
| 760 | (bookmark-bmenu-surreptitiously-rebuild-list) | ||
| 761 | (goto-char bookmark-current-point)))) | 753 | (goto-char bookmark-current-point)))) |
| 762 | 754 | ||
| 763 | 755 | ||
| @@ -772,45 +764,10 @@ Does not affect the kill ring." | |||
| 772 | 764 | ||
| 773 | 765 | ||
| 774 | ;; Defvars to avoid compilation warnings: | 766 | ;; Defvars to avoid compilation warnings: |
| 775 | (defvar bookmark-annotation-paragraph nil) | 767 | (defvar bookmark-annotation-name nil |
| 776 | (defvar bookmark-annotation-name nil) | 768 | "Variable holding the name of the bookmark. |
| 777 | (defvar bookmark-annotation-buffer nil) | 769 | This is used in `bookmark-edit-annotation' to record the bookmark |
| 778 | (defvar bookmark-annotation-file nil) | 770 | whose annotation is being edited.") |
| 779 | (defvar bookmark-annotation-point nil) | ||
| 780 | |||
| 781 | |||
| 782 | (defun bookmark-send-annotation () | ||
| 783 | "Use buffer contents as the annotation for a bookmark. | ||
| 784 | Exclude lines that begin with `#'. | ||
| 785 | Store the annotation text in the bookmark list with | ||
| 786 | the bookmark (and file, and point) specified in buffer local variables." | ||
| 787 | (interactive) | ||
| 788 | (if (not (eq major-mode 'bookmark-read-annotation-mode)) | ||
| 789 | (error "Not in bookmark-read-annotation-mode")) | ||
| 790 | (goto-char (point-min)) | ||
| 791 | (while (< (point) (point-max)) | ||
| 792 | (if (looking-at "^#") | ||
| 793 | (bookmark-kill-line t) | ||
| 794 | (forward-line 1))) | ||
| 795 | (let ((annotation (buffer-string)) | ||
| 796 | (parg bookmark-annotation-paragraph) | ||
| 797 | (bookmark bookmark-annotation-name) | ||
| 798 | (pt bookmark-annotation-point) | ||
| 799 | (buf bookmark-annotation-buffer)) | ||
| 800 | ;; for bookmark-make-record-function to work, we need to be | ||
| 801 | ;; in the relevant buffer, at the relevant point. | ||
| 802 | ;; Actually, the bookmark-make-record-function spec should | ||
| 803 | ;; probably be changed to avoid this need. Should I handle the | ||
| 804 | ;; error if a buffer is killed between "C-x r m" and a "C-c C-c" | ||
| 805 | ;; in the annotation buffer? | ||
| 806 | (save-excursion | ||
| 807 | (pop-to-buffer buf) | ||
| 808 | (goto-char pt) | ||
| 809 | (bookmark-make bookmark annotation parg) | ||
| 810 | (setq bookmark-current-bookmark bookmark)) | ||
| 811 | (bookmark-bmenu-surreptitiously-rebuild-list) | ||
| 812 | (goto-char bookmark-current-point)) | ||
| 813 | (kill-buffer (current-buffer))) | ||
| 814 | 771 | ||
| 815 | 772 | ||
| 816 | (defun bookmark-default-annotation-text (bookmark) | 773 | (defun bookmark-default-annotation-text (bookmark) |
| @@ -822,52 +779,20 @@ the bookmark (and file, and point) specified in buffer local variables." | |||
| 822 | "# Date: " (current-time-string) "\n")) | 779 | "# Date: " (current-time-string) "\n")) |
| 823 | 780 | ||
| 824 | 781 | ||
| 825 | (defvar bookmark-read-annotation-text-func 'bookmark-default-annotation-text | 782 | (defvar bookmark-edit-annotation-text-func 'bookmark-default-annotation-text |
| 826 | "Function to return default text to use for a bookmark annotation. | 783 | "Function to return default text to use for a bookmark annotation. |
| 827 | It takes one argument, the name of the bookmark, as a string.") | 784 | It takes one argument, the name of the bookmark, as a string.") |
| 785 | (define-obsolete-variable-alias 'bookmark-read-annotation-text-func | ||
| 786 | 'bookmark-edit-annotation-text-func "23.1") | ||
| 828 | 787 | ||
| 829 | (defun bookmark-read-annotation-mode (buf point parg bookmark) | 788 | (defvar bookmark-edit-annotation-mode-map |
| 830 | "Mode for composing annotations for a bookmark. | 789 | (let ((map (make-sparse-keymap))) |
| 831 | Wants BUF, POINT, PARG, and BOOKMARK. | 790 | (set-keymap-parent map text-mode-map) |
| 832 | When you have finished composing, type \\[bookmark-send-annotation] to send | 791 | (define-key map "\C-c\C-c" 'bookmark-send-edited-annotation) |
| 833 | the annotation. | 792 | map) |
| 834 | |||
| 835 | \\{bookmark-read-annotation-mode-map}" | ||
| 836 | (interactive) | ||
| 837 | (kill-all-local-variables) | ||
| 838 | (make-local-variable 'bookmark-annotation-paragraph) | ||
| 839 | (make-local-variable 'bookmark-annotation-name) | ||
| 840 | (make-local-variable 'bookmark-annotation-buffer) | ||
| 841 | (make-local-variable 'bookmark-annotation-file) | ||
| 842 | (make-local-variable 'bookmark-annotation-point) | ||
| 843 | (setq bookmark-annotation-paragraph parg) | ||
| 844 | (setq bookmark-annotation-name bookmark) | ||
| 845 | (setq bookmark-annotation-buffer buf) | ||
| 846 | (setq bookmark-annotation-file (buffer-file-name buf)) | ||
| 847 | (setq bookmark-annotation-point point) | ||
| 848 | (use-local-map bookmark-read-annotation-mode-map) | ||
| 849 | (setq major-mode 'bookmark-read-annotation-mode) | ||
| 850 | (insert (funcall bookmark-read-annotation-text-func bookmark)) | ||
| 851 | (run-mode-hooks 'text-mode-hook)) | ||
| 852 | |||
| 853 | |||
| 854 | (defun bookmark-read-annotation (parg bookmark) | ||
| 855 | "Pop up a buffer for entering a bookmark annotation. | ||
| 856 | Text surrounding the bookmark is PARG; the bookmark name is BOOKMARK." | ||
| 857 | (let ((buf (current-buffer)) | ||
| 858 | (point (point))) | ||
| 859 | (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*")) | ||
| 860 | (bookmark-read-annotation-mode buf point parg bookmark))) | ||
| 861 | |||
| 862 | |||
| 863 | (defvar bookmark-edit-annotation-mode-map (copy-keymap text-mode-map) | ||
| 864 | "Keymap for editing an annotation of a bookmark.") | 793 | "Keymap for editing an annotation of a bookmark.") |
| 865 | 794 | ||
| 866 | 795 | ||
| 867 | (define-key bookmark-edit-annotation-mode-map "\C-c\C-c" | ||
| 868 | 'bookmark-send-edited-annotation) | ||
| 869 | |||
| 870 | |||
| 871 | (defun bookmark-edit-annotation-mode (bookmark) | 796 | (defun bookmark-edit-annotation-mode (bookmark) |
| 872 | "Mode for editing the annotation of bookmark BOOKMARK. | 797 | "Mode for editing the annotation of bookmark BOOKMARK. |
| 873 | When you have finished composing, type \\[bookmark-send-annotation]. | 798 | When you have finished composing, type \\[bookmark-send-annotation]. |
| @@ -880,7 +805,7 @@ When you have finished composing, type \\[bookmark-send-annotation]. | |||
| 880 | (use-local-map bookmark-edit-annotation-mode-map) | 805 | (use-local-map bookmark-edit-annotation-mode-map) |
| 881 | (setq major-mode 'bookmark-edit-annotation-mode | 806 | (setq major-mode 'bookmark-edit-annotation-mode |
| 882 | mode-name "Edit Bookmark Annotation") | 807 | mode-name "Edit Bookmark Annotation") |
| 883 | (insert (funcall bookmark-read-annotation-text-func bookmark)) | 808 | (insert (funcall bookmark-edit-annotation-text-func bookmark)) |
| 884 | (let ((annotation (bookmark-get-annotation bookmark))) | 809 | (let ((annotation (bookmark-get-annotation bookmark))) |
| 885 | (if (and annotation (not (string-equal annotation ""))) | 810 | (if (and annotation (not (string-equal annotation ""))) |
| 886 | (insert annotation))) | 811 | (insert annotation))) |