From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-devel@gnu.org
Subject: doc-view support for bookmark.el
Date: Tue, 25 Dec 2007 11:54:00 +0100 [thread overview]
Message-ID: <8763yn3v07.fsf@member.fsf.org> (raw)
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 <tassilo@member.fsf.org>
* 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))))
\f
+
+;;; 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
next reply other threads:[~2007-12-25 10:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-25 10:54 Tassilo Horn [this message]
2007-12-25 11:43 ` doc-view support for bookmark.el Stefan Monnier
2007-12-25 14:42 ` Tassilo Horn
2007-12-25 17:32 ` Stefan Monnier
2007-12-25 19:00 ` Tassilo Horn
2007-12-25 22:00 ` Tassilo Horn
2007-12-25 22:05 ` Nick Roberts
2007-12-25 22:25 ` Tassilo Horn
2007-12-25 23:07 ` Stefan Monnier
2007-12-26 8:22 ` Tassilo Horn
2007-12-26 11:52 ` bookmark support for doc-view and image-mode (was: doc-view support for bookmark.el) Tassilo Horn
2007-12-26 18:53 ` doc-view support for bookmark.el Karl Fogel
2007-12-26 17:08 ` Drew Adams
2007-12-26 20:21 ` Karl Fogel
2007-12-27 9:21 ` Tassilo Horn
2007-12-27 15:34 ` Drew Adams
2007-12-28 9:10 ` Karl Fogel
2007-12-28 23:44 ` Kim F. Storm
2007-12-29 7:40 ` Karl Fogel
2007-12-29 7:43 ` Stefan Monnier
2007-12-30 0:34 ` Kim F. Storm
2008-01-02 2:18 ` Stefan Monnier
2008-01-02 9:43 ` Kim F. Storm
2008-01-02 20:22 ` Stefan Monnier
2007-12-25 17:24 ` Drew Adams
2007-12-25 17:54 ` martin rudalics
2007-12-25 18:43 ` Tassilo Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8763yn3v07.fsf@member.fsf.org \
--to=tassilo@member.fsf.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.