Subject: bug#16541: 23.3; doc-view-open-text should grab place in current doc

From: Suhail Shergill <[email-masked]>
Date: Sat, 25 Jan 2014 02:10:47 +0000

Stefan Monnier <[email-masked]> writes:

> Currently doc-view has pretty much no idea about the format in use, so it
> doesn't know how to go from one page to another.

except results shown by doc-view-search and doc-view-search-next-match are
associated with the correct page number as seen in docview mode (even though it
seems the search is conducted on the extracted text). so, clearly that
information is available to doc-view in some sense.

digging deeper, it seems doc-view-search-internal uses occurrences of  as page
markers. in fact, with a little bit of tinkering the following advice does the
trick: 

(defadvice doc-view-open-text (around
                               su/advice/doc-view/doc-view-open-text/around/goto-page
                               last a c pre)
  "grab the page when in doc-view mode and ensure that doc-view-open-text
   opens the correct page"
  (let ((su/dv/page (doc-view-current-page))
        (su/dv/text-buffer-name (concat "Text contents of " (buffer-name))))
    ad-do-it
    (with-current-buffer su/dv/text-buffer-name
     (re-search-forward "" nil t (1- su/dv/page))
     (recenter-top-bottom 0))))

-- 
Suhail