From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: doc-view support for bookmark.el Date: Tue, 25 Dec 2007 11:54:00 +0100 Message-ID: <8763yn3v07.fsf@member.fsf.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1198580061 30889 80.91.229.12 (25 Dec 2007 10:54:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Dec 2007 10:54:21 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 25 11:54:34 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J77Qf-0004cP-1N for ged-emacs-devel@m.gmane.org; Tue, 25 Dec 2007 11:54:33 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J77QK-0006uG-MV for ged-emacs-devel@m.gmane.org; Tue, 25 Dec 2007 05:54:12 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J77QF-0006sw-Pe for emacs-devel@gnu.org; Tue, 25 Dec 2007 05:54:07 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J77QD-0006qa-3I for emacs-devel@gnu.org; Tue, 25 Dec 2007 05:54:07 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J77QD-0006qX-0Q for emacs-devel@gnu.org; Tue, 25 Dec 2007 05:54:05 -0500 Original-Received: from out4.smtp.messagingengine.com ([66.111.4.28]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J77QC-0006Xd-Od for emacs-devel@gnu.org; Tue, 25 Dec 2007 05:54:05 -0500 Original-Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 0BC5181E71 for ; Tue, 25 Dec 2007 05:54:04 -0500 (EST) Original-Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Tue, 25 Dec 2007 05:54:04 -0500 X-Sasl-enc: sZIX/Kib7moggeT0HCjPwI5qTJiosnrtgWDqF2NBKAff 1198580043 Original-Received: from baldur (dslb-084-063-018-200.pools.arcor-ip.net [84.63.18.200]) by mail.messagingengine.com (Postfix) with ESMTP id E638517928 for ; Tue, 25 Dec 2007 05:54:02 -0500 (EST) Mail-Followup-To: emacs-devel@gnu.org User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:85442 Archived-At: 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 * 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