all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-devel@gnu.org
Subject: Re: isearch for doc-view.el
Date: Mon, 05 Nov 2007 22:01:10 +0100	[thread overview]
Message-ID: <87fxzk4dbd.fsf@baldur.tsdh.de> (raw)
In-Reply-To: <jwvr6j4hgw7.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 05 Nov 2007 10:14:21 -0500")

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Don't know.  It seems to work more or less here.

After spending quite some time to make isearch working I have given up.
It seems to be rather complicated, so I only changed the current search
facility to use an isearch-like UI.  Now you hit C-s and enter the
regexp and each additional C-s or C-r jumps to the next/previous match.
To enter a new regexp, you have to provide a prefix arg to C-s or C-r.

Then I tried fixing the auto-compression-mode bug Reiner poined out in
<v9640nx9n9.fsf@marauder.physik.uni-ulm.de>.  Because I could not find
an elegant solution to work with compressed files transparently I took a
trivial approach:  doc-view-mode now offers to save the uncompressed
file somewhere and then this file is viewed.

Here's the ChangeLog entry:

--8<---------------cut here---------------start------------->8---
2007-11-05  Tassilo Horn  <tassilo@member.fsf.org>

	* doc-view.el (doc-view-mode-map, doc-view-menu)
	(doc-view-pdf->txt-sentinel): Adapt to new search UI.
	(doc-view-search-backward): New function.
	(doc-view-search): Query new regexp if prefix arg is given, else
	jump to next/previous match.
	(doc-view-mode): Handle compressed files.
--8<---------------cut here---------------end--------------->8---

And here's the patch:

--8<---------------cut here---------------start------------->8---
Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.18
diff -u -r1.18 doc-view.el
--- lisp/doc-view.el	1 Nov 2007 03:53:32 -0000	1.18
+++ lisp/doc-view.el	5 Nov 2007 21:00:08 -0000
@@ -71,14 +71,14 @@
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
-;; can jump to the next page containing a match with
-;; `doc-view-search-next-match' (bound to `C-S-n') or to the previous matching
-;; page with `doc-view-search-previous-match' (bound to `C-S-p').  This works
-;; by searching a plain text representation of the document.  If that doesn't
-;; already exist the first invokation of `doc-view-search' starts the
-;; conversion.  When that finishes and you're still viewing the document
-;; (i.e. you didn't switch to another buffer) you're queried for the regexp
-;; then.
+;; can jump to the next page containing a match with an additional `C-s'.  With
+;; `C-r' you can do the same, but backwards.  To search for a new regexp give a
+;; prefix arg to one of the search functions, e.g. by typing `C-u C-s'.  The
+;; searching works by using a plain text representation of the document.  If
+;; that doesn't already exist the first invokation of `doc-view-search' (or
+;; `doc-view-search-backward') starts the conversion.  When that finishes and
+;; you're still viewing the document (i.e. you didn't switch to another buffer)
+;; you're queried for the regexp then.
 ;;
 ;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
 ;; it will be opened using `doc-view-mode'.
@@ -239,8 +239,7 @@
     ;; Searching
     (define-key map (kbd "C-s")       'doc-view-search)
     (define-key map (kbd "<find>")    'doc-view-search)
-    (define-key map (kbd "C-S-n")     'doc-view-search-next-match)
-    (define-key map (kbd "C-S-p")     'doc-view-search-previous-match)
+    (define-key map (kbd "C-r")       'doc-view-search-backward)
     ;; Scrolling
     (define-key map [remap forward-char]  'image-forward-hscroll)
     (define-key map [remap backward-char] 'image-backward-hscroll)
@@ -264,6 +263,7 @@
     ["Reset Slice"		doc-view-reset-slice]
     "---"
     ["Search"			doc-view-search]
+    ["Search Backwards"         doc-view-search-backward]
     ["Toggle display"		doc-view-toggle-display]
     ))
 
@@ -502,7 +502,7 @@
       ;; If the user looks at the DocView buffer where the conversion was
       ;; performed, search anew.  This time it will be queried for a regexp.
       (when (eq current-buffer proc-buffer)
-	(doc-view-search)))))
+	(doc-view-search nil)))))
 
 (defun doc-view-pdf->txt (pdf txt)
   "Convert PDF to TXT asynchronously."
@@ -733,46 +733,56 @@
       (setq no (+ no (1- (length p)))))
     no))
 
-(defun doc-view-search ()
+(defun doc-view-search-backward (arg)
+  "Call `doc-view-search' for backward search."
+  (interactive "P")
+  (doc-view-search arg t))
+
+(defun doc-view-search (arg &optional backward)
   "Query for a regexp and search the current document.
 If the current document hasn't been transformed to plain text
 till now do that first.  You should try searching anew when the
 conversion finished."
-  (interactive)
-  ;; New search, so forget the old results.
-  (setq doc-view-current-search-matches nil)
-  (let ((txt (expand-file-name "doc.txt"
-                               (doc-view-current-cache-dir))))
-    (if (file-readable-p txt)
-	(progn
-	  (setq doc-view-current-search-matches
-		(doc-view-search-internal
-		 (read-from-minibuffer "Regexp: ")
-		 txt))
-	  (message "DocView: search yielded %d matches."
-		   (doc-view-search-no-of-matches
-		    doc-view-current-search-matches)))
-      ;; We must convert to TXT first!
-      (if doc-view-current-converter-process
-	  (message "DocView: please wait till conversion finished.")
-	(let ((ext (file-name-extension buffer-file-name)))
-	  (cond
-	   ((string= ext "pdf")
-	    ;; Doc is a PDF, so convert it to TXT
-	    (doc-view-pdf->txt buffer-file-name txt))
-	   ((string= ext "ps")
-	    ;; Doc is a PS, so convert it to PDF (which will be converted to
-	    ;; TXT thereafter).
-	    (doc-view-ps->pdf buffer-file-name
-			      (expand-file-name "doc.pdf"
-                                                (doc-view-current-cache-dir))))
-	   ((string= ext "dvi")
-	    ;; Doc is a DVI.  This means that a doc.pdf already exists in its
-	    ;; cache subdirectory.
-	    (doc-view-pdf->txt (expand-file-name "doc.pdf"
-                                                 (doc-view-current-cache-dir))
-			       txt))
-	   (t (error "DocView doesn't know what to do"))))))))
+  (interactive "P")
+  (if (and (not arg)
+	   doc-view-current-search-matches)
+      (if backward
+	  (doc-view-search-previous-match 1)
+	(doc-view-search-next-match 1))
+    ;; New search, so forget the old results.
+    (setq doc-view-current-search-matches nil)
+    (let ((txt (expand-file-name "doc.txt"
+				 (doc-view-current-cache-dir))))
+      (if (file-readable-p txt)
+	  (progn
+	    (setq doc-view-current-search-matches
+		  (doc-view-search-internal
+		   (read-from-minibuffer "Regexp: ")
+		   txt))
+	    (message "DocView: search yielded %d matches."
+		     (doc-view-search-no-of-matches
+		      doc-view-current-search-matches)))
+	;; We must convert to TXT first!
+	(if doc-view-current-converter-process
+	    (message "DocView: please wait till conversion finished.")
+	  (let ((ext (file-name-extension buffer-file-name)))
+	    (cond
+	     ((string= ext "pdf")
+	      ;; Doc is a PDF, so convert it to TXT
+	      (doc-view-pdf->txt buffer-file-name txt))
+	     ((string= ext "ps")
+	      ;; Doc is a PS, so convert it to PDF (which will be converted to
+	      ;; TXT thereafter).
+	      (doc-view-ps->pdf buffer-file-name
+				(expand-file-name "doc.pdf"
+						  (doc-view-current-cache-dir))))
+	     ((string= ext "dvi")
+	      ;; Doc is a DVI.  This means that a doc.pdf already exists in its
+	      ;; cache subdirectory.
+	      (doc-view-pdf->txt (expand-file-name "doc.pdf"
+						   (doc-view-current-cache-dir))
+				 txt))
+	     (t (error "DocView doesn't know what to do")))))))))
 
 (defun doc-view-search-next-match (arg)
   "Go to the ARGth next matching page."
@@ -835,36 +845,47 @@
 You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
 toggle between displaying the document or editing it as text."
   (interactive)
-  (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
-			      doc-view-previous-major-mode
-			    major-mode)))
-    (kill-all-local-variables)
-    (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
-  (make-local-variable 'doc-view-current-files)
-  (make-local-variable 'doc-view-current-image)
-  (make-local-variable 'doc-view-current-page)
-  (make-local-variable 'doc-view-current-converter-process)
-  (make-local-variable 'doc-view-current-timer)
-  (make-local-variable 'doc-view-current-slice)
-  (make-local-variable 'doc-view-current-cache-dir)
-  (make-local-variable 'doc-view-current-info)
-  (make-local-variable 'doc-view-current-search-matches)
-  (set (make-local-variable 'doc-view-current-overlay)
-       (make-overlay (point-min) (point-max) nil t))
-  (add-hook 'change-major-mode-hook
-            (lambda () (delete-overlay doc-view-current-overlay))
-            nil t)
-  (set (make-local-variable 'mode-line-position)
-       '(" P" (:eval (number-to-string doc-view-current-page))
-         "/" (:eval (number-to-string (length doc-view-current-files)))))
-  (set (make-local-variable 'cursor-type) nil)
-  (use-local-map doc-view-mode-map)
-  (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
-  (setq mode-name "DocView"
-	buffer-read-only t
-	major-mode 'doc-view-mode)
-  (doc-view-initiate-display)
-  (run-mode-hooks 'doc-view-mode-hook))
+  (if jka-compr-really-do-compress
+      ;; This is a compressed file uncompressed by auto-compression-mode.
+      (when (y-or-n-p (concat "DocView: Cannot convert compressed file.  "
+			      "Save it uncompressed first? "))
+	(let ((file (read-file-name
+		     "File: "
+		     (file-name-directory buffer-file-name))))
+	  (write-region (point-min) (point-max) file)
+	  (kill-buffer nil)
+	  (find-file file)
+	  (doc-view-mode)))
+    (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
+				doc-view-previous-major-mode
+			      major-mode)))
+      (kill-all-local-variables)
+      (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
+    (make-local-variable 'doc-view-current-files)
+    (make-local-variable 'doc-view-current-image)
+    (make-local-variable 'doc-view-current-page)
+    (make-local-variable 'doc-view-current-converter-process)
+    (make-local-variable 'doc-view-current-timer)
+    (make-local-variable 'doc-view-current-slice)
+    (make-local-variable 'doc-view-current-cache-dir)
+    (make-local-variable 'doc-view-current-info)
+    (make-local-variable 'doc-view-current-search-matches)
+    (set (make-local-variable 'doc-view-current-overlay)
+	 (make-overlay (point-min) (point-max) nil t))
+    (add-hook 'change-major-mode-hook
+	      (lambda () (delete-overlay doc-view-current-overlay))
+	      nil t)
+    (set (make-local-variable 'mode-line-position)
+	 '(" P" (:eval (number-to-string doc-view-current-page))
+	   "/" (:eval (number-to-string (length doc-view-current-files)))))
+    (set (make-local-variable 'cursor-type) nil)
+    (use-local-map doc-view-mode-map)
+    (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
+    (setq mode-name "DocView"
+	  buffer-read-only t
+	  major-mode 'doc-view-mode)
+    (doc-view-initiate-display)
+    (run-mode-hooks 'doc-view-mode-hook)))
 
 ;;;###autoload
 (define-minor-mode doc-view-minor-mode
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo

  parent reply	other threads:[~2007-11-05 21:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-30 18:50 doc-view cache file permissions Glenn Morris
2007-10-30 20:11 ` Stefan Monnier
2007-10-30 20:57   ` Glenn Morris
2007-10-30 21:56     ` Stefan Monnier
2007-10-31  7:22       ` Tassilo Horn
2007-10-31  7:56         ` Tassilo Horn
2007-10-31 15:10           ` Stefan Monnier
2007-10-31 17:46             ` Tassilo Horn
2007-10-31 18:21               ` Stefan Monnier
2007-10-31 19:44                 ` Tassilo Horn
2007-10-31 20:41                   ` Stefan Monnier
2007-11-02 20:44                   ` Juri Linkov
2007-11-02 23:53                     ` Tassilo Horn
2007-11-03 14:07                       ` Stefan Monnier
2007-11-03 19:20                         ` Tassilo Horn
2007-11-05 12:01                         ` isearch for doc-view.el (was: doc-view cache file permissions) Tassilo Horn
2007-11-05 12:43                           ` isearch for doc-view.el David Kastrup
2007-11-05 13:19                             ` Tassilo Horn
2007-11-05 15:14                           ` Stefan Monnier
2007-11-05 16:42                             ` CEDET/senator kill the buffer-local value of isearch-search-fun-function (was: isearch for doc-view.el) Tassilo Horn
2007-11-05 21:01                             ` Tassilo Horn [this message]
2007-11-05 21:20                               ` isearch for doc-view.el Stefan Monnier
2007-11-05 21:51                                 ` Tassilo Horn
2007-11-06  0:44                                   ` Juri Linkov
2007-11-06  8:25                                     ` Tassilo Horn
2007-11-06 22:29                                       ` Juri Linkov
2007-11-07  8:41                                         ` Tassilo Horn
2007-11-10 21:57                                           ` Juri Linkov
2007-11-06  8:34                               ` Tassilo Horn
2007-10-30 22:14     ` doc-view cache file permissions Reiner Steib
2007-10-31  0:52       ` Stefan Monnier
2007-10-30 20:34 ` 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=87fxzk4dbd.fsf@baldur.tsdh.de \
    --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.