* Yet another doc-view patch
@ 2007-10-19 12:57 Tassilo Horn
2007-10-20 3:30 ` Richard Stallman
0 siblings, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2007-10-19 12:57 UTC (permalink / raw)
To: emacs-devel
Hi all,
this patch (below or from [1]) implements the following:
- New minor mode: doc-view-minor-mode which has only one binding C-c
C-c to switch to doc-view-mode.
- New function: doc-view-mode-maybe. If there's another mode for this
file type in auto-mode-alist (like ps-mode), then use that mode and
enable doc-view-minor-mode, else enable doc-view-mode.
- fixed some bugs.
The results are, that opening a e?ps file opens it with ps-mode (as
auto-mode-alist says) and toggles doc-view-minor-mode on. With C-c C-c
you can toggle between the editing mode found in auto-mode-alist and
doc-view-mode. If you edited a e?ps file and toggle to d-v-m you'll be
asked to save your changes and the doc will be reconverted.
Currently, C-c C-c for PDF and DVI files will re-open them with
doc-view-mode again, because that's what auto-mode-alist tells. I
suggest we take the doc-view-mode entries out of auto-mode-alist and
replace them with the proper editing modes, e.g. ps-mode for PDF files
(is that correct?) and fundamental-mode for DVI files. Then we can add
autoload-cookies similar to the one for e?ps files to doc-view.el and
everything behaves similar for all types of document files.
If you agree, feel free to change that before committing.
Bye,
Tassilo
__________
[1] http://www.tsdh.de/stuff/doc-view.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Yet another doc-view patch
2007-10-19 12:57 Yet another doc-view patch Tassilo Horn
@ 2007-10-20 3:30 ` Richard Stallman
2007-10-20 10:31 ` Tassilo Horn
0 siblings, 1 reply; 4+ messages in thread
From: Richard Stallman @ 2007-10-20 3:30 UTC (permalink / raw)
To: Tassilo Horn; +Cc: emacs-devel
I
suggest we take the doc-view-mode entries out of auto-mode-alist and
replace them with the proper editing modes, e.g. ps-mode for PDF files
(is that correct?) and fundamental-mode for DVI files. Then we can add
autoload-cookies similar to the one for e?ps files to doc-view.el and
everything behaves similar for all types of document files.
I think it should display PDF and DVI files in rendered form by default.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Yet another doc-view patch
2007-10-20 3:30 ` Richard Stallman
@ 2007-10-20 10:31 ` Tassilo Horn
2007-10-20 10:32 ` Tassilo Horn
0 siblings, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2007-10-20 10:31 UTC (permalink / raw)
To: rms; +Cc: emacs-devel
Richard Stallman <rms@gnu.org> writes:
Hi Richard,
> I think it should display PDF and DVI files in rendered form by
> default.
Ok, the following patch (attached or at [1]) implements this.
I added editing mode entries for `auto-mode-alist' (files.el: `ps-mode'
for PDF and `fundamental-mode' for DVI) and in doc-view.el I push
additional entries for all doc-files that use `doc-view-mode-maybe' as
function. This function finally decides if `doc-view-mode' or the
editing mode + `doc-view-minor-mode' is used.
There's one little problem: `ps-mode' has `C-c C-c' already bound. So
what other key should we use for toggling?
Bye,
Tassilo
__________
[1] http://www.tsdh.de/stuff/doc-view.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Yet another doc-view patch
2007-10-20 10:31 ` Tassilo Horn
@ 2007-10-20 10:32 ` Tassilo Horn
0 siblings, 0 replies; 4+ messages in thread
From: Tassilo Horn @ 2007-10-20 10:32 UTC (permalink / raw)
To: rms; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 149 bytes --]
Tassilo Horn <tassilo@member.fsf.org> writes:
> Ok, the following patch (attached or at [1]) implements this.
Ups, sorry. I forgot to attach it.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: doc-view.patch --]
[-- Type: text/x-patch, Size: 14345 bytes --]
Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.935
diff -u -r1.935 files.el
--- lisp/files.el 18 Oct 2007 19:59:52 -0000 1.935
+++ lisp/files.el 20 Oct 2007 10:24:20 -0000
@@ -2060,7 +2060,8 @@
("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MSDOG
("\\.[eE]?[pP][sS]\\'" . ps-mode)
- ("\\.\\(?:PDF\\|DVI\\|pdf\\|dvi\\)" . doc-view-mode)
+ ("\\.[Pp][Dd][Ff]\\'" . ps-mode)
+ ("\\.[Dd][Vv][Ii]\\'" . fundamental-mode)
("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
("BROWSE\\'" . ebrowse-tree-mode)
("\\.ebrowse\\'" . ebrowse-tree-mode)
Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.11
diff -u -r1.11 doc-view.el
--- lisp/doc-view.el 19 Oct 2007 16:03:09 -0000 1.11
+++ lisp/doc-view.el 20 Oct 2007 10:24:21 -0000
@@ -104,6 +104,10 @@
(require 'image-mode)
(eval-when-compile (require 'cl))
+;;;###autoload (push '("\\.[eE]?[pP][sS]\\'" . doc-view-mode-maybe) auto-mode-alist)
+;;;###autoload (push '("\\.[Dd][Vv][Ii]\\'" . doc-view-mode-maybe) auto-mode-alist)
+;;;###autoload (push '("\\.[Pp][Dd][Ff]\\'" . doc-view-mode-maybe) auto-mode-alist)
+
;;;; Customization Options
(defgroup doc-view nil
@@ -202,9 +206,6 @@
(defvar doc-view-current-info nil
"Only used internally.")
-(defvar doc-view-current-display nil
- "Only used internally.")
-
;;;; DocView Keymaps
(defvar doc-view-mode-map
@@ -224,6 +225,7 @@
;; Killing/burying the buffer (and the process)
(define-key map (kbd "q") 'bury-buffer)
(define-key map (kbd "k") 'doc-view-kill-proc-and-buffer)
+ (define-key map (kbd "K") 'doc-view-kill-proc)
;; Slicing the image
(define-key map (kbd "s s") 'doc-view-set-slice)
(define-key map (kbd "s m") 'doc-view-set-slice-using-mouse)
@@ -242,24 +244,18 @@
(define-key map (kbd "C-t") 'doc-view-show-tooltip)
;; Toggle between text and image display or editing
(define-key map (kbd "C-c C-c") 'doc-view-toggle-display)
- (define-key map (kbd "C-c C-e") 'doc-view-edit-doc)
;; Reconvert the current document
(define-key map (kbd "g") 'doc-view-reconvert-doc)
(suppress-keymap map)
map)
"Keymap used by `doc-view-mode' when displaying a doc as a set of images.")
-(defvar doc-view-mode-text-map
+(defvar doc-view-minor-mode-map
(let ((map (make-sparse-keymap)))
;; Toggle between text and image display or editing
(define-key map (kbd "C-c C-c") 'doc-view-toggle-display)
- (define-key map (kbd "C-c C-e") 'doc-view-edit-doc)
- ;; Killing/burying the buffer (and the process)
- (define-key map (kbd "q") 'bury-buffer)
- (define-key map (kbd "k") 'doc-view-kill-proc-and-buffer)
- (define-key map (kbd "C-x k") 'doc-view-kill-proc-and-buffer)
map)
- "Keymap used by `doc-view-mode' when displaying a document as text.")
+ "Keymap used by `doc-minor-view-mode'.")
;;;; Navigation Commands
@@ -339,11 +335,14 @@
(error (doc-view-previous-page)
(goto-char (point-max)))))
+;;;; Utility Functions
+
(defun doc-view-kill-proc ()
"Kill the current converter process."
(interactive)
(when doc-view-current-converter-process
- (kill-process doc-view-current-converter-process))
+ (kill-process doc-view-current-converter-process)
+ (setq doc-view-current-converter-process nil))
(when doc-view-current-timer
(cancel-timer doc-view-current-timer)
(setq doc-view-current-timer nil))
@@ -356,20 +355,14 @@
(when (eq major-mode 'doc-view-mode)
(kill-buffer (current-buffer))))
-;;;; Conversion Functions
-
-(defun doc-view-reconvert-doc (&rest args)
- "Reconvert the current document.
-Should be invoked when the cached images aren't up-to-date."
- (interactive)
- (let ((inhibit-read-only t)
- (doc doc-view-current-doc))
- (doc-view-kill-proc)
- ;; Clear the old cached files
- (when (file-exists-p (doc-view-current-cache-dir))
- (dired-delete-file (doc-view-current-cache-dir) 'always))
- (doc-view-kill-proc-and-buffer)
- (find-file doc)))
+(defun doc-view-clean-auto-mode-alist ()
+ "Return `auto-mode-alist' with all occurences of `doc-view-mode-maybe' removed."
+ (delq nil (mapcar
+ (lambda (elt)
+ (unless (eq (or (car-safe (cdr elt)) (cdr elt))
+ 'doc-view-mode-maybe)
+ elt))
+ auto-mode-alist)))
(defun doc-view-current-cache-dir ()
"Return the directory where the png files of the current doc should be saved.
@@ -384,6 +377,20 @@
(insert-file-contents-literally doc)
(md5 (current-buffer)))))))))
+;;;; Conversion Functions
+
+(defun doc-view-reconvert-doc (&rest args)
+ "Reconvert the current document.
+Should be invoked when the cached images aren't up-to-date."
+ (interactive)
+ (let ((inhibit-read-only t)
+ (doc doc-view-current-doc))
+ (doc-view-kill-proc)
+ ;; Clear the old cached files
+ (when (file-exists-p (doc-view-current-cache-dir))
+ (dired-delete-file (doc-view-current-cache-dir) 'always))
+ (doc-view-mode)))
+
(defun doc-view-dvi->pdf-sentinel (proc event)
"If DVI->PDF conversion was successful, convert the PDF to PNG now."
(if (not (string-match "finished" event))
@@ -439,7 +446,7 @@
(when doc-view-conversion-refresh-interval
(setq doc-view-current-timer
(run-at-time "1 secs" doc-view-conversion-refresh-interval
- 'doc-view-display-maybe
+ 'doc-view-display
doc-view-current-doc))))
(defun doc-view-pdf->txt-sentinel (proc event)
@@ -482,10 +489,11 @@
(setq doc-view-current-converter-process
(start-process "ps->pdf" doc-view-conversion-buffer
doc-view-ps2pdf-program
- ps pdf
;; Avoid security problems when rendering files from
;; untrusted sources.
- "-dSAFER")
+ "-dSAFER"
+ ;; in-file and out-file
+ ps pdf)
mode-line-process (list (format ":%s" doc-view-current-converter-process)))
(set-process-sentinel doc-view-current-converter-process
'doc-view-ps->pdf-sentinel)
@@ -499,7 +507,7 @@
(clear-image-cache)
(let ((png-file (concat (doc-view-current-cache-dir)
"page-%d.png")))
- (make-directory doc-view-current-cache-dir t)
+ (make-directory (doc-view-current-cache-dir) t)
(if (not (string= (file-name-extension doc-view-current-doc) "dvi"))
;; Convert to PNG images.
(doc-view-pdf/ps->png doc-view-current-doc png-file)
@@ -576,11 +584,6 @@
nil
(string< a b))))
-(defun doc-view-display-maybe (doc)
- "Call `doc-view-display' iff we're in the image display."
- (when (eq doc-view-current-display 'image)
- (doc-view-display doc)))
-
(defun doc-view-display (doc)
"Start viewing the document DOC."
(set-buffer (get-file-buffer doc))
@@ -603,58 +606,36 @@
For now these keys are useful:
`q' : Bury this buffer. Conversion will go on in background.
-`k' : Kill the conversion process and this buffer.\n")
+`k' : Kill the conversion process and this buffer.
+`K' : Kill the conversion process.\n")
(set-buffer-modified-p nil))
(defun doc-view-show-tooltip ()
(interactive)
(tooltip-show doc-view-current-info))
-;;;;; Toggle between text and image display
+;;;;; Toggle between editing and viewing
(defun doc-view-toggle-display ()
- "Start or stop displaying a document file as a set of images.
-This command toggles between showing the text of the document
-file and showing the document as a set of images."
+ "Toggle between editing a document as text or viewing it."
(interactive)
- (if (get-text-property (point-min) 'display)
- ;; Switch to text display
- (let ((inhibit-read-only t))
+ (if (eq major-mode 'doc-view-mode)
+ ;; Switch to editing mode
+ (let ((auto-mode-alist (doc-view-clean-auto-mode-alist))
+ (doc doc-view-current-doc))
+ (doc-view-kill-proc)
+ (setq buffer-read-only nil)
(erase-buffer)
- (insert-file-contents doc-view-current-doc)
- (use-local-map doc-view-mode-text-map)
- (setq mode-name "DocView[text]"
- doc-view-current-display 'text)
- (if (called-interactively-p)
- (message "Repeat this command to go back to displaying the file as images")))
- ;; Switch to image display
- (let ((inhibit-read-only t))
- (erase-buffer)
- (doc-view-buffer-message)
- (setq doc-view-current-page (or doc-view-current-page 1))
- (if (file-exists-p (doc-view-current-cache-dir))
- (progn
- (message "DocView: using cached files!")
- (doc-view-display doc-view-current-doc))
- (doc-view-convert-current-doc))
- (use-local-map doc-view-mode-map)
- (setq mode-name (format "DocView")
- doc-view-current-display 'image)
- (if (called-interactively-p)
- (message "Repeat this command to go back to displaying the file as text"))))
- (set-buffer-modified-p nil))
-
-;;;;; Leave doc-view-mode and open the file for edit
-
-(defun doc-view-edit-doc ()
- "Leave `doc-view-mode' and open the current doc with an appropriate editing mode."
- (interactive)
- (let ((filename doc-view-current-doc)
- (auto-mode-alist (append '(("\\.[eE]?[pP][sS]\\'" . ps-mode)
- ("\\.\\(pdf\\|PDF\\|dvi\\|DVI\\)$" . fundamental-mode))
- auto-mode-alist)))
- (kill-buffer (current-buffer))
- (find-file filename)))
+ (insert-file-contents buffer-file-name)
+ (set-auto-mode)
+ (doc-view-minor-mode 1)
+ (set-buffer-modified-p nil))
+ ;; Switch to doc-view-mode
+ (when (and (buffer-modified-p)
+ (y-or-n-p "The buffer has been modified. Save the changes? "))
+ (save-buffer))
+ (erase-buffer)
+ (doc-view-mode)))
;;;; Searching
@@ -773,7 +754,7 @@
(define-derived-mode doc-view-mode nil "DocView"
"Major mode in DocView buffers.
You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
-toggle between display as a set of images and display as text."
+toggle between displaying the document or editing it as text."
:group 'doc-view
(make-local-variable 'doc-view-current-files)
(make-local-variable 'doc-view-current-doc)
@@ -787,20 +768,65 @@
(make-local-variable 'doc-view-current-search-matches)
(setq doc-view-current-doc (buffer-file-name))
(insert-file-contents doc-view-current-doc)
- (use-local-map doc-view-mode-text-map)
- (setq mode-name "DocView[text]"
- doc-view-current-display 'text
+ (use-local-map doc-view-mode-map)
+ (setq mode-name "DocView"
buffer-read-only t
revert-buffer-function 'doc-view-reconvert-doc)
;; Switch to image display if possible
(if (and (display-images-p)
- (image-type-available-p 'png)
- (not (get-text-property (point-min) 'display)))
- (doc-view-toggle-display))
- (message
- "%s"
- (substitute-command-keys
- "Type \\[doc-view-toggle-display] to toggle between image and text display.")))
+ (image-type-available-p 'png))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (doc-view-buffer-message)
+ (setq doc-view-current-page (or doc-view-current-page 1))
+ (if (file-exists-p (doc-view-current-cache-dir))
+ (progn
+ (message "DocView: using cached files!")
+ (doc-view-display doc-view-current-doc))
+ (doc-view-convert-current-doc))
+ (use-local-map doc-view-mode-map)
+ (message
+ "%s"
+ (substitute-command-keys
+ (concat "Type \\[doc-view-toggle-display] to toggle between "
+ "editing or viewing the document."))))
+ (message
+ "%s"
+ (substitute-command-keys
+ (concat "No image (png) support available. Type \\[doc-view-toggle-display] "
+ "to switch to an editing mode.")))))
+
+;;;###autoload
+(define-minor-mode doc-view-minor-mode
+ "Toggle Doc view minor mode.
+With arg, turn Doc view minor mode on if arg is positive, off otherwise.
+See the command `doc-view-mode' for more information on this mode."
+ nil " DocView" doc-view-minor-mode-map
+ :group 'doc-view
+ (when doc-view-minor-mode
+ (add-hook 'change-major-mode-hook (lambda () (doc-view-minor-mode -1)) nil t)
+ (message
+ "%s"
+ (substitute-command-keys
+ "Type \\[doc-view-toggle-display] to toggle between editing or viewing the document."))))
+
+;;;###autoload
+(defun doc-view-mode-maybe ()
+ "Set major or minor mode for document files.
+For PostScript files use the editing mode found in
+`auto-mode-alist' and enable `doc-view-minor-mode', else use
+`doc-view-mode'.
+
+See commands `doc-view-mode' and `doc-view-minor-mode' for more
+information on these modes."
+ (interactive)
+ (let ((mode-alist (doc-view-clean-auto-mode-alist)))
+ (if (string-match "^[eE]?[pP][sS]$" (file-name-extension buffer-file-name))
+ (let ((auto-mode-alist mode-alist)
+ (magic-mode-alist nil))
+ (set-auto-mode)
+ (doc-view-minor-mode 1))
+ (doc-view-mode))))
(defun doc-view-clear-cache ()
"Delete the whole cache (`doc-view-cache-directory')."
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11999
diff -u -r1.11999 ChangeLog
--- lisp/ChangeLog 20 Oct 2007 06:53:05 -0000 1.11999
+++ lisp/ChangeLog 20 Oct 2007 10:24:27 -0000
@@ -1,3 +1,23 @@
+2007-10-20 Tassilo Horn <tassilo@member.fsf.org>
+
+ * files.el (auto-mode-alist): Change entries: pdf -> ps-mode, dvi
+ -> fundamental-mode.
+
+ * doc-view.el (doc-view-mode): Remove text/image switching code.
+ (doc-view-minor-mode): New minor mode.
+ (doc-view-mode-maybe): New function.
+ (doc-view-minor-mode-map): New keymap.
+ (doc-view-mode-text-map): Remove keymap.
+ (doc-view-mode-map): New binding K to kill the converter process.
+ (doc-view-current-display): Remove variable.
+ (doc-vie w-buffer-message): Mention new binding K.
+ (doc-view-displa y-maybe): Remove function.
+ (doc-view-pdf/ps->png): Timer calls d-v-display instead
+ d-v-display-maybe.
+ (doc-view-mode-map): Use image-mode scrolling for mouse-wheel.
+ (doc-view-ps->pdf): Resort args to make ps2pdf happy.
+ (doc-view-clean-auto-mode-alist): New function.
+
2007-10-20 Dan Nicolaescu <dann@ics.uci.edu>
* term/x-win.el (x-gtk-stock-map, icon-map-list)
[-- Attachment #3: Type: text/plain, Size: 14 bytes --]
Bye,
Tassilo
[-- Attachment #4: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-10-20 10:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-19 12:57 Yet another doc-view patch Tassilo Horn
2007-10-20 3:30 ` Richard Stallman
2007-10-20 10:31 ` Tassilo Horn
2007-10-20 10:32 ` Tassilo Horn
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.