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: Re: isearch for doc-view.el Date: Tue, 06 Nov 2007 09:34:43 +0100 Message-ID: <87640fzs9o.fsf@baldur.tsdh.de> References: <7gk5p448xq.fsf@fencepost.gnu.org> <87wst33g0o.fsf@baldur.tsdh.de> <87pryv3eew.fsf@baldur.tsdh.de> <87k5p3qisa.fsf@baldur.tsdh.de> <87ejfbqdb4.fsf@baldur.tsdh.de> <87y7dhv89p.fsf@jurta.org> <87ejf8kxwg.fsf@baldur.tsdh.de> <87sl3koq9k.fsf_-_@baldur.tsdh.de> <87fxzk4dbd.fsf@baldur.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1194338196 663 80.91.229.12 (6 Nov 2007 08:36:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 6 Nov 2007 08:36:36 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 06 09:36:39 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 1IpJvJ-000649-HR for ged-emacs-devel@m.gmane.org; Tue, 06 Nov 2007 09:36:38 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IpJv7-0005Sl-Uu for ged-emacs-devel@m.gmane.org; Tue, 06 Nov 2007 03:36:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IpJtY-000532-97 for emacs-devel@gnu.org; Tue, 06 Nov 2007 03:34:48 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IpJtX-00052f-8i for emacs-devel@gnu.org; Tue, 06 Nov 2007 03:34:47 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IpJtW-00052a-W9 for emacs-devel@gnu.org; Tue, 06 Nov 2007 03:34:47 -0500 Original-Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IpJtW-00050Z-OM for emacs-devel@gnu.org; Tue, 06 Nov 2007 03:34:46 -0500 Original-Received: from compute2.internal (compute2.internal [10.202.2.42]) by out1.messagingengine.com (Postfix) with ESMTP id 55EF245810 for ; Tue, 6 Nov 2007 03:34:46 -0500 (EST) Original-Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute2.internal (MEProxy); Tue, 06 Nov 2007 03:34:46 -0500 X-Sasl-enc: 5mr+QRTbzv/QHGnla4cDa5OgzdYL7BrBWh7gnFS1HhLZ 1194338085 Original-Received: from baldur.tsdh.de (dslb-084-063-060-089.pools.arcor-ip.net [84.63.60.89]) by mail.messagingengine.com (Postfix) with ESMTP id 3FB301431 for ; Tue, 6 Nov 2007 03:34:44 -0500 (EST) Mail-Followup-To: emacs-devel@gnu.org In-Reply-To: <87fxzk4dbd.fsf@baldur.tsdh.de> (Tassilo Horn's message of "Mon, 05 Nov 2007 22:01:10 +0100") 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:82633 Archived-At: --=-=-= Hi, there was a missing require which I didn't think about and the doc-string of doc-view-search wasn't updated. This patch fixes those problems. --8<---------------cut here---------------start------------->8--- 2007-11-06 Tassilo Horn * 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. (jka-compr): Required for compressed files. --8<---------------cut here---------------end--------------->8--- --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=doc-view.patch 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 6 Nov 2007 08:33:43 -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'. @@ -109,6 +109,7 @@ (require 'dired) (require 'image-mode) +(require 'jka-compr) ;;;; Customization Options @@ -239,8 +240,7 @@ ;; Searching (define-key map (kbd "C-s") 'doc-view-search) (define-key map (kbd "") '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 +264,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 +503,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 +734,57 @@ (setq no (+ no (1- (length p))))) no)) -(defun doc-view-search () - "Query for a regexp and search the current document. +(defun doc-view-search-backward (new-query) + "Call `doc-view-search' for backward search. +If prefix NEW-QUERY is given, ask for a new regexp." + (interactive "P") + (doc-view-search arg t)) + +(defun doc-view-search (new-query &optional backward) + "Jump to the next match or initiate a new search if NEW-QUERY is given. 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")))))))) +till now do that first. +If BACKWARD is non-nil, jump to the previous match." + (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 +847,47 @@ You can use \\\\[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 --=-=-= Bye, Tassilo --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--