unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: Andreas Politz <politza@hochschule-trier.de>
Cc: 16090@debbugs.gnu.org
Subject: bug#16090: 24.3.50; [PATCH] error when jumping to a doc-view bookmark
Date: Fri, 20 Dec 2013 14:02:58 +0100	[thread overview]
Message-ID: <87lhzfd69p.fsf@thinkpad.tsdh.org> (raw)
In-Reply-To: <877gb0hqol.fsf@hochschule-trier.de> (Andreas Politz's message of "Fri, 20 Dec 2013 09:28:26 +0100")

Andreas Politz <politza@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





  reply	other threads:[~2013-12-20 13:02 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-08 16:54 bug#16090: 24.3.50; [PATCH] error when jumping to a doc-view bookmark Andreas Politz
2013-12-09  9:13 ` Tassilo Horn
2013-12-09 12:33   ` Andreas Politz
2013-12-09 14:56     ` Tassilo Horn
2013-12-09 16:55   ` Glenn Morris
2013-12-10  7:28     ` Tassilo Horn
2013-12-10  2:51 ` Stefan Monnier
2013-12-10  7:53   ` Tassilo Horn
2013-12-10 10:02     ` Andreas Politz
2013-12-10 11:58       ` Andreas Politz
2013-12-10 16:56     ` Andreas Politz
2013-12-10 20:07       ` Tassilo Horn
2013-12-10 22:16         ` Andreas Politz
2013-12-11  4:43     ` Stefan Monnier
2013-12-11 19:08       ` Tassilo Horn
2013-12-20  8:00 ` Tassilo Horn
2013-12-20  8:28   ` Andreas Politz
2013-12-20 13:02     ` Tassilo Horn [this message]
2014-04-02 14:43       ` Stefan Monnier
2014-04-04 13:43         ` Tassilo Horn
2014-04-04 15:14           ` Stefan Monnier
2014-04-04 15:53             ` Tassilo Horn
2014-04-04 16:04               ` Glenn Morris
2014-04-04 17:44                 ` Tassilo Horn
2013-12-20 14:33   ` Stefan Monnier
2013-12-20 14:36     ` 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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lhzfd69p.fsf@thinkpad.tsdh.org \
    --to=tsdh@gnu.org \
    --cc=16090@debbugs.gnu.org \
    --cc=politza@hochschule-trier.de \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).