GNU bug report logs - #16090
24.3.50; [PATCH] error when jumping to a doc-view bookmark

Previous Next

Package: emacs;

Reported by: Andreas Politz <politza <at> hochschule-trier.de>

Date: Sun, 8 Dec 2013 16:56:01 UTC

Severity: normal

Tags: patch

Found in version 24.3.50

Done: Tassilo Horn <tsdh <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Tassilo Horn <tsdh <at> gnu.org>
To: Andreas Politz <politza <at> hochschule-trier.de>
Cc: 16090 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#16090: 24.3.50; [PATCH] error when jumping to a doc-view bookmark
Date: Fri, 20 Dec 2013 14:02:58 +0100
Andreas Politz <politza <at> hochschule-trier.de> writes:

> Do you acknowledge and have an opinion on the cached vs. non-cached
> behaviour I did mention earlier ?

No, I haven't looked into the differences yet.  But I think I've come up
with a quite good solution for the general problem right now.  The patch
below allows bookmark handlers to return a function that accepts the
window showing the buffer and then may act on it.  When the
display-function has been run, that function is called and in the
doc-view case sets the page for that window.

Until now, return values of handlers where simply ignored.  It shouldn't
break existing handlers, except if there's some handler that does
something like

  (setq dunno (lambda (...) ...))

or

  (add-hook 'dunno-hook (lambda (...) ...))

as last expression which seems unlikely.  I've grepped the emacs source
code and at least all handlers in there (man, woman, image-mode, gnus,
help, Info) don't do so.

I've tested it with bookmarks to docs that had to be converted anew and
bookmarks to docs that were already cached, and it seems to DTRT in all
cases.

--8<---------------cut here---------------start------------->8---
=== modified file 'lisp/bookmark.el'
--- lisp/bookmark.el	2013-09-11 03:31:56 +0000
+++ lisp/bookmark.el	2013-12-20 13:01:29 +0000
@@ -997,12 +997,18 @@
 
 After calling DISPLAY-FUNCTION, set window point to the point specified
 by BOOKMARK-NAME-OR-RECORD, if necessary, run `bookmark-after-jump-hook',
-and then show any annotations for this bookmark."
-  (bookmark-handle-bookmark bookmark-name-or-record)
+and then show any annotations for this bookmark.
+
+If the handler returns a function, this function will be called
+with the window showing the bookmark buffer."
+  (let ((win-fn (bookmark-handle-bookmark bookmark-name-or-record)))
   (save-current-buffer
     (funcall display-function (current-buffer)))
   (let ((win (get-buffer-window (current-buffer) 0)))
-    (if win (set-window-point win (point))))
+      (when win
+	(set-window-point win (point))
+	(when (functionp win-fn)
+	  (funcall win-fn win)))))
   ;; FIXME: we used to only run bookmark-after-jump-hook in
   ;; `bookmark-jump' itself, but in none of the other commands.
   (run-hooks 'bookmark-after-jump-hook)
@@ -1061,13 +1067,16 @@
     (cons (current-buffer) (point))))
 
 (defun bookmark-handle-bookmark (bookmark-name-or-record)
-  "Call BOOKMARK-NAME-OR-RECORD's handler or `bookmark-default-handler'
-if it has none.  This changes current buffer and point and returns nil,
-or signals a `file-error'.
+  "Call BOOKMARK-NAME-OR-RECORD's handler or
+`bookmark-default-handler' if it has none.  This changes current
+buffer and point, or signals a `file-error'.  The handler may
+return a function with one argument, a window.  This function
+will be called with the window showing the bookmark's buffer.
 
 If BOOKMARK-NAME-OR-RECORD has no file, this is a no-op.  If
 BOOKMARK-NAME-OR-RECORD has a file, but that file no longer exists,
 then offer interactively to relocate BOOKMARK-NAME-OR-RECORD."
+  (prog1
   (condition-case err
       (funcall (or (bookmark-get-handler bookmark-name-or-record)
                    'bookmark-default-handler)
@@ -1106,8 +1115,7 @@
                  (signal (car err) (cdr err))))))))))
   ;; Added by db.
   (when (stringp bookmark-name-or-record)
-    (setq bookmark-current-bookmark bookmark-name-or-record))
-  nil)
+      (setq bookmark-current-bookmark bookmark-name-or-record))))
 
 (define-error 'bookmark-errors nil)
 (define-error 'bookmark-error-no-filename

=== modified file 'lisp/doc-view.el'
--- lisp/doc-view.el	2013-11-28 22:43:09 +0000
+++ lisp/doc-view.el	2013-12-20 12:30:55 +0000
@@ -1866,13 +1866,12 @@
 (defun doc-view-bookmark-jump (bmk)
   ;; This implements the `handler' function interface for record type
   ;; returned by `doc-view-bookmark-make-record', which see.
-  (prog1 (bookmark-default-handler bmk)
+  (bookmark-default-handler bmk)
     (let ((page (bookmark-prop-get bmk 'page)))
+    (lambda (win)
       (when (not (eq major-mode 'doc-view-mode))
         (doc-view-toggle-display))
-      (with-selected-window
-       (or (get-buffer-window (current-buffer) 0)
-	   (selected-window))
+      (with-selected-window win
        (doc-view-goto-page page)))))
--8<---------------cut here---------------end--------------->8---

Good to commit?

Bye,
Tassilo




This bug report was last modified 11 years and 51 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.