diff options
| author | Tassilo Horn | 2007-12-26 08:53:06 +0000 |
|---|---|---|
| committer | Tassilo Horn | 2007-12-26 08:53:06 +0000 |
| commit | 1666a6b3e851967e9b37de28c4c2ece2926a0cf5 (patch) | |
| tree | 3bcb8244c03187c5a28d6f947129f9ab36f5dde5 | |
| parent | afa39f21c8d27bed08525ee0ed23692f12d2b3e2 (diff) | |
| download | emacs-1666a6b3e851967e9b37de28c4c2ece2926a0cf5.tar.gz emacs-1666a6b3e851967e9b37de28c4c2ece2926a0cf5.zip | |
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
* bookmark.el (bookmark-make-cell-function): New variable.
(bookmark-make): Call bookmark-make-cell-function's function
instead of bookmark-make-cell.
(bookmark-get-handler, bookmark-jump-internal): New functions.
(bookmark-jump, bookmark-jump-other-window, bookmark-insert)
(bookmark-bmenu-2-window, bookmark-bmenu-other-window): Use
bookmark-jump-internal.
(bookmark-make-cell-for-text-file): Renamed from
bookmark-make-cell.
* doc-view.el (doc-view-bookmark-make-cell)
(doc-view-bookmark-jump): New functions.
(doc-view-mode): Set bookmark-make-cell-function buffer-locally.
| -rw-r--r-- | lisp/ChangeLog | 16 | ||||
| -rw-r--r-- | lisp/bookmark.el | 55 | ||||
| -rw-r--r-- | lisp/doc-view.el | 30 |
3 files changed, 84 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f4533083e2c..060e932b23c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2007-12-26 Tassilo Horn <tassilo@member.fsf.org> | ||
| 2 | |||
| 3 | * bookmark.el (bookmark-make-cell-function): New variable. | ||
| 4 | (bookmark-make): Call bookmark-make-cell-function's function | ||
| 5 | instead of bookmark-make-cell. | ||
| 6 | (bookmark-get-handler, bookmark-jump-internal): New functions. | ||
| 7 | (bookmark-jump, bookmark-jump-other-window, bookmark-insert) | ||
| 8 | (bookmark-bmenu-2-window, bookmark-bmenu-other-window): Use | ||
| 9 | bookmark-jump-internal. | ||
| 10 | (bookmark-make-cell-for-text-file): Renamed from | ||
| 11 | bookmark-make-cell. | ||
| 12 | |||
| 13 | * doc-view.el (doc-view-bookmark-make-cell) | ||
| 14 | (doc-view-bookmark-jump): New functions. | ||
| 15 | (doc-view-mode): Set bookmark-make-cell-function buffer-locally. | ||
| 16 | |||
| 1 | 2007-12-25 Miles Bader <miles@gnu.org> | 17 | 2007-12-25 Miles Bader <miles@gnu.org> |
| 2 | 18 | ||
| 3 | * indent.el (indent-for-tab-command): Rigidly indent the following | 19 | * indent.el (indent-for-tab-command): Rigidly indent the following |
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 184f9de518c..9b8eb738f0c 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -443,6 +443,8 @@ That is, all information but the name." | |||
| 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.") |
| @@ -480,6 +482,22 @@ menus, so `completing-read' never gets a chance to set `bookmark-history'." | |||
| 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. |
| @@ -498,7 +516,7 @@ INFO-NODE, so record this fact in the bookmark's entry." | |||
| 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 |
| @@ -507,7 +525,7 @@ INFO-NODE, so record this fact in the bookmark's entry." | |||
| 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 |
| @@ -518,7 +536,7 @@ INFO-NODE, so record this fact in the bookmark's entry." | |||
| 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. |
| @@ -780,7 +798,7 @@ the list of bookmarks.\)" | |||
| 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 | ||
| @@ -855,8 +873,7 @@ 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) |
| @@ -896,8 +913,7 @@ Text surrounding the bookmark is PARG; the bookmark name is 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) |
| @@ -1068,7 +1084,7 @@ of the old one in the permanent bookmark record." | |||
| 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)) |
| @@ -1090,7 +1106,7 @@ See `bookmark-jump'." | |||
| 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)) |
| @@ -1120,6 +1136,11 @@ be retrieved from a VC backend, else return 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 :-) |
| @@ -1273,10 +1294,10 @@ this." | |||
| 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))) |
| @@ -1904,7 +1925,7 @@ With a prefix arg, prompts for a file to save them in." | |||
| 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) |
| @@ -1924,7 +1945,7 @@ With a prefix arg, prompts for a file to save them in." | |||
| 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) |
| @@ -1942,7 +1963,7 @@ The current window remains selected." | |||
| 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) |
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 9073ce1536a..12b3012448e 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -958,6 +958,8 @@ toggle between displaying the document or editing it as text." | |||
| 958 | (set (make-local-variable 'cursor-type) nil) | 958 | (set (make-local-variable 'cursor-type) nil) |
| 959 | (use-local-map doc-view-mode-map) | 959 | (use-local-map doc-view-mode-map) |
| 960 | (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc) | 960 | (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc) |
| 961 | (set (make-local-variable 'bookmark-make-cell-function) | ||
| 962 | 'doc-view-bookmark-make-cell) | ||
| 961 | (setq mode-name "DocView" | 963 | (setq mode-name "DocView" |
| 962 | buffer-read-only t | 964 | buffer-read-only t |
| 963 | major-mode 'doc-view-mode) | 965 | major-mode 'doc-view-mode) |
| @@ -996,4 +998,32 @@ See the command `doc-view-mode' for more information on this mode." | |||
| 996 | ;; End: | 998 | ;; End: |
| 997 | 999 | ||
| 998 | ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be | 1000 | ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be |
| 1001 | ;;;; Bookmark integration | ||
| 1002 | |||
| 1003 | (defun doc-view-bookmark-make-cell (annotation &rest args) | ||
| 1004 | (let ((the-record | ||
| 1005 | `((filename . ,(buffer-file-name)) | ||
| 1006 | (page . ,doc-view-current-page) | ||
| 1007 | (handler . doc-view-bookmark-jump)))) | ||
| 1008 | |||
| 1009 | ;; Take no chances with text properties | ||
| 1010 | (set-text-properties 0 (length annotation) nil annotation) | ||
| 1011 | |||
| 1012 | (when annotation | ||
| 1013 | (nconc the-record (list (cons 'annotation annotation)))) | ||
| 1014 | |||
| 1015 | ;; Finally, return the completed record. | ||
| 1016 | the-record)) | ||
| 1017 | |||
| 1018 | ;;;###autoload | ||
| 1019 | (defun doc-view-bookmark-jump (bmk) | ||
| 1020 | (save-window-excursion | ||
| 1021 | (let ((filename (bookmark-get-filename bmk)) | ||
| 1022 | (page (cdr (assq 'page (bookmark-get-bookmark-record bookmark))))) | ||
| 1023 | (find-file filename) | ||
| 1024 | (when (not (eq major-mode 'doc-view-mode)) | ||
| 1025 | (doc-view-toggle-display)) | ||
| 1026 | (doc-view-goto-page page) | ||
| 1027 | (cons (current-buffer) 1)))) | ||
| 1028 | |||
| 999 | ;;; doc-view.el ends here | 1029 | ;;; doc-view.el ends here |