aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2007-11-10 21:53:47 +0000
committerJuri Linkov2007-11-10 21:53:47 +0000
commit7baca0fa6ea9fd696475acb605be6abb41c7daa5 (patch)
treef9942bbedc533f55407168faca9034010f7fe2a4
parent59b5d020e4b85357da050a7242e8690f1b18740b (diff)
downloademacs-7baca0fa6ea9fd696475acb605be6abb41c7daa5.tar.gz
emacs-7baca0fa6ea9fd696475acb605be6abb41c7daa5.zip
(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.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/doc-view.el183
2 files changed, 113 insertions, 80 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ec6c084dd77..1b8ea95301d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12007-11-10 Tassilo Horn <tassilo@member.fsf.org>
2
3 * doc-view.el (doc-view-mode-map, doc-view-menu)
4 (doc-view-pdf->txt-sentinel): Adapt to new search UI.
5 (doc-view-search-backward): New function.
6 (doc-view-search): Query new regexp if prefix arg is given, else
7 jump to next/previous match.
8 (doc-view-mode): Handle compressed files.
9 (jka-compr): Required for compressed files.
10
12007-11-10 Paul Pogonyshev <pogonyshev@gmx.net> 112007-11-10 Paul Pogonyshev <pogonyshev@gmx.net>
2 12
3 * replace.el (query-replace-show-replacement): New defcustom. 13 * replace.el (query-replace-show-replacement): New defcustom.
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index a03b2e16785..89f1b009f7f 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -71,14 +71,14 @@
71;; You can also search within the document. The command `doc-view-search' 71;; You can also search within the document. The command `doc-view-search'
72;; (bound to `C-s') queries for a search regexp and initializes a list of all 72;; (bound to `C-s') queries for a search regexp and initializes a list of all
73;; matching pages and messages how many match-pages were found. After that you 73;; matching pages and messages how many match-pages were found. After that you
74;; can jump to the next page containing a match with 74;; can jump to the next page containing a match with an additional `C-s'. With
75;; `doc-view-search-next-match' (bound to `C-S-n') or to the previous matching 75;; `C-r' you can do the same, but backwards. To search for a new regexp give a
76;; page with `doc-view-search-previous-match' (bound to `C-S-p'). This works 76;; prefix arg to one of the search functions, e.g. by typing `C-u C-s'. The
77;; by searching a plain text representation of the document. If that doesn't 77;; searching works by using a plain text representation of the document. If
78;; already exist the first invokation of `doc-view-search' starts the 78;; that doesn't already exist the first invokation of `doc-view-search' (or
79;; conversion. When that finishes and you're still viewing the document 79;; `doc-view-search-backward') starts the conversion. When that finishes and
80;; (i.e. you didn't switch to another buffer) you're queried for the regexp 80;; you're still viewing the document (i.e. you didn't switch to another buffer)
81;; then. 81;; you're queried for the regexp then.
82;; 82;;
83;; Dired users can simply hit `v' on a document file. If it's a PS, PDF or DVI 83;; Dired users can simply hit `v' on a document file. If it's a PS, PDF or DVI
84;; it will be opened using `doc-view-mode'. 84;; it will be opened using `doc-view-mode'.
@@ -109,6 +109,7 @@
109 109
110(require 'dired) 110(require 'dired)
111(require 'image-mode) 111(require 'image-mode)
112(require 'jka-compr)
112 113
113;;;; Customization Options 114;;;; Customization Options
114 115
@@ -239,8 +240,7 @@ has finished."
239 ;; Searching 240 ;; Searching
240 (define-key map (kbd "C-s") 'doc-view-search) 241 (define-key map (kbd "C-s") 'doc-view-search)
241 (define-key map (kbd "<find>") 'doc-view-search) 242 (define-key map (kbd "<find>") 'doc-view-search)
242 (define-key map (kbd "C-S-n") 'doc-view-search-next-match) 243 (define-key map (kbd "C-r") 'doc-view-search-backward)
243 (define-key map (kbd "C-S-p") 'doc-view-search-previous-match)
244 ;; Scrolling 244 ;; Scrolling
245 (define-key map [remap forward-char] 'image-forward-hscroll) 245 (define-key map [remap forward-char] 'image-forward-hscroll)
246 (define-key map [remap backward-char] 'image-backward-hscroll) 246 (define-key map [remap backward-char] 'image-backward-hscroll)
@@ -264,6 +264,7 @@ has finished."
264 ["Reset Slice" doc-view-reset-slice] 264 ["Reset Slice" doc-view-reset-slice]
265 "---" 265 "---"
266 ["Search" doc-view-search] 266 ["Search" doc-view-search]
267 ["Search Backwards" doc-view-search-backward]
267 ["Toggle display" doc-view-toggle-display] 268 ["Toggle display" doc-view-toggle-display]
268 )) 269 ))
269 270
@@ -502,7 +503,7 @@ Should be invoked when the cached images aren't up-to-date."
502 ;; If the user looks at the DocView buffer where the conversion was 503 ;; If the user looks at the DocView buffer where the conversion was
503 ;; performed, search anew. This time it will be queried for a regexp. 504 ;; performed, search anew. This time it will be queried for a regexp.
504 (when (eq current-buffer proc-buffer) 505 (when (eq current-buffer proc-buffer)
505 (doc-view-search))))) 506 (doc-view-search nil)))))
506 507
507(defun doc-view-pdf->txt (pdf txt) 508(defun doc-view-pdf->txt (pdf txt)
508 "Convert PDF to TXT asynchronously." 509 "Convert PDF to TXT asynchronously."
@@ -733,46 +734,57 @@ the pagenumber and CONTEXTS are all lines of text containing a match."
733 (setq no (+ no (1- (length p))))) 734 (setq no (+ no (1- (length p)))))
734 no)) 735 no))
735 736
736(defun doc-view-search () 737(defun doc-view-search-backward (new-query)
737 "Query for a regexp and search the current document. 738 "Call `doc-view-search' for backward search.
739If prefix NEW-QUERY is given, ask for a new regexp."
740 (interactive "P")
741 (doc-view-search arg t))
742
743(defun doc-view-search (new-query &optional backward)
744 "Jump to the next match or initiate a new search if NEW-QUERY is given.
738If the current document hasn't been transformed to plain text 745If the current document hasn't been transformed to plain text
739till now do that first. You should try searching anew when the 746till now do that first.
740conversion finished." 747If BACKWARD is non-nil, jump to the previous match."
741 (interactive) 748 (interactive "P")
742 ;; New search, so forget the old results. 749 (if (and (not arg)
743 (setq doc-view-current-search-matches nil) 750 doc-view-current-search-matches)
744 (let ((txt (expand-file-name "doc.txt" 751 (if backward
745 (doc-view-current-cache-dir)))) 752 (doc-view-search-previous-match 1)
746 (if (file-readable-p txt) 753 (doc-view-search-next-match 1))
747 (progn 754 ;; New search, so forget the old results.
748 (setq doc-view-current-search-matches 755 (setq doc-view-current-search-matches nil)
749 (doc-view-search-internal 756 (let ((txt (expand-file-name "doc.txt"
750 (read-from-minibuffer "Regexp: ") 757 (doc-view-current-cache-dir))))
751 txt)) 758 (if (file-readable-p txt)
752 (message "DocView: search yielded %d matches." 759 (progn
753 (doc-view-search-no-of-matches 760 (setq doc-view-current-search-matches
754 doc-view-current-search-matches))) 761 (doc-view-search-internal
755 ;; We must convert to TXT first! 762 (read-from-minibuffer "Regexp: ")
756 (if doc-view-current-converter-process 763 txt))
757 (message "DocView: please wait till conversion finished.") 764 (message "DocView: search yielded %d matches."
758 (let ((ext (file-name-extension buffer-file-name))) 765 (doc-view-search-no-of-matches
759 (cond 766 doc-view-current-search-matches)))
760 ((string= ext "pdf") 767 ;; We must convert to TXT first!
761 ;; Doc is a PDF, so convert it to TXT 768 (if doc-view-current-converter-process
762 (doc-view-pdf->txt buffer-file-name txt)) 769 (message "DocView: please wait till conversion finished.")
763 ((string= ext "ps") 770 (let ((ext (file-name-extension buffer-file-name)))
764 ;; Doc is a PS, so convert it to PDF (which will be converted to 771 (cond
765 ;; TXT thereafter). 772 ((string= ext "pdf")
766 (doc-view-ps->pdf buffer-file-name 773 ;; Doc is a PDF, so convert it to TXT
767 (expand-file-name "doc.pdf" 774 (doc-view-pdf->txt buffer-file-name txt))
768 (doc-view-current-cache-dir)))) 775 ((string= ext "ps")
769 ((string= ext "dvi") 776 ;; Doc is a PS, so convert it to PDF (which will be converted to
770 ;; Doc is a DVI. This means that a doc.pdf already exists in its 777 ;; TXT thereafter).
771 ;; cache subdirectory. 778 (doc-view-ps->pdf buffer-file-name
772 (doc-view-pdf->txt (expand-file-name "doc.pdf" 779 (expand-file-name "doc.pdf"
773 (doc-view-current-cache-dir)) 780 (doc-view-current-cache-dir))))
774 txt)) 781 ((string= ext "dvi")
775 (t (error "DocView doesn't know what to do")))))))) 782 ;; Doc is a DVI. This means that a doc.pdf already exists in its
783 ;; cache subdirectory.
784 (doc-view-pdf->txt (expand-file-name "doc.pdf"
785 (doc-view-current-cache-dir))
786 txt))
787 (t (error "DocView doesn't know what to do")))))))))
776 788
777(defun doc-view-search-next-match (arg) 789(defun doc-view-search-next-match (arg)
778 "Go to the ARGth next matching page." 790 "Go to the ARGth next matching page."
@@ -835,36 +847,47 @@ conversion finished."
835You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to 847You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
836toggle between displaying the document or editing it as text." 848toggle between displaying the document or editing it as text."
837 (interactive) 849 (interactive)
838 (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode) 850 (if jka-compr-really-do-compress
839 doc-view-previous-major-mode 851 ;; This is a compressed file uncompressed by auto-compression-mode.
840 major-mode))) 852 (when (y-or-n-p (concat "DocView: Cannot convert compressed file. "
841 (kill-all-local-variables) 853 "Save it uncompressed first? "))
842 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) 854 (let ((file (read-file-name
843 (make-local-variable 'doc-view-current-files) 855 "File: "
844 (make-local-variable 'doc-view-current-image) 856 (file-name-directory buffer-file-name))))
845 (make-local-variable 'doc-view-current-page) 857 (write-region (point-min) (point-max) file)
846 (make-local-variable 'doc-view-current-converter-process) 858 (kill-buffer nil)
847 (make-local-variable 'doc-view-current-timer) 859 (find-file file)
848 (make-local-variable 'doc-view-current-slice) 860 (doc-view-mode)))
849 (make-local-variable 'doc-view-current-cache-dir) 861 (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
850 (make-local-variable 'doc-view-current-info) 862 doc-view-previous-major-mode
851 (make-local-variable 'doc-view-current-search-matches) 863 major-mode)))
852 (set (make-local-variable 'doc-view-current-overlay) 864 (kill-all-local-variables)
853 (make-overlay (point-min) (point-max) nil t)) 865 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
854 (add-hook 'change-major-mode-hook 866 (make-local-variable 'doc-view-current-files)
855 (lambda () (delete-overlay doc-view-current-overlay)) 867 (make-local-variable 'doc-view-current-image)
856 nil t) 868 (make-local-variable 'doc-view-current-page)
857 (set (make-local-variable 'mode-line-position) 869 (make-local-variable 'doc-view-current-converter-process)
858 '(" P" (:eval (number-to-string doc-view-current-page)) 870 (make-local-variable 'doc-view-current-timer)
859 "/" (:eval (number-to-string (length doc-view-current-files))))) 871 (make-local-variable 'doc-view-current-slice)
860 (set (make-local-variable 'cursor-type) nil) 872 (make-local-variable 'doc-view-current-cache-dir)
861 (use-local-map doc-view-mode-map) 873 (make-local-variable 'doc-view-current-info)
862 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc) 874 (make-local-variable 'doc-view-current-search-matches)
863 (setq mode-name "DocView" 875 (set (make-local-variable 'doc-view-current-overlay)
864 buffer-read-only t 876 (make-overlay (point-min) (point-max) nil t))
865 major-mode 'doc-view-mode) 877 (add-hook 'change-major-mode-hook
866 (doc-view-initiate-display) 878 (lambda () (delete-overlay doc-view-current-overlay))
867 (run-mode-hooks 'doc-view-mode-hook)) 879 nil t)
880 (set (make-local-variable 'mode-line-position)
881 '(" P" (:eval (number-to-string doc-view-current-page))
882 "/" (:eval (number-to-string (length doc-view-current-files)))))
883 (set (make-local-variable 'cursor-type) nil)
884 (use-local-map doc-view-mode-map)
885 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
886 (setq mode-name "DocView"
887 buffer-read-only t
888 major-mode 'doc-view-mode)
889 (doc-view-initiate-display)
890 (run-mode-hooks 'doc-view-mode-hook)))
868 891
869;;;###autoload 892;;;###autoload
870(define-minor-mode doc-view-minor-mode 893(define-minor-mode doc-view-minor-mode