aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichaël Cadilhac2007-10-03 23:28:19 +0000
committerMichaël Cadilhac2007-10-03 23:28:19 +0000
commit1ca678aaf73e776c59f2c8d462e5b4dea29ce0ef (patch)
tree299720116e9abcc329ab00f26eaba745499bd058
parenta390930c456496eda774e0f4d16e37ccc03f656c (diff)
downloademacs-1ca678aaf73e776c59f2c8d462e5b4dea29ce0ef.tar.gz
emacs-1ca678aaf73e776c59f2c8d462e5b4dea29ce0ef.zip
(doc-view): Don't ignore pdf and dvi files when completing filename.
(doc-view-search-internal): Docstring change.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/doc-view.el338
2 files changed, 177 insertions, 167 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fa2826b4ed7..21d477ffe25 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12007-10-04 Tassilo Horn <tassilo@member.fsf.org>
2
3 * doc-view.el (doc-view): Don't ignore pdf and dvi files when
4 completing filename.
5 (doc-view-search-internal): Docstring change.
6
12007-10-03 Michael Albinus <michael.albinus@gmx.de> 72007-10-03 Michael Albinus <michael.albinus@gmx.de>
2 8
3 * net/tramp.el (top): Add tramp-compat to `tramp-unload-hook'. 9 * net/tramp.el (top): Add tramp-compat to `tramp-unload-hook'.
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 74ad6e398a8..e64dd37d1fc 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -5,7 +5,7 @@
5;; Author: Tassilo Horn <tassilo@member.fsf.org> 5;; Author: Tassilo Horn <tassilo@member.fsf.org>
6;; Maintainer: Tassilo Horn <tassilo@member.fsf.org> 6;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
7;; Keywords: files, pdf, ps, dvi 7;; Keywords: files, pdf, ps, dvi
8;; Version: <2007-09-07 Fri 15:28> 8;; Version: <2007-10-02 Tue 18:21>
9 9
10;; This file is part of GNU Emacs. 10;; This file is part of GNU Emacs.
11 11
@@ -150,7 +150,7 @@ Needed for searching."
150 :group 'doc-view) 150 :group 'doc-view)
151 151
152(defcustom doc-view-cache-directory (concat temporary-file-directory 152(defcustom doc-view-cache-directory (concat temporary-file-directory
153 "doc-view") 153 "doc-view")
154 "The base directory, where the PNG images will be saved." 154 "The base directory, where the PNG images will be saved."
155 :type '(directory) 155 :type '(directory)
156 :group 'doc-view) 156 :group 'doc-view)
@@ -246,36 +246,36 @@ has finished."
246 (interactive "nPage: ") 246 (interactive "nPage: ")
247 (let ((len (length doc-view-current-files))) 247 (let ((len (length doc-view-current-files)))
248 (if (< page 1) 248 (if (< page 1)
249 (setq page 1) 249 (setq page 1)
250 (when (> page len) 250 (when (> page len)
251 (setq page len))) 251 (setq page len)))
252 (setq doc-view-current-page page 252 (setq doc-view-current-page page
253 doc-view-current-info 253 doc-view-current-info
254 (concat 254 (concat
255 (propertize 255 (propertize
256 (format "Page %d of %d." 256 (format "Page %d of %d."
257 doc-view-current-page 257 doc-view-current-page
258 len) 'face 'bold) 258 len) 'face 'bold)
259 ;; Tell user if converting isn't finished yet 259 ;; Tell user if converting isn't finished yet
260 (if doc-view-current-converter-process 260 (if doc-view-current-converter-process
261 " (still converting...)\n" 261 " (still converting...)\n"
262 "\n") 262 "\n")
263 ;; Display context infos if this page matches the last search 263 ;; Display context infos if this page matches the last search
264 (when (and doc-view-current-search-matches 264 (when (and doc-view-current-search-matches
265 (assq doc-view-current-page 265 (assq doc-view-current-page
266 doc-view-current-search-matches)) 266 doc-view-current-search-matches))
267 (concat (propertize "Search matches:\n" 'face 'bold) 267 (concat (propertize "Search matches:\n" 'face 'bold)
268 (let ((contexts "")) 268 (let ((contexts ""))
269 (dolist (m (cdr (assq doc-view-current-page 269 (dolist (m (cdr (assq doc-view-current-page
270 doc-view-current-search-matches))) 270 doc-view-current-search-matches)))
271 (setq contexts (concat contexts " - \"" m "\"\n"))) 271 (setq contexts (concat contexts " - \"" m "\"\n")))
272 contexts))))) 272 contexts)))))
273 ;; Update the buffer 273 ;; Update the buffer
274 (setq inhibit-read-only t) 274 (setq inhibit-read-only t)
275 (erase-buffer) 275 (erase-buffer)
276 (let ((beg (point))) 276 (let ((beg (point)))
277 (doc-view-insert-image (nth (1- page) doc-view-current-files) 277 (doc-view-insert-image (nth (1- page) doc-view-current-files)
278 :pointer 'arrow) 278 :pointer 'arrow)
279 (put-text-property beg (point) 'help-echo doc-view-current-info)) 279 (put-text-property beg (point) 'help-echo doc-view-current-info))
280 (insert "\n" doc-view-current-info) 280 (insert "\n" doc-view-current-info)
281 (goto-char (point-min)) 281 (goto-char (point-min))
@@ -315,7 +315,7 @@ has finished."
315 (condition-case nil 315 (condition-case nil
316 (scroll-down) 316 (scroll-down)
317 (error (doc-view-previous-page) 317 (error (doc-view-previous-page)
318 (goto-char (point-max))))) 318 (goto-char (point-max)))))
319 319
320(defun doc-view-kill-proc-and-buffer () 320(defun doc-view-kill-proc-and-buffer ()
321 "Kill the current converter process and buffer." 321 "Kill the current converter process and buffer."
@@ -338,13 +338,13 @@ It'a a subdirectory of `doc-view-cache-directory'."
338 doc-view-current-cache-dir 338 doc-view-current-cache-dir
339 (file-name-as-directory 339 (file-name-as-directory
340 (concat (file-name-as-directory doc-view-cache-directory) 340 (concat (file-name-as-directory doc-view-cache-directory)
341 (with-temp-buffer 341 (with-temp-buffer
342 (insert-file-contents-literally file) 342 (insert-file-contents-literally file)
343 (md5 (current-buffer))))))) 343 (md5 (current-buffer)))))))
344 344
345(defun doc-view-dvi->pdf-sentinel (proc event) 345(defun doc-view-dvi->pdf-sentinel (proc event)
346 "If DVI->PDF conversion was successful, convert the PDF to PNG 346 "If DVI->PDF conversion was successful, convert the PDF to PNG
347now." 347 now."
348 (if (not (string-match "finished" event)) 348 (if (not (string-match "finished" event))
349 (message "DocView: dvi->pdf process changed status to %s." event) 349 (message "DocView: dvi->pdf process changed status to %s." event)
350 (set-buffer (process-get proc 'buffer)) 350 (set-buffer (process-get proc 'buffer))
@@ -352,20 +352,20 @@ now."
352 (message "DocView: finished conversion from DVI to PDF!") 352 (message "DocView: finished conversion from DVI to PDF!")
353 ;; Now go on converting this PDF to a set of PNG files. 353 ;; Now go on converting this PDF to a set of PNG files.
354 (let* ((pdf (process-get proc 'pdf-file)) 354 (let* ((pdf (process-get proc 'pdf-file))
355 (png (concat (doc-view-file-name-to-directory-name 355 (png (concat (doc-view-file-name-to-directory-name
356 doc-view-current-doc) 356 doc-view-current-doc)
357 "page-%d.png"))) 357 "page-%d.png")))
358 (doc-view-pdf/ps->png pdf png)))) 358 (doc-view-pdf/ps->png pdf png))))
359 359
360(defun doc-view-dvi->pdf (dvi pdf) 360(defun doc-view-dvi->pdf (dvi pdf)
361 "Convert DVI to PDF asynchrounously." 361 "Convert DVI to PDF asynchrounously."
362 (message "DocView: converting DVI to PDF now!") 362 (message "DocView: converting DVI to PDF now!")
363 (setq doc-view-current-converter-process 363 (setq doc-view-current-converter-process
364 (start-process "doc-view-dvi->pdf" doc-view-conversion-buffer 364 (start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
365 doc-view-dvipdfm-program 365 doc-view-dvipdfm-program
366 "-o" pdf dvi)) 366 "-o" pdf dvi))
367 (set-process-sentinel doc-view-current-converter-process 367 (set-process-sentinel doc-view-current-converter-process
368 'doc-view-dvi->pdf-sentinel) 368 'doc-view-dvi->pdf-sentinel)
369 (process-put doc-view-current-converter-process 'buffer (current-buffer)) 369 (process-put doc-view-current-converter-process 'buffer (current-buffer))
370 (process-put doc-view-current-converter-process 'pdf-file pdf)) 370 (process-put doc-view-current-converter-process 'pdf-file pdf))
371 371
@@ -386,44 +386,44 @@ now."
386 "Convert PDF-PS to PNG asynchrounously." 386 "Convert PDF-PS to PNG asynchrounously."
387 (message "DocView: converting PDF or PS to PNG now!") 387 (message "DocView: converting PDF or PS to PNG now!")
388 (setq doc-view-current-converter-process 388 (setq doc-view-current-converter-process
389 (apply 'start-process 389 (apply 'start-process
390 (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer 390 (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
391 doc-view-ghostscript-program) 391 doc-view-ghostscript-program)
392 doc-view-ghostscript-options 392 doc-view-ghostscript-options
393 (list (concat "-sOutputFile=" png)) 393 (list (concat "-sOutputFile=" png))
394 (list pdf-ps)))) 394 (list pdf-ps))))
395 (process-put doc-view-current-converter-process 395 (process-put doc-view-current-converter-process
396 'buffer (current-buffer)) 396 'buffer (current-buffer))
397 (set-process-sentinel doc-view-current-converter-process 397 (set-process-sentinel doc-view-current-converter-process
398 'doc-view-pdf/ps->png-sentinel) 398 'doc-view-pdf/ps->png-sentinel)
399 (when doc-view-conversion-refresh-interval 399 (when doc-view-conversion-refresh-interval
400 (setq doc-view-current-timer 400 (setq doc-view-current-timer
401 (run-at-time "1 secs" doc-view-conversion-refresh-interval 401 (run-at-time "1 secs" doc-view-conversion-refresh-interval
402 'doc-view-display 402 'doc-view-display
403 doc-view-current-doc)))) 403 doc-view-current-doc))))
404 404
405(defun doc-view-pdf->txt-sentinel (proc event) 405(defun doc-view-pdf->txt-sentinel (proc event)
406 (if (not (string-match "finished" event)) 406 (if (not (string-match "finished" event))
407 (message "DocView: converter process changed status to %s." event) 407 (message "DocView: converter process changed status to %s." event)
408 (let ((current-buffer (current-buffer)) 408 (let ((current-buffer (current-buffer))
409 (proc-buffer (process-get proc 'buffer))) 409 (proc-buffer (process-get proc 'buffer)))
410 (set-buffer proc-buffer) 410 (set-buffer proc-buffer)
411 (setq doc-view-current-converter-process nil) 411 (setq doc-view-current-converter-process nil)
412 (message "DocView: finished conversion from PDF to TXT!") 412 (message "DocView: finished conversion from PDF to TXT!")
413 ;; If the user looks at the DocView buffer where the conversion was 413 ;; If the user looks at the DocView buffer where the conversion was
414 ;; performed, search anew. This time it will be queried for a regexp. 414 ;; performed, search anew. This time it will be queried for a regexp.
415 (when (eq current-buffer proc-buffer) 415 (when (eq current-buffer proc-buffer)
416 (doc-view-search))))) 416 (doc-view-search)))))
417 417
418(defun doc-view-pdf->txt (pdf txt) 418(defun doc-view-pdf->txt (pdf txt)
419 "Convert PDF to TXT asynchrounously." 419 "Convert PDF to TXT asynchrounously."
420 (message "DocView: converting PDF to TXT now!") 420 (message "DocView: converting PDF to TXT now!")
421 (setq doc-view-current-converter-process 421 (setq doc-view-current-converter-process
422 (start-process "doc-view-pdf->txt" doc-view-conversion-buffer 422 (start-process "doc-view-pdf->txt" doc-view-conversion-buffer
423 doc-view-pdftotext-program "-raw" 423 doc-view-pdftotext-program "-raw"
424 pdf txt)) 424 pdf txt))
425 (set-process-sentinel doc-view-current-converter-process 425 (set-process-sentinel doc-view-current-converter-process
426 'doc-view-pdf->txt-sentinel) 426 'doc-view-pdf->txt-sentinel)
427 (process-put doc-view-current-converter-process 'buffer (current-buffer))) 427 (process-put doc-view-current-converter-process 'buffer (current-buffer)))
428 428
429(defun doc-view-ps->pdf-sentinel (proc event) 429(defun doc-view-ps->pdf-sentinel (proc event)
@@ -434,19 +434,19 @@ now."
434 (message "DocView: finished conversion from PS to PDF!") 434 (message "DocView: finished conversion from PS to PDF!")
435 ;; Now we can transform to plain text. 435 ;; Now we can transform to plain text.
436 (doc-view-pdf->txt (process-get proc 'pdf-file) 436 (doc-view-pdf->txt (process-get proc 'pdf-file)
437 (concat (doc-view-file-name-to-directory-name 437 (concat (doc-view-file-name-to-directory-name
438 doc-view-current-doc) 438 doc-view-current-doc)
439 "doc.txt")))) 439 "doc.txt"))))
440 440
441(defun doc-view-ps->pdf (ps pdf) 441(defun doc-view-ps->pdf (ps pdf)
442 "Convert PS to PDF asynchronously." 442 "Convert PS to PDF asynchronously."
443 (message "DocView: converting PS to PDF now!") 443 (message "DocView: converting PS to PDF now!")
444 (setq doc-view-current-converter-process 444 (setq doc-view-current-converter-process
445 (start-process "doc-view-ps->pdf" doc-view-conversion-buffer 445 (start-process "doc-view-ps->pdf" doc-view-conversion-buffer
446 doc-view-ps2pdf-program 446 doc-view-ps2pdf-program
447 ps pdf)) 447 ps pdf))
448 (set-process-sentinel doc-view-current-converter-process 448 (set-process-sentinel doc-view-current-converter-process
449 'doc-view-ps->pdf-sentinel) 449 'doc-view-ps->pdf-sentinel)
450 (process-put doc-view-current-converter-process 'buffer (current-buffer)) 450 (process-put doc-view-current-converter-process 'buffer (current-buffer))
451 (process-put doc-view-current-converter-process 'pdf-file pdf)) 451 (process-put doc-view-current-converter-process 'pdf-file pdf))
452 452
@@ -457,18 +457,18 @@ Those files are saved in the directory given by
457`doc-view-file-name-to-directory-name'." 457`doc-view-file-name-to-directory-name'."
458 (clear-image-cache) 458 (clear-image-cache)
459 (let* ((dir (doc-view-file-name-to-directory-name doc)) 459 (let* ((dir (doc-view-file-name-to-directory-name doc))
460 (png-file (concat (file-name-as-directory dir) "page-%d.png"))) 460 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
461 (when (file-exists-p dir) 461 (when (file-exists-p dir)
462 (dired-delete-file dir 'always)) 462 (dired-delete-file dir 'always))
463 (make-directory dir t) 463 (make-directory dir t)
464 (if (not (string= (file-name-extension doc) "dvi")) 464 (if (not (string= (file-name-extension doc) "dvi"))
465 ;; Convert to PNG images. 465 ;; Convert to PNG images.
466 (doc-view-pdf/ps->png doc png-file) 466 (doc-view-pdf/ps->png doc png-file)
467 ;; DVI files have to be converted to PDF before GhostScript can process 467 ;; DVI files have to be converted to PDF before GhostScript can process
468 ;; it. 468 ;; it.
469 (doc-view-dvi->pdf doc 469 (doc-view-dvi->pdf doc
470 (concat (file-name-as-directory dir) 470 (concat (file-name-as-directory dir)
471 "doc.pdf"))))) 471 "doc.pdf")))))
472 472
473;;;; DocView Mode 473;;;; DocView Mode
474 474
@@ -501,10 +501,10 @@ See `doc-view-set-slice-using-mouse' for a more convenient way to
501do that. To reset the slice use `doc-view-reset-slice'." 501do that. To reset the slice use `doc-view-reset-slice'."
502 (interactive 502 (interactive
503 (let* ((size (image-size doc-view-current-image t)) 503 (let* ((size (image-size doc-view-current-image t))
504 (a (read-number (format "Top-left X (0..%d): " (car size)))) 504 (a (read-number (format "Top-left X (0..%d): " (car size))))
505 (b (read-number (format "Top-left Y (0..%d): " (cdr size)))) 505 (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
506 (c (read-number (format "Width (0..%d): " (- (car size) a)))) 506 (c (read-number (format "Width (0..%d): " (- (car size) a))))
507 (d (read-number (format "Height (0..%d): " (- (cdr size) b))))) 507 (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
508 (list a b c d))) 508 (list a b c d)))
509 (setq doc-view-current-slice (list x y width height)) 509 (setq doc-view-current-slice (list x y width height))
510 ;; Redisplay 510 ;; Redisplay
@@ -519,14 +519,14 @@ dragging it to its bottom-right corner. See also
519 (let (x y w h done) 519 (let (x y w h done)
520 (while (not done) 520 (while (not done)
521 (let ((e (read-event 521 (let ((e (read-event
522 (concat "Press mouse-1 at the top-left corner and " 522 (concat "Press mouse-1 at the top-left corner and "
523 "drag it to the bottom-right corner!")))) 523 "drag it to the bottom-right corner!"))))
524 (when (eq (car e) 'drag-mouse-1) 524 (when (eq (car e) 'drag-mouse-1)
525 (setq x (car (posn-object-x-y (event-start e)))) 525 (setq x (car (posn-object-x-y (event-start e))))
526 (setq y (cdr (posn-object-x-y (event-start e)))) 526 (setq y (cdr (posn-object-x-y (event-start e))))
527 (setq w (- (car (posn-object-x-y (event-end e))) x)) 527 (setq w (- (car (posn-object-x-y (event-end e))) x))
528 (setq h (- (cdr (posn-object-x-y (event-end e))) y)) 528 (setq h (- (cdr (posn-object-x-y (event-end e))) y))
529 (setq done t)))) 529 (setq done t))))
530 (doc-view-set-slice x y w h))) 530 (doc-view-set-slice x y w h)))
531 531
532(defun doc-view-reset-slice () 532(defun doc-view-reset-slice ()
@@ -553,7 +553,7 @@ Predicate for sorting `doc-view-current-files'."
553 (if (< (length a) (length b)) 553 (if (< (length a) (length b))
554 t 554 t
555 (if (> (length a) (length b)) 555 (if (> (length a) (length b))
556 nil 556 nil
557 (string< a b)))) 557 (string< a b))))
558 558
559(defun doc-view-display (doc) 559(defun doc-view-display (doc)
@@ -561,8 +561,8 @@ Predicate for sorting `doc-view-current-files'."
561 (let ((dir (doc-view-file-name-to-directory-name doc))) 561 (let ((dir (doc-view-file-name-to-directory-name doc)))
562 (set-buffer (format "*DocView: %s*" doc)) 562 (set-buffer (format "*DocView: %s*" doc))
563 (setq doc-view-current-files 563 (setq doc-view-current-files
564 (sort (directory-files dir t "page-[0-9]+\\.png" t) 564 (sort (directory-files dir t "page-[0-9]+\\.png" t)
565 'doc-view-sort)) 565 'doc-view-sort))
566 (when (> (length doc-view-current-files) 0) 566 (when (> (length doc-view-current-files) 0)
567 (doc-view-goto-page doc-view-current-page)))) 567 (doc-view-goto-page doc-view-current-page))))
568 568
@@ -570,8 +570,8 @@ Predicate for sorting `doc-view-current-files'."
570 (setq inhibit-read-only t) 570 (setq inhibit-read-only t)
571 (erase-buffer) 571 (erase-buffer)
572 (insert (propertize "Welcome to DocView!" 'face 'bold) 572 (insert (propertize "Welcome to DocView!" 'face 'bold)
573 "\n" 573 "\n"
574 " 574 "
575If you see this buffer it means that the document you want to 575If you see this buffer it means that the document you want to
576view gets converted to PNG now and the conversion of the first 576view gets converted to PNG now and the conversion of the first
577page hasn't finished yet or 577page hasn't finished yet or
@@ -579,8 +579,8 @@ page hasn't finished yet or
579 579
580For now these keys are useful: 580For now these keys are useful:
581 581
582 `q' : Bury this buffer. Conversion will go on in background. 582`q' : Bury this buffer. Conversion will go on in background.
583 `k' : Kill the conversion process and this buffer.\n") 583`k' : Kill the conversion process and this buffer.\n")
584 (setq inhibit-read-only nil)) 584 (setq inhibit-read-only nil))
585 585
586(defun doc-view-show-tooltip () 586(defun doc-view-show-tooltip ()
@@ -591,39 +591,35 @@ For now these keys are useful:
591 591
592(defun doc-view-search-internal (regexp file) 592(defun doc-view-search-internal (regexp file)
593 "Return a list of FILE's pages that contain text matching REGEXP. 593 "Return a list of FILE's pages that contain text matching REGEXP.
594The value is an alist of the form 594The value is an alist of the form (PAGE CONTEXTS) where PAGE is
595 595the pagenumber and CONTEXTS are all lines of text containing a match."
596 (PAGE CONTEXTS)
597
598where PAGE is the pagenumber and CONTEXTS are the lines
599containing the match."
600 (with-temp-buffer 596 (with-temp-buffer
601 (insert-file-contents file) 597 (insert-file-contents file)
602 (let ((page 1) 598 (let ((page 1)
603 (lastpage 1) 599 (lastpage 1)
604 matches) 600 matches)
605 (while (re-search-forward (concat "\\(?:\\([ ]\\)\\|\\(" 601 (while (re-search-forward (concat "\\(?:\\([ ]\\)\\|\\("
606 regexp "\\)\\)") nil t) 602 regexp "\\)\\)") nil t)
607 (when (match-string 1) (incf page)) 603 (when (match-string 1) (incf page))
608 (when (match-string 2) 604 (when (match-string 2)
609 (if (/= page lastpage) 605 (if (/= page lastpage)
610 (setq matches (push (cons page 606 (setq matches (push (cons page
611 (list (buffer-substring 607 (list (buffer-substring
612 (line-beginning-position) 608 (line-beginning-position)
613 (line-end-position)))) 609 (line-end-position))))
614 matches)) 610 matches))
615 (setq matches (cons 611 (setq matches (cons
616 (append 612 (append
617 (or 613 (or
618 ;; This page already is a match. 614 ;; This page already is a match.
619 (car matches) 615 (car matches)
620 ;; This is the first match on page. 616 ;; This is the first match on page.
621 (list page)) 617 (list page))
622 (list (buffer-substring 618 (list (buffer-substring
623 (line-beginning-position) 619 (line-beginning-position)
624 (line-end-position)))) 620 (line-end-position))))
625 (cdr matches)))) 621 (cdr matches))))
626 (setq lastpage page))) 622 (setq lastpage page)))
627 (nreverse matches)))) 623 (nreverse matches))))
628 624
629(defun doc-view-search-no-of-matches (list) 625(defun doc-view-search-no-of-matches (list)
@@ -642,69 +638,70 @@ conversion finished."
642 ;; New search, so forget the old results. 638 ;; New search, so forget the old results.
643 (setq doc-view-current-search-matches nil) 639 (setq doc-view-current-search-matches nil)
644 (let ((txt (concat (doc-view-file-name-to-directory-name 640 (let ((txt (concat (doc-view-file-name-to-directory-name
645 doc-view-current-doc) 641 doc-view-current-doc)
646 "doc.txt"))) 642 "doc.txt")))
647 (if (file-readable-p txt) 643 (if (file-readable-p txt)
648 (progn 644 (progn
649 (setq doc-view-current-search-matches 645 (setq doc-view-current-search-matches
650 (doc-view-search-internal 646 (doc-view-search-internal
651 (read-from-minibuffer "Regexp: ") 647 (read-from-minibuffer "Regexp: ")
652 txt)) 648 txt))
653 (message "DocView: search yielded %d matches." 649 (message "DocView: search yielded %d matches."
654 (doc-view-search-no-of-matches 650 (doc-view-search-no-of-matches
655 doc-view-current-search-matches))) 651 doc-view-current-search-matches)))
656 ;; We must convert to TXT first! 652 ;; We must convert to TXT first!
657 (if doc-view-current-converter-process 653 (if doc-view-current-converter-process
658 (message "DocView: please wait till conversion finished.") 654 (message "DocView: please wait till conversion finished.")
659 (let ((ext (file-name-extension doc-view-current-doc))) 655 (let ((ext (file-name-extension doc-view-current-doc)))
660 (cond 656 (cond
661 ((string= ext "pdf") 657 ((string= ext "pdf")
662 ;; Doc is a PDF, so convert it to TXT 658 ;; Doc is a PDF, so convert it to TXT
663 (doc-view-pdf->txt doc-view-current-doc txt)) 659 (doc-view-pdf->txt doc-view-current-doc txt))
664 ((string= ext "ps") 660 ((string= ext "ps")
665 ;; Doc is a PS, so convert it to PDF (which will be converted to 661 ;; Doc is a PS, so convert it to PDF (which will be converted to
666 ;; TXT thereafter). 662 ;; TXT thereafter).
667 (doc-view-ps->pdf doc-view-current-doc 663 (doc-view-ps->pdf doc-view-current-doc
668 (concat (doc-view-file-name-to-directory-name 664 (concat (doc-view-file-name-to-directory-name
669 doc-view-current-doc) 665 doc-view-current-doc)
670 "doc.pdf"))) 666 "doc.pdf")))
671 ((string= ext "dvi") 667 ((string= ext "dvi")
672 ;; Doc is a DVI. This means that a doc.pdf already exists in its 668 ;; Doc is a DVI. This means that a doc.pdf already exists in its
673 ;; cache subdirectory. 669 ;; cache subdirectory.
674 (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name 670 (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
675 doc-view-current-doc) 671 doc-view-current-doc)
676 "doc.pdf") 672 "doc.pdf")
677 txt)) 673 txt))
678 (t (error "DocView doesn't know what to do")))))))) 674 (t (error "DocView doesn't know what to do"))))))))
679 675
680(defun doc-view-search-next-match (arg) 676(defun doc-view-search-next-match (arg)
681 "Go to the ARGth next matching page." 677 "Go to the ARGth next matching page."
682 (interactive "p") 678 (interactive "p")
683 (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page)) 679 (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page))
684 doc-view-current-search-matches)) 680 doc-view-current-search-matches))
685 (page (car (nth (1- arg) next-pages)))) 681 (page (car (nth (1- arg) next-pages))))
686 (if page 682 (if page
687 (doc-view-goto-page page) 683 (doc-view-goto-page page)
688 (when (and 684 (when (and
689 doc-view-current-search-matches 685 doc-view-current-search-matches
690 (y-or-n-p "No more matches after current page. Wrap to first match? ")) 686 (y-or-n-p "No more matches after current page. Wrap to first match? "))
691 (doc-view-goto-page (caar doc-view-current-search-matches)))))) 687 (doc-view-goto-page (caar doc-view-current-search-matches))))))
692 688
693(defun doc-view-search-previous-match (arg) 689(defun doc-view-search-previous-match (arg)
694 "Go to the ARGth previous matching page." 690 "Go to the ARGth previous matching page."
695 (interactive "p") 691 (interactive "p")
696 (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page)) 692 (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page))
697 doc-view-current-search-matches)) 693 doc-view-current-search-matches))
698 (page (car (nth (1- arg) (nreverse prev-pages))))) 694 (page (car (nth (1- arg) (nreverse prev-pages)))))
699 (if page 695 (if page
700 (doc-view-goto-page page) 696 (doc-view-goto-page page)
701 (when (and 697 (when (and
702 doc-view-current-search-matches 698 doc-view-current-search-matches
703 (y-or-n-p "No more matches before current page. Wrap to last match? ")) 699 (y-or-n-p "No more matches before current page. Wrap to last match? "))
704 (doc-view-goto-page (caar (last doc-view-current-search-matches))))))) 700 (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
705 701
706;;;; User Interface Commands 702;;;; User Interface Commands
707 703
704;;;###autoload
708(defun doc-view (no-cache &optional file) 705(defun doc-view (no-cache &optional file)
709 "Convert FILE to png and start viewing it. 706 "Convert FILE to png and start viewing it.
710If no FILE is given, query for on. 707If no FILE is given, query for on.
@@ -713,24 +710,31 @@ existing page files. With prefix arg NO-CACHE, don't use the
713cached files and convert anew." 710cached files and convert anew."
714 (interactive "P") 711 (interactive "P")
715 (if (not (and (image-type-available-p 'png) 712 (if (not (and (image-type-available-p 'png)
716 (display-images-p))) 713 (display-images-p)))
717 (message "DocView: your emacs or display doesn't support png images.") 714 (message "DocView: your emacs or display doesn't support png images.")
718 (let* ((doc (or file 715 (let* ((doc (or file
719 (expand-file-name (read-file-name "File: " nil nil t)))) 716 (expand-file-name
720 (buffer (get-buffer-create (format "*DocView: %s*" doc))) 717 (let ((completion-ignored-extensions
721 (dir (doc-view-file-name-to-directory-name doc))) 718 ;; Don't hide files doc-view can display
719 (remove-if (lambda (str)
720 (string-match "\\.\\(ps\\|pdf\\|dvi\\)$"
721 str))
722 completion-ignored-extensions)))
723 (read-file-name "File: " nil nil t)))))
724 (buffer (get-buffer-create (format "*DocView: %s*" doc)))
725 (dir (doc-view-file-name-to-directory-name doc)))
722 (switch-to-buffer buffer) 726 (switch-to-buffer buffer)
723 (doc-view-buffer-message) 727 (doc-view-buffer-message)
724 (doc-view-mode) 728 (doc-view-mode)
725 (setq doc-view-current-doc doc) 729 (setq doc-view-current-doc doc)
726 (setq doc-view-current-page 1) 730 (setq doc-view-current-page 1)
727 (if (not (and (file-exists-p dir) 731 (if (not (and (file-exists-p dir)
728 (not no-cache))) 732 (not no-cache)))
729 (progn 733 (progn
730 (setq doc-view-current-cache-dir nil) 734 (setq doc-view-current-cache-dir nil)
731 (doc-view-convert-doc doc-view-current-doc)) 735 (doc-view-convert-doc doc-view-current-doc))
732 (message "DocView: using cached files!") 736 (message "DocView: using cached files!")
733 (doc-view-display doc-view-current-doc))))) 737 (doc-view-display doc-view-current-doc)))))
734 738
735(defun doc-view-dired (no-cache) 739(defun doc-view-dired (no-cache)
736 "View the current dired file with doc-view. 740 "View the current dired file with doc-view.