Mercurial > emacs
comparison lisp/bookmark.el @ 91302:56a72e2bd635
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-306
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sat, 29 Dec 2007 02:39:17 +0000 |
parents | 14c4a6aac623 9ac481bc897b |
children | 606f2d163a64 |
comparison
equal
deleted
inserted
replaced
91301:7774e5860c70 | 91302:56a72e2bd635 |
---|---|
441 (list (cons 'info-node node))))) | 441 (list (cons 'info-node node))))) |
442 | 442 |
443 (message "%S" (assq 'info-node (bookmark-get-bookmark-record bookmark))) | 443 (message "%S" (assq 'info-node (bookmark-get-bookmark-record bookmark))) |
444 (sit-for 4)) | 444 (sit-for 4)) |
445 | 445 |
446 (defun bookmark-get-handler (bookmark) | |
447 (cdr (assq 'handler (bookmark-get-bookmark-record bookmark)))) | |
446 | 448 |
447 (defvar bookmark-history nil | 449 (defvar bookmark-history nil |
448 "The history list for bookmark functions.") | 450 "The history list for bookmark functions.") |
449 | 451 |
450 | 452 |
478 menus, so `completing-read' never gets a chance to set `bookmark-history'." | 480 menus, so `completing-read' never gets a chance to set `bookmark-history'." |
479 `(or | 481 `(or |
480 (interactive-p) | 482 (interactive-p) |
481 (setq bookmark-history (cons ,string bookmark-history)))) | 483 (setq bookmark-history (cons ,string bookmark-history)))) |
482 | 484 |
485 (defvar bookmark-make-cell-function 'bookmark-make-cell-for-text-file | |
486 "A function that should be called to create the bookmark | |
487 record. Modes may set this variable buffer-locally to enable | |
488 bookmarking of non-text files like images or pdf documents. | |
489 | |
490 The function will be called with two arguments: ANNOTATION and | |
491 INFO-NODE. See `bookmark-make-cell-for-text-file' for a | |
492 description. | |
493 | |
494 The returned record may contain a special cons (handler | |
495 . some-function) which sets the handler function that should be | |
496 used to open this bookmark instead of `bookmark-jump-noselect'. | |
497 It should return a cons (BUFFER . POINT) indicating buffer | |
498 showing the bookmarked location and the value of point in that | |
499 buffer. Like `bookmark-jump-noselect' the buffer shouldn't be | |
500 selected by the handler.") | |
483 | 501 |
484 (defun bookmark-make (name &optional annotation overwrite info-node) | 502 (defun bookmark-make (name &optional annotation overwrite info-node) |
485 "Make a bookmark named NAME. | 503 "Make a bookmark named NAME. |
486 Optional second arg ANNOTATION gives it an annotation. | 504 Optional second arg ANNOTATION gives it an annotation. |
487 Optional third arg OVERWRITE means replace any existing bookmarks with | 505 Optional third arg OVERWRITE means replace any existing bookmarks with |
496 (set-text-properties 0 (length stripped-name) nil stripped-name)) | 514 (set-text-properties 0 (length stripped-name) nil stripped-name)) |
497 (if (and (bookmark-get-bookmark stripped-name) (not overwrite)) | 515 (if (and (bookmark-get-bookmark stripped-name) (not overwrite)) |
498 ;; already existing bookmark under that name and | 516 ;; already existing bookmark under that name and |
499 ;; no prefix arg means just overwrite old bookmark | 517 ;; no prefix arg means just overwrite old bookmark |
500 (setcdr (bookmark-get-bookmark stripped-name) | 518 (setcdr (bookmark-get-bookmark stripped-name) |
501 (list (bookmark-make-cell annotation info-node))) | 519 (list (funcall bookmark-make-cell-function annotation info-node))) |
502 | 520 |
503 ;; otherwise just cons it onto the front (either the bookmark | 521 ;; otherwise just cons it onto the front (either the bookmark |
504 ;; doesn't exist already, or there is no prefix arg. In either | 522 ;; doesn't exist already, or there is no prefix arg. In either |
505 ;; case, we want the new bookmark consed onto the alist...) | 523 ;; case, we want the new bookmark consed onto the alist...) |
506 | 524 |
507 (setq bookmark-alist | 525 (setq bookmark-alist |
508 (cons | 526 (cons |
509 (list stripped-name | 527 (list stripped-name |
510 (bookmark-make-cell annotation info-node)) | 528 (funcall bookmark-make-cell-function annotation info-node)) |
511 bookmark-alist))) | 529 bookmark-alist))) |
512 | 530 |
513 ;; Added by db | 531 ;; Added by db |
514 (setq bookmark-current-bookmark stripped-name) | 532 (setq bookmark-current-bookmark stripped-name) |
515 (setq bookmark-alist-modification-count | 533 (setq bookmark-alist-modification-count |
516 (1+ bookmark-alist-modification-count)) | 534 (1+ bookmark-alist-modification-count)) |
517 (if (bookmark-time-to-save-p) | 535 (if (bookmark-time-to-save-p) |
518 (bookmark-save)))) | 536 (bookmark-save)))) |
519 | 537 |
520 | 538 |
521 (defun bookmark-make-cell (annotation &optional info-node) | 539 (defun bookmark-make-cell-for-text-file (annotation &optional info-node) |
522 "Return the record part of a new bookmark, given ANNOTATION. | 540 "Return the record part of a new bookmark, given ANNOTATION. |
523 Must be at the correct position in the buffer in which the bookmark is | 541 Must be at the correct position in the buffer in which the bookmark is |
524 being set. This might change someday. | 542 being set. This might change someday. |
525 Optional second arg INFO-NODE means this bookmark is at info node | 543 Optional second arg INFO-NODE means this bookmark is at info node |
526 INFO-NODE, so record this fact in the bookmark's entry." | 544 INFO-NODE, so record this fact in the bookmark's entry." |
778 (bookmark-bmenu-surreptitiously-rebuild-list) | 796 (bookmark-bmenu-surreptitiously-rebuild-list) |
779 (goto-char bookmark-current-point)))) | 797 (goto-char bookmark-current-point)))) |
780 | 798 |
781 | 799 |
782 (defun bookmark-info-current-node () | 800 (defun bookmark-info-current-node () |
783 "If in Info-mode, return current node name (a string), else nil." | 801 "If in `Info-mode', return current node name (a string), else nil." |
784 (if (eq major-mode 'Info-mode) | 802 (if (eq major-mode 'Info-mode) |
785 Info-current-node)) | 803 Info-current-node)) |
786 | 804 |
787 | 805 |
788 (defun bookmark-kill-line (&optional newline-too) | 806 (defun bookmark-kill-line (&optional newline-too) |
853 "Mode for composing annotations for a bookmark. | 871 "Mode for composing annotations for a bookmark. |
854 Wants BUF, POINT, PARG, and BOOKMARK. | 872 Wants BUF, POINT, PARG, and BOOKMARK. |
855 When you have finished composing, type \\[bookmark-send-annotation] to send | 873 When you have finished composing, type \\[bookmark-send-annotation] to send |
856 the annotation. | 874 the annotation. |
857 | 875 |
858 \\{bookmark-read-annotation-mode-map} | 876 \\{bookmark-read-annotation-mode-map}" |
859 " | |
860 (interactive) | 877 (interactive) |
861 (kill-all-local-variables) | 878 (kill-all-local-variables) |
862 (make-local-variable 'bookmark-annotation-paragraph) | 879 (make-local-variable 'bookmark-annotation-paragraph) |
863 (make-local-variable 'bookmark-annotation-name) | 880 (make-local-variable 'bookmark-annotation-name) |
864 (make-local-variable 'bookmark-annotation-buffer) | 881 (make-local-variable 'bookmark-annotation-buffer) |
894 | 911 |
895 (defun bookmark-edit-annotation-mode (bookmark) | 912 (defun bookmark-edit-annotation-mode (bookmark) |
896 "Mode for editing the annotation of bookmark BOOKMARK. | 913 "Mode for editing the annotation of bookmark BOOKMARK. |
897 When you have finished composing, type \\[bookmark-send-annotation]. | 914 When you have finished composing, type \\[bookmark-send-annotation]. |
898 | 915 |
899 \\{bookmark-edit-annotation-mode-map} | 916 \\{bookmark-edit-annotation-mode-map}" |
900 " | |
901 (interactive) | 917 (interactive) |
902 (kill-all-local-variables) | 918 (kill-all-local-variables) |
903 (make-local-variable 'bookmark-annotation-name) | 919 (make-local-variable 'bookmark-annotation-name) |
904 (setq bookmark-annotation-name bookmark) | 920 (setq bookmark-annotation-name bookmark) |
905 (use-local-map bookmark-edit-annotation-mode-map) | 921 (use-local-map bookmark-edit-annotation-mode-map) |
1066 (list (bookmark-completing-read "Jump to bookmark" | 1082 (list (bookmark-completing-read "Jump to bookmark" |
1067 bookmark-current-bookmark))) | 1083 bookmark-current-bookmark))) |
1068 (unless bookmark | 1084 (unless bookmark |
1069 (error "No bookmark specified")) | 1085 (error "No bookmark specified")) |
1070 (bookmark-maybe-historicize-string bookmark) | 1086 (bookmark-maybe-historicize-string bookmark) |
1071 (let ((cell (bookmark-jump-noselect bookmark))) | 1087 (let ((cell (bookmark-jump-internal bookmark))) |
1072 (and cell | 1088 (and cell |
1073 (switch-to-buffer (car cell)) | 1089 (switch-to-buffer (car cell)) |
1074 (goto-char (cdr cell)) | 1090 (goto-char (cdr cell)) |
1075 (progn (run-hooks 'bookmark-after-jump-hook) t) | 1091 (progn (run-hooks 'bookmark-after-jump-hook) t) |
1076 (if bookmark-automatically-show-annotations | 1092 (if bookmark-automatically-show-annotations |
1088 bookmark-current-bookmark))) | 1104 bookmark-current-bookmark))) |
1089 (if (> emacs-major-version 21) | 1105 (if (> emacs-major-version 21) |
1090 (list bkm) bkm))) | 1106 (list bkm) bkm))) |
1091 (when bookmark | 1107 (when bookmark |
1092 (bookmark-maybe-historicize-string bookmark) | 1108 (bookmark-maybe-historicize-string bookmark) |
1093 (let ((cell (bookmark-jump-noselect bookmark))) | 1109 (let ((cell (bookmark-jump-internal bookmark))) |
1094 (and cell | 1110 (and cell |
1095 (switch-to-buffer-other-window (car cell)) | 1111 (switch-to-buffer-other-window (car cell)) |
1096 (goto-char (cdr cell)) | 1112 (goto-char (cdr cell)) |
1097 (if bookmark-automatically-show-annotations | 1113 (if bookmark-automatically-show-annotations |
1098 ;; if there is an annotation for this bookmark, | 1114 ;; if there is an annotation for this bookmark, |
1118 Info-suffix-list) | 1134 Info-suffix-list) |
1119 nil)) | 1135 nil)) |
1120 ;; Last possibility: try VC | 1136 ;; Last possibility: try VC |
1121 (if (vc-backend file) file)))) | 1137 (if (vc-backend file) file)))) |
1122 | 1138 |
1139 (defun bookmark-jump-internal (bookmark) | |
1140 "Call BOOKMARK's handler or `bookmark-jump-noselect' if it has none." | |
1141 (funcall (or (bookmark-get-handler bookmark) | |
1142 'bookmark-jump-noselect) | |
1143 bookmark)) | |
1123 | 1144 |
1124 (defun bookmark-jump-noselect (str) | 1145 (defun bookmark-jump-noselect (str) |
1125 ;; a leetle helper for bookmark-jump :-) | 1146 ;; a leetle helper for bookmark-jump :-) |
1126 ;; returns (BUFFER . POINT) | 1147 ;; returns (BUFFER . POINT) |
1127 (bookmark-maybe-load-default-file) | 1148 (bookmark-maybe-load-default-file) |
1271 this." | 1292 this." |
1272 (interactive (list (bookmark-completing-read "Insert bookmark contents"))) | 1293 (interactive (list (bookmark-completing-read "Insert bookmark contents"))) |
1273 (bookmark-maybe-historicize-string bookmark) | 1294 (bookmark-maybe-historicize-string bookmark) |
1274 (bookmark-maybe-load-default-file) | 1295 (bookmark-maybe-load-default-file) |
1275 (let ((orig-point (point)) | 1296 (let ((orig-point (point)) |
1276 (str-to-insert | 1297 (str-to-insert |
1277 (save-excursion | 1298 (save-excursion |
1278 (set-buffer (car (bookmark-jump-noselect bookmark))) | 1299 (set-buffer (car (bookmark-jump-internal bookmark))) |
1279 (buffer-string)))) | 1300 (buffer-string)))) |
1280 (insert str-to-insert) | 1301 (insert str-to-insert) |
1281 (push-mark) | 1302 (push-mark) |
1282 (goto-char orig-point))) | 1303 (goto-char orig-point))) |
1283 | 1304 |
1284 | 1305 |
1902 (let ((bmrk (bookmark-bmenu-bookmark)) | 1923 (let ((bmrk (bookmark-bmenu-bookmark)) |
1903 (menu (current-buffer)) | 1924 (menu (current-buffer)) |
1904 (pop-up-windows t)) | 1925 (pop-up-windows t)) |
1905 (delete-other-windows) | 1926 (delete-other-windows) |
1906 (switch-to-buffer (other-buffer)) | 1927 (switch-to-buffer (other-buffer)) |
1907 (let* ((pair (bookmark-jump-noselect bmrk)) | 1928 (let* ((pair (bookmark-jump-internal bmrk)) |
1908 (buff (car pair)) | 1929 (buff (car pair)) |
1909 (pos (cdr pair))) | 1930 (pos (cdr pair))) |
1910 (pop-to-buffer buff) | 1931 (pop-to-buffer buff) |
1911 (goto-char pos)) | 1932 (goto-char pos)) |
1912 (bury-buffer menu)))) | 1933 (bury-buffer menu)))) |
1922 (defun bookmark-bmenu-other-window () | 1943 (defun bookmark-bmenu-other-window () |
1923 "Select this line's bookmark in other window, leaving bookmark menu visible." | 1944 "Select this line's bookmark in other window, leaving bookmark menu visible." |
1924 (interactive) | 1945 (interactive) |
1925 (let ((bookmark (bookmark-bmenu-bookmark))) | 1946 (let ((bookmark (bookmark-bmenu-bookmark))) |
1926 (if (bookmark-bmenu-check-position) | 1947 (if (bookmark-bmenu-check-position) |
1927 (let* ((pair (bookmark-jump-noselect bookmark)) | 1948 (let* ((pair (bookmark-jump-internal bookmark)) |
1928 (buff (car pair)) | 1949 (buff (car pair)) |
1929 (pos (cdr pair))) | 1950 (pos (cdr pair))) |
1930 (switch-to-buffer-other-window buff) | 1951 (switch-to-buffer-other-window buff) |
1931 (goto-char pos) | 1952 (goto-char pos) |
1932 (set-window-point (get-buffer-window buff) pos) | 1953 (set-window-point (get-buffer-window buff) pos) |
1940 (let ((bookmark (bookmark-bmenu-bookmark)) | 1961 (let ((bookmark (bookmark-bmenu-bookmark)) |
1941 (pop-up-windows t) | 1962 (pop-up-windows t) |
1942 same-window-buffer-names | 1963 same-window-buffer-names |
1943 same-window-regexps) | 1964 same-window-regexps) |
1944 (if (bookmark-bmenu-check-position) | 1965 (if (bookmark-bmenu-check-position) |
1945 (let* ((pair (bookmark-jump-noselect bookmark)) | 1966 (let* ((pair (bookmark-jump-internal bookmark)) |
1946 (buff (car pair)) | 1967 (buff (car pair)) |
1947 (pos (cdr pair))) | 1968 (pos (cdr pair))) |
1948 (display-buffer buff) | 1969 (display-buffer buff) |
1949 (let ((o-buffer (current-buffer))) | 1970 (let ((o-buffer (current-buffer))) |
1950 ;; save-excursion won't do | 1971 ;; save-excursion won't do |