emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

doc-view support for bookmark.el


From: Tassilo Horn
Subject: doc-view support for bookmark.el
Date: Tue, 25 Dec 2007 11:54:00 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

Hi all,

on emacs-sources there was a request for a bookmarking facility for
doc-view, so I added support for it in bookmark.el.

When I was doing that I found some strange code: bookmark-jump-noselect
opened the bookmarked file, set point at the correct position and
returned a cons (BUFFER . POSITION).  All calling functions did set the
position once again.  I suspect that was a relict of the past, so I
removed it and now bookmark-jump-noselect only returns the buffer.

Till now I didn't use bookmarks, so I'm not sure if this change will
break something.  So bookmark-users, please test it.  (For me it works
nicely, but I only tested simple setting and jumping.)

If nobody complains in some days or some people report that it works for
them, I'll install the change.

--8<---------------cut here---------------start------------->8---
2007-12-25  Tassilo Horn  <address@hidden>

        * bookmark.el (bookmark-jump-noselect): Return only the bookmark
        buffer.
        (bookmark-insert, bookmark-bmenu-2-window)
        (bookmark-bmenu-other-window, bookmark-jump)
        (bookmark-jump-other-window, bookmark-bmenu-switch-other-window):
        Adapt to that.
        (bookmark-doc-view-p, bookmark-get-doc-view-page)
        (bookmark-set-doc-view-page): New functions.
        (bookmark-make-cell, bookmark-jump-noselect): Support
        doc-view-buffers.
--8<---------------cut here---------------end--------------->8---

Here's the patch:

--8<---------------cut here---------------start------------->8---
Index: lisp/bookmark.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bookmark.el,v
retrieving revision 1.98
diff -u -r1.98 bookmark.el
--- lisp/bookmark.el    25 Sep 2007 10:43:39 -0000      1.98
+++ lisp/bookmark.el    25 Dec 2007 10:50:49 -0000
@@ -526,19 +526,22 @@
 INFO-NODE, so record this fact in the bookmark's entry."
   (let ((the-record
          `((filename . ,(bookmark-buffer-file-name))
-           (front-context-string
-            . ,(if (>= (- (point-max) (point)) bookmark-search-size)
-                   (buffer-substring-no-properties
-                    (point)
-                    (+ (point) bookmark-search-size))
-                   nil))
-           (rear-context-string
-            . ,(if (>= (- (point) (point-min)) bookmark-search-size)
-                   (buffer-substring-no-properties
-                    (point)
-                    (- (point) bookmark-search-size))
-                   nil))
-           (position . ,(point)))))
+          ,(if (bookmark-doc-view-p)
+               ;; For doc-view buffers only the page is of interest.
+               `(doc-view-page . ,doc-view-current-page)
+             `(front-context-string
+               . ,(if (>= (- (point-max) (point)) bookmark-search-size)
+                      (buffer-substring-no-properties
+                       (point)
+                       (+ (point) bookmark-search-size))
+                    nil))
+             `(rear-context-string
+               . ,(if (>= (- (point) (point-min)) bookmark-search-size)
+                      (buffer-substring-no-properties
+                       (point)
+                       (- (point) bookmark-search-size))
+                    nil))
+             `(position . ,(point))))))
 
     ;; Now fill in the optional parts:
 
@@ -1068,10 +1071,9 @@
   (unless bookmark
     (error "No bookmark specified"))
   (bookmark-maybe-historicize-string bookmark)
-  (let ((cell (bookmark-jump-noselect bookmark)))
-    (and cell
-         (switch-to-buffer (car cell))
-         (goto-char (cdr cell))
+  (let ((buf (bookmark-jump-noselect bookmark)))
+    (and buf
+         (switch-to-buffer buf)
         (progn (run-hooks 'bookmark-after-jump-hook) t)
         (if bookmark-automatically-show-annotations
              ;; if there is an annotation for this bookmark,
@@ -1090,10 +1092,9 @@
          (list bkm) bkm)))
   (when bookmark
     (bookmark-maybe-historicize-string bookmark)
-    (let ((cell (bookmark-jump-noselect bookmark)))
-      (and cell
-           (switch-to-buffer-other-window (car cell))
-           (goto-char (cdr cell))
+    (let ((buf (bookmark-jump-noselect bookmark)))
+      (and buf
+           (switch-to-buffer-other-window buf)
            (if bookmark-automatically-show-annotations
                ;; if there is an annotation for this bookmark,
                ;; show it in a buffer.
@@ -1123,12 +1124,13 @@
 
 (defun bookmark-jump-noselect (str)
   ;; a leetle helper for bookmark-jump :-)
-  ;; returns (BUFFER . POINT)
+  ;; returns the BUFFER showing the bookmark
   (bookmark-maybe-load-default-file)
   (let* ((file (expand-file-name (bookmark-get-filename str)))
          (forward-str            (bookmark-get-front-context-string str))
          (behind-str             (bookmark-get-rear-context-string str))
          (place                  (bookmark-get-position str))
+        (doc-view-page          (bookmark-get-doc-view-page str))
          (info-node              (bookmark-get-info-node str))
          (orig-file              file)
          )
@@ -1143,7 +1145,15 @@
                    (Info-find-node file info-node)))
               ;; Else no Info.  Can do an ordinary find-file:
               (set-buffer (find-file-noselect file))
-              (goto-char place))
+             (if (not doc-view-page)
+                 ;; ordinary text file
+                 (goto-char place)
+               ;; a document that should be viewed with doc-view
+               (when (not (eq major-mode 'doc-view-mode))
+                 ;; d-v-m's not activated, so we're probably in ps-mode and
+                 ;; need to toggle display.
+                 (doc-view-toggle-display))
+               (doc-view-goto-page doc-view-page)))
 
             ;; Go searching forward first.  Then, if forward-str exists and
             ;; was found in the file, we can search backward for behind-str.
@@ -1158,7 +1168,7 @@
                     (goto-char (match-end 0))))
             ;; added by db
             (setq bookmark-current-bookmark str)
-            (cons (current-buffer) (point))))
+            (current-buffer)))
 
       ;; Else unable to find the marked file, so ask if user wants to
       ;; relocate the bookmark, else remind them to consider deletion.
@@ -1173,7 +1183,7 @@
             (bookmark-jump-noselect str))
         (message
          "Bookmark not relocated; consider removing it \(%s\)." str)
-        nil))))
+       nil))))
 
 
 ;;;###autoload
@@ -1275,7 +1285,7 @@
   (let ((orig-point (point))
         (str-to-insert
          (save-excursion
-           (set-buffer (car (bookmark-jump-noselect bookmark)))
+           (set-buffer (bookmark-jump-noselect bookmark))
            (buffer-string))))
     (insert str-to-insert)
     (push-mark)
@@ -1904,11 +1914,7 @@
             (pop-up-windows t))
         (delete-other-windows)
         (switch-to-buffer (other-buffer))
-       (let* ((pair (bookmark-jump-noselect bmrk))
-               (buff (car pair))
-               (pos  (cdr pair)))
-          (pop-to-buffer buff)
-          (goto-char pos))
+       (pop-to-buffer (bookmark-jump-noselect bmrk))
         (bury-buffer menu))))
 
 
@@ -1923,14 +1929,9 @@
   "Select this line's bookmark in other window, leaving bookmark menu visible."
   (interactive)
   (let ((bookmark (bookmark-bmenu-bookmark)))
-    (if (bookmark-bmenu-check-position)
-       (let* ((pair (bookmark-jump-noselect bookmark))
-               (buff (car pair))
-               (pos  (cdr pair)))
-         (switch-to-buffer-other-window buff)
-          (goto-char pos)
-          (set-window-point (get-buffer-window buff) pos)
-         (bookmark-show-annotation bookmark)))))
+    (when (bookmark-bmenu-check-position)
+      (switch-to-buffer-other-window (bookmark-jump-noselect bookmark))
+      (bookmark-show-annotation bookmark))))
 
 
 (defun bookmark-bmenu-switch-other-window ()
@@ -1941,18 +1942,9 @@
         (pop-up-windows t)
         same-window-buffer-names
         same-window-regexps)
-    (if (bookmark-bmenu-check-position)
-       (let* ((pair (bookmark-jump-noselect bookmark))
-               (buff (car pair))
-               (pos  (cdr pair)))
-         (display-buffer buff)
-          (let ((o-buffer (current-buffer)))
-            ;; save-excursion won't do
-            (set-buffer buff)
-            (goto-char pos)
-            (set-window-point (get-buffer-window buff) pos)
-            (set-buffer o-buffer))
-         (bookmark-show-annotation bookmark)))))
+    (when (bookmark-bmenu-check-position)
+      (display-buffer (bookmark-jump-noselect bookmark))
+      (bookmark-show-annotation bookmark))))
 
 (defun bookmark-bmenu-other-window-with-mouse (event)
   "Select bookmark at the mouse pointer in other window, leaving bookmark menu 
visible."
@@ -2107,6 +2099,27 @@
         (goto-char thispoint))))
 
 
+
+;;; Doc-view support functions
+
+(defun bookmark-doc-view-p ()
+  "Return non-nil if the current buffer in which the bookmark
+should be set uses `doc-view-mode'."
+  (eq major-mode 'doc-view-mode))
+
+(defun bookmark-get-doc-view-page (bookmark)
+  "Return the page \(i.e.: doc-view-page\) of BOOKMARK."
+  (cdr (assq 'doc-view-page (bookmark-get-bookmark-record bookmark))))
+
+(defun bookmark-set-doc-view-page (bookmark page)
+  "Set the page \(i.e.: doc-view-page\) of BOOKMARK to PAGE."
+  (let ((cell (assq 'doc-view-page (bookmark-get-bookmark-record bookmark))))
+    (if cell
+        (setcdr cell page)
+      (nconc (bookmark-get-bookmark-record bookmark)
+             (list (cons 'doc-view-page page))))))
+
+
 ;;; Menu bar stuff.  Prefix is "bookmark-menu".
 
 (defun bookmark-menu-popup-paned-menu (event name entries)
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]