]> git.eshelyaron.com Git - emacs.git/commitdiff
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
authorTassilo Horn <tassilo@member.fsf.org>
Wed, 26 Dec 2007 08:53:06 +0000 (08:53 +0000)
committerTassilo Horn <tassilo@member.fsf.org>
Wed, 26 Dec 2007 08:53:06 +0000 (08:53 +0000)
* 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.

lisp/ChangeLog
lisp/bookmark.el
lisp/doc-view.el

index f4533083e2c913ce25f45fa33763539410a1fc66..060e932b23cd3317a715839a68e352cc4b0d6f04 100644 (file)
@@ -1,3 +1,19 @@
+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.
+
 2007-12-25  Miles Bader  <miles@gnu.org>
 
        * indent.el (indent-for-tab-command): Rigidly indent the following
index 184f9de518cc4597bdc7fe224a707bb8eabbb610..9b8eb738f0cd6b80869dd5ae9372728cd4c612b2 100644 (file)
@@ -443,6 +443,8 @@ That is, all information but the name."
   (message "%S" (assq 'info-node (bookmark-get-bookmark-record bookmark)))
   (sit-for 4))
 
+(defun bookmark-get-handler (bookmark)
+  (cdr (assq 'handler (bookmark-get-bookmark-record bookmark))))
 
 (defvar bookmark-history nil
   "The history list for bookmark functions.")
@@ -480,6 +482,22 @@ menus, so `completing-read' never gets a chance to set `bookmark-history'."
     (interactive-p)
     (setq bookmark-history (cons ,string bookmark-history))))
 
+(defvar bookmark-make-cell-function 'bookmark-make-cell-for-text-file
+  "A function that should be called to create the bookmark
+record.  Modes may set this variable buffer-locally to enable
+bookmarking of non-text files like images or pdf documents.
+
+The function will be called with two arguments: ANNOTATION and
+INFO-NODE.  See `bookmark-make-cell-for-text-file' for a
+description.
+
+The returned record may contain a special cons (handler
+. some-function) which sets the handler function that should be
+used to open this bookmark instead of `bookmark-jump-noselect'.
+It should return a cons (BUFFER . POINT) indicating buffer
+showing the bookmarked location and the value of point in that
+buffer.  Like `bookmark-jump-noselect' the buffer shouldn't be
+selected by the handler.")
 
 (defun bookmark-make (name &optional annotation overwrite info-node)
   "Make a bookmark named NAME.
@@ -498,7 +516,7 @@ INFO-NODE, so record this fact in the bookmark's entry."
         ;; already existing bookmark under that name and
         ;; no prefix arg means just overwrite old bookmark
         (setcdr (bookmark-get-bookmark stripped-name)
-                (list (bookmark-make-cell annotation info-node)))
+                (list (funcall bookmark-make-cell-function annotation info-node)))
 
       ;; otherwise just cons it onto the front (either the bookmark
       ;; 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."
       (setq bookmark-alist
             (cons
              (list stripped-name
-                   (bookmark-make-cell annotation info-node))
+                   (funcall bookmark-make-cell-function annotation info-node))
              bookmark-alist)))
 
     ;; Added by db
@@ -518,7 +536,7 @@ INFO-NODE, so record this fact in the bookmark's entry."
         (bookmark-save))))
 
 
-(defun bookmark-make-cell (annotation &optional info-node)
+(defun bookmark-make-cell-for-text-file (annotation &optional info-node)
   "Return the record part of a new bookmark, given ANNOTATION.
 Must be at the correct position in the buffer in which the bookmark is
 being set.  This might change someday.
@@ -780,7 +798,7 @@ the list of bookmarks.\)"
 
 
 (defun bookmark-info-current-node ()
-  "If in Info-mode, return current node name (a string), else nil."
+  "If in `Info-mode', return current node name (a string), else nil."
   (if (eq major-mode 'Info-mode)
       Info-current-node))
 
@@ -855,8 +873,7 @@ Wants BUF, POINT, PARG, and BOOKMARK.
 When you have finished composing, type \\[bookmark-send-annotation] to send
 the annotation.
 
-\\{bookmark-read-annotation-mode-map}
-"
+\\{bookmark-read-annotation-mode-map}"
   (interactive)
   (kill-all-local-variables)
   (make-local-variable 'bookmark-annotation-paragraph)
@@ -896,8 +913,7 @@ Text surrounding the bookmark is PARG; the bookmark name is BOOKMARK."
   "Mode for editing the annotation of bookmark BOOKMARK.
 When you have finished composing, type \\[bookmark-send-annotation].
 
-\\{bookmark-edit-annotation-mode-map}
-"
+\\{bookmark-edit-annotation-mode-map}"
   (interactive)
   (kill-all-local-variables)
   (make-local-variable 'bookmark-annotation-name)
@@ -1068,7 +1084,7 @@ of the old one in the permanent bookmark record."
   (unless bookmark
     (error "No bookmark specified"))
   (bookmark-maybe-historicize-string bookmark)
-  (let ((cell (bookmark-jump-noselect bookmark)))
+  (let ((cell (bookmark-jump-internal bookmark)))
     (and cell
          (switch-to-buffer (car cell))
          (goto-char (cdr cell))
@@ -1090,7 +1106,7 @@ See `bookmark-jump'."
          (list bkm) bkm)))
   (when bookmark
     (bookmark-maybe-historicize-string bookmark)
-    (let ((cell (bookmark-jump-noselect bookmark)))
+    (let ((cell (bookmark-jump-internal bookmark)))
       (and cell
            (switch-to-buffer-other-window (car cell))
            (goto-char (cdr cell))
@@ -1120,6 +1136,11 @@ be retrieved from a VC backend, else return nil."
      ;; Last possibility: try VC
      (if (vc-backend file) file))))
 
+(defun bookmark-jump-internal (bookmark)
+  "Call BOOKMARK's handler or `bookmark-jump-noselect' if it has none."
+  (funcall (or (bookmark-get-handler bookmark)
+              'bookmark-jump-noselect)
+          bookmark))
 
 (defun bookmark-jump-noselect (str)
   ;; a leetle helper for bookmark-jump :-)
@@ -1273,10 +1294,10 @@ this."
   (bookmark-maybe-historicize-string bookmark)
   (bookmark-maybe-load-default-file)
   (let ((orig-point (point))
-        (str-to-insert
-         (save-excursion
-           (set-buffer (car (bookmark-jump-noselect bookmark)))
-           (buffer-string))))
+       (str-to-insert
+        (save-excursion
+          (set-buffer (car (bookmark-jump-internal bookmark)))
+          (buffer-string))))
     (insert str-to-insert)
     (push-mark)
     (goto-char orig-point)))
@@ -1904,7 +1925,7 @@ With a prefix arg, prompts for a file to save them in."
             (pop-up-windows t))
         (delete-other-windows)
         (switch-to-buffer (other-buffer))
-       (let* ((pair (bookmark-jump-noselect bmrk))
+       (let* ((pair (bookmark-jump-internal bmrk))
                (buff (car pair))
                (pos  (cdr pair)))
           (pop-to-buffer buff)
@@ -1924,7 +1945,7 @@ With a prefix arg, prompts for a file to save them in."
   (interactive)
   (let ((bookmark (bookmark-bmenu-bookmark)))
     (if (bookmark-bmenu-check-position)
-       (let* ((pair (bookmark-jump-noselect bookmark))
+       (let* ((pair (bookmark-jump-internal bookmark))
                (buff (car pair))
                (pos  (cdr pair)))
          (switch-to-buffer-other-window buff)
@@ -1942,7 +1963,7 @@ The current window remains selected."
         same-window-buffer-names
         same-window-regexps)
     (if (bookmark-bmenu-check-position)
-       (let* ((pair (bookmark-jump-noselect bookmark))
+       (let* ((pair (bookmark-jump-internal bookmark))
                (buff (car pair))
                (pos  (cdr pair)))
          (display-buffer buff)
index 9073ce1536aa06ce52c42a11fa735eb96c01bc9b..12b3012448e3d23630cf2f6164c73a09242b54bc 100644 (file)
@@ -958,6 +958,8 @@ toggle between displaying the document or editing it as text."
     (set (make-local-variable 'cursor-type) nil)
     (use-local-map doc-view-mode-map)
     (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
+    (set (make-local-variable 'bookmark-make-cell-function)
+                             'doc-view-bookmark-make-cell)
     (setq mode-name "DocView"
          buffer-read-only t
          major-mode 'doc-view-mode)
@@ -996,4 +998,32 @@ See the command `doc-view-mode' for more information on this mode."
 ;; End:
 
 ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be
+;;;; Bookmark integration
+
+(defun doc-view-bookmark-make-cell (annotation &rest args)
+  (let ((the-record
+         `((filename . ,(buffer-file-name))
+           (page     . ,doc-view-current-page)
+           (handler  . doc-view-bookmark-jump))))
+
+    ;; Take no chances with text properties
+    (set-text-properties 0 (length annotation) nil annotation)
+
+    (when annotation
+      (nconc the-record (list (cons 'annotation annotation))))
+
+    ;; Finally, return the completed record.
+    the-record))
+
+;;;###autoload
+(defun doc-view-bookmark-jump (bmk)
+  (save-window-excursion
+    (let ((filename (bookmark-get-filename bmk))
+         (page (cdr (assq 'page (bookmark-get-bookmark-record bookmark)))))
+      (find-file filename)
+      (when (not (eq major-mode 'doc-view-mode))
+       (doc-view-toggle-display))
+      (doc-view-goto-page page)
+      (cons (current-buffer) 1))))
+
 ;;; doc-view.el ends here