* doc-view compilation warnings @ 2007-10-21 2:38 Miles Bader 2007-10-21 8:55 ` Tassilo Horn 0 siblings, 1 reply; 38+ messages in thread From: Miles Bader @ 2007-10-21 2:38 UTC (permalink / raw) To: emacs-devel doc-view.el:746:33:Warning: Function `remove-if' from cl package called at runtime (etc) -miles -- Americans are broad-minded people. They'll accept the fact that a person can be an alcoholic, a dope fiend, a wife beater, and even a newspaperman, but if a man doesn't drive, there is something wrong with him. -- Art Buchwald ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-21 2:38 doc-view compilation warnings Miles Bader @ 2007-10-21 8:55 ` Tassilo Horn 2007-10-22 9:00 ` Richard Stallman 0 siblings, 1 reply; 38+ messages in thread From: Tassilo Horn @ 2007-10-21 8:55 UTC (permalink / raw) To: emacs-devel Miles Bader <miles@gnu.org> writes: Hi Miles, > doc-view.el:746:33:Warning: Function `remove-if' from cl package called at > runtime > (etc) Yes, I know. I'll fix those after my latest patch got applied. So what is the convention? Is calling a cl-function at runtime strictly forbidden? Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-21 8:55 ` Tassilo Horn @ 2007-10-22 9:00 ` Richard Stallman 2007-10-23 13:32 ` Tassilo Horn 0 siblings, 1 reply; 38+ messages in thread From: Richard Stallman @ 2007-10-22 9:00 UTC (permalink / raw) To: Tassilo Horn; +Cc: emacs-devel Yes, I know. I'll fix those after my latest patch got applied. So what is the convention? Is calling a cl-function at runtime strictly forbidden? Yes. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-22 9:00 ` Richard Stallman @ 2007-10-23 13:32 ` Tassilo Horn 2007-10-23 14:30 ` Dan Nicolaescu 2007-10-24 2:49 ` Richard Stallman 0 siblings, 2 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-23 13:32 UTC (permalink / raw) To: rms; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 648 bytes --] Richard Stallman <rms@gnu.org> writes: > Yes, I know. I'll fix those after my latest patch got applied. > So what is the convention? Is calling a cl-function at runtime > strictly forbidden? > > Yes. Ok, this patch fixes this issue plus the "open dvi/pdf files with doc-view and ps-files with ps-mode by default" issue. (See message <877ilj45zn.fsf@baldur.tsdh.de> and its follow-ups.) The only thing that remains is to find another keybinding for toggling between editing and viewing with doc-view, because ps-mode already uses `C-c C-c'. Suggestions? The patch is also at http://www.tsdh.de/stuff/doc-view.patch Bye, Tassilo [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: doc-view.patch --] [-- Type: text/x-patch, Size: 15960 bytes --] Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.936 diff -u -r1.936 files.el --- lisp/files.el 21 Oct 2007 10:48:28 -0000 1.936 +++ lisp/files.el 23 Oct 2007 12:53:00 -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 23 Oct 2007 12:53:01 -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,6 +355,37 @@ (when (eq major-mode 'doc-view-mode) (kill-buffer (current-buffer)))) +(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. +It's a subdirectory of `doc-view-cache-directory'." + (if doc-view-current-cache-dir + doc-view-current-cache-dir + (setq doc-view-current-cache-dir + (file-name-as-directory + (concat (file-name-as-directory doc-view-cache-directory) + (let ((doc doc-view-current-doc)) + (concat (file-name-nondirectory doc) + "-" + (with-temp-buffer + (insert-file-contents-literally doc) + (md5 (current-buffer)))))))))) + +(defun doc-view-remove-if (predicate list) + "Return LIST with all items removed that satisfy PREDICATE." + (let (new-list) + (dolist (item list (nreverse new-list)) + (when (not (funcall predicate item)) + (setq new-list (cons item new-list)))))) + ;;;; Conversion Functions (defun doc-view-reconvert-doc (&rest args) @@ -368,21 +398,7 @@ ;; 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-current-cache-dir () - "Return the directory where the png files of the current doc should be saved. -It's a subdirectory of `doc-view-cache-directory'." - (if doc-view-current-cache-dir - doc-view-current-cache-dir - (setq doc-view-current-cache-dir - (file-name-as-directory - (concat (file-name-as-directory doc-view-cache-directory) - (let ((doc doc-view-current-doc)) - (with-temp-buffer - (insert-file-contents-literally doc) - (md5 (current-buffer))))))))) + (doc-view-mode))) (defun doc-view-dvi->pdf-sentinel (proc event) "If DVI->PDF conversion was successful, convert the PDF to PNG now." @@ -439,7 +455,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 +498,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 +516,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 +593,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 +615,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 @@ -742,8 +732,9 @@ (defun doc-view-search-next-match (arg) "Go to the ARGth next matching page." (interactive "p") - (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((next-pages (doc-view-remove-if + (lambda (i) (<= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) next-pages)))) (if page (doc-view-goto-page page) @@ -755,8 +746,9 @@ (defun doc-view-search-previous-match (arg) "Go to the ARGth previous matching page." (interactive "p") - (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((prev-pages (doc-view-remove-if + (lambda (i) (>= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) (nreverse prev-pages))))) (if page (doc-view-goto-page page) @@ -773,7 +765,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 +779,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.12034 diff -u -r1.12034 ChangeLog --- lisp/ChangeLog 23 Oct 2007 08:42:39 -0000 1.12034 +++ lisp/ChangeLog 23 Oct 2007 12:53:08 -0000 @@ -1,3 +1,27 @@ +2007-10-23 Tassilo Horn <tassilo@member.fsf.org> + + * 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. + (doc-view-current-cache-dir): Better cache dir naming. + (doc-view-remove-if): New function. + (doc-view-search-next-match, doc-view-search-previous-match): Use + it. + + * files.el (auto-mode-alist): Change entries: pdf -> ps-mode, dvi + -> fundamental-mode. + 2007-10-23 Katsumi Yamaoka <yamaoka@jpl.org> * emacs-lisp/advice.el (ad-make-advised-docstring): [-- Attachment #3: 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] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 13:32 ` Tassilo Horn @ 2007-10-23 14:30 ` Dan Nicolaescu 2007-10-23 15:54 ` Tassilo Horn 2007-10-24 2:49 ` Richard Stallman 2007-10-24 2:49 ` Richard Stallman 1 sibling, 2 replies; 38+ messages in thread From: Dan Nicolaescu @ 2007-10-23 14:30 UTC (permalink / raw) To: rms; +Cc: emacs-devel Tassilo Horn <tassilo@member.fsf.org> writes: > Richard Stallman <rms@gnu.org> writes: > > > Yes, I know. I'll fix those after my latest patch got applied. > > So what is the convention? Is calling a cl-function at runtime > > strictly forbidden? > > > > Yes. > > Ok, this patch fixes this issue plus the "open dvi/pdf files with > doc-view and ps-files with ps-mode by default" issue. (See message > <877ilj45zn.fsf@baldur.tsdh.de> and its follow-ups.) > > The only thing that remains is to find another keybinding for toggling > between editing and viewing with doc-view, because ps-mode already uses > `C-c C-c'. Suggestions? Please add ChangeLog entries when sending patches. > The patch is also at http://www.tsdh.de/stuff/doc-view.patch > > --- lisp/files.el 21 Oct 2007 10:48:28 -0000 1.936 > +++ lisp/files.el 23 Oct 2007 12:53:00 -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 23 Oct 2007 12:53:01 -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) Given that you are changing auto-mode-alist alist directly, why not put all the auto-mode-alist manipulation in files.el? It's a bit confusing to see this done in 2 places. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 14:30 ` Dan Nicolaescu @ 2007-10-23 15:54 ` Tassilo Horn 2007-10-23 16:07 ` Dan Nicolaescu 2007-10-24 8:32 ` Richard Stallman 2007-10-24 2:49 ` Richard Stallman 1 sibling, 2 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-23 15:54 UTC (permalink / raw) To: Dan Nicolaescu; +Cc: rms, emacs-devel Dan Nicolaescu <dann@ics.uci.edu> writes: Hi Dan, > Please add ChangeLog entries when sending patches. The patch contains ChangeLog entries. (The last part of it.) > > The patch is also at http://www.tsdh.de/stuff/doc-view.patch > > > > --- lisp/files.el 21 Oct 2007 10:48:28 -0000 1.936 > > +++ lisp/files.el 23 Oct 2007 12:53:00 -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 23 Oct 2007 12:53:01 -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) > > Given that you are changing auto-mode-alist alist directly, why not > put all the auto-mode-alist manipulation in files.el? It's a bit > confusing to see this done in 2 places. This way it only affects users that want to use doc-view (by requiring it explicitly). If we say that it should be loaded by default, then I agree with you. But I'm sure there are a lot people that prefer it not to be loaded by default. Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 15:54 ` Tassilo Horn @ 2007-10-23 16:07 ` Dan Nicolaescu 2007-10-23 17:50 ` Tassilo Horn 2007-10-24 8:32 ` Richard Stallman 2007-10-24 8:32 ` Richard Stallman 1 sibling, 2 replies; 38+ messages in thread From: Dan Nicolaescu @ 2007-10-23 16:07 UTC (permalink / raw) To: rms; +Cc: emacs-devel Tassilo Horn <tassilo@member.fsf.org> writes: > Dan Nicolaescu <dann@ics.uci.edu> writes: > > Hi Dan, > > > Please add ChangeLog entries when sending patches. > > The patch contains ChangeLog entries. (The last part of it.) It is not a good idea to do the add the ChangeLog entry as a diff, it rarely still applies cleanly at the time it is checked in. Include it as plain text before that patch, so that it is easier to see what the patch is about. > > > The patch is also at http://www.tsdh.de/stuff/doc-view.patch > > > > > > --- lisp/files.el 21 Oct 2007 10:48:28 -0000 1.936 > > > +++ lisp/files.el 23 Oct 2007 12:53:00 -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 23 Oct 2007 12:53:01 -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) > > > > Given that you are changing auto-mode-alist alist directly, why not > > put all the auto-mode-alist manipulation in files.el? It's a bit > > confusing to see this done in 2 places. > > This way it only affects users that want to use doc-view (by requiring > it explicitly). If we say that it should be loaded by default, then I > agree with you. But I'm sure there are a lot people that prefer it not > to be loaded by default. I am not sure I get what you are trying to say. Adding autoloads like that will result that code to be loaded by default... ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 16:07 ` Dan Nicolaescu @ 2007-10-23 17:50 ` Tassilo Horn 2007-10-23 18:35 ` Dan Nicolaescu 2007-10-24 8:32 ` Richard Stallman 1 sibling, 1 reply; 38+ messages in thread From: Tassilo Horn @ 2007-10-23 17:50 UTC (permalink / raw) To: Dan Nicolaescu; +Cc: rms, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1996 bytes --] Dan Nicolaescu <dann@ics.uci.edu> writes: > > The patch contains ChangeLog entries. (The last part of it.) > > It is not a good idea to do the add the ChangeLog entry as a diff, it > rarely still applies cleanly at the time it is checked in. Include it > as plain text before that patch, so that it is easier to see what the > patch is about. Ok, here's the lisp/ChangeLog entry: --8<---------------cut here---------------start------------->8--- 2007-10-23 Tassilo Horn <tassilo@member.fsf.org> * 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. (doc-view-current-cache-dir): Better cache dir naming. (doc-view-remove-if): New function. (doc-view-search-next-match, doc-view-search-previous-match): Use it. * files.el (auto-mode-alist): Change entries: pdf -> ps-mode, dvi -> fundamental-mode. --8<---------------cut here---------------end--------------->8--- > > This way it only affects users that want to use doc-view (by > > requiring it explicitly). If we say that it should be loaded by > > default, then I agree with you. But I'm sure there are a lot > > people that prefer it not to be loaded by default. > > I am not sure I get what you are trying to say. Adding autoloads like > that will result that code to be loaded by default... Yes, you're right. So I removed the autoload cookies there and from `doc-view-mode-maybe'. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: doc-view.patch --] [-- Type: text/x-patch, Size: 14471 bytes --] Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.936 diff -u -r1.936 files.el --- lisp/files.el 21 Oct 2007 10:48:28 -0000 1.936 +++ lisp/files.el 23 Oct 2007 17:49:05 -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 23 Oct 2007 17:49:05 -0000 @@ -104,6 +104,10 @@ (require 'image-mode) (eval-when-compile (require 'cl)) +(push '("\\.[eE]?[pP][sS]\\'" . doc-view-mode-maybe) auto-mode-alist) +(push '("\\.[Dd][Vv][Ii]\\'" . doc-view-mode-maybe) auto-mode-alist) +(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,6 +355,37 @@ (when (eq major-mode 'doc-view-mode) (kill-buffer (current-buffer)))) +(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. +It's a subdirectory of `doc-view-cache-directory'." + (if doc-view-current-cache-dir + doc-view-current-cache-dir + (setq doc-view-current-cache-dir + (file-name-as-directory + (concat (file-name-as-directory doc-view-cache-directory) + (let ((doc doc-view-current-doc)) + (concat (file-name-nondirectory doc) + "-" + (with-temp-buffer + (insert-file-contents-literally doc) + (md5 (current-buffer)))))))))) + +(defun doc-view-remove-if (predicate list) + "Return LIST with all items removed that satisfy PREDICATE." + (let (new-list) + (dolist (item list (nreverse new-list)) + (when (not (funcall predicate item)) + (setq new-list (cons item new-list)))))) + ;;;; Conversion Functions (defun doc-view-reconvert-doc (&rest args) @@ -368,21 +398,7 @@ ;; 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-current-cache-dir () - "Return the directory where the png files of the current doc should be saved. -It's a subdirectory of `doc-view-cache-directory'." - (if doc-view-current-cache-dir - doc-view-current-cache-dir - (setq doc-view-current-cache-dir - (file-name-as-directory - (concat (file-name-as-directory doc-view-cache-directory) - (let ((doc doc-view-current-doc)) - (with-temp-buffer - (insert-file-contents-literally doc) - (md5 (current-buffer))))))))) + (doc-view-mode))) (defun doc-view-dvi->pdf-sentinel (proc event) "If DVI->PDF conversion was successful, convert the PDF to PNG now." @@ -439,7 +455,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 +498,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 +516,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 +593,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 +615,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 @@ -742,8 +732,9 @@ (defun doc-view-search-next-match (arg) "Go to the ARGth next matching page." (interactive "p") - (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((next-pages (doc-view-remove-if + (lambda (i) (<= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) next-pages)))) (if page (doc-view-goto-page page) @@ -755,8 +746,9 @@ (defun doc-view-search-previous-match (arg) "Go to the ARGth previous matching page." (interactive "p") - (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((prev-pages (doc-view-remove-if + (lambda (i) (>= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) (nreverse prev-pages))))) (if page (doc-view-goto-page page) @@ -773,7 +765,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 +779,64 @@ (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.")))) + +(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')." [-- 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] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 17:50 ` Tassilo Horn @ 2007-10-23 18:35 ` Dan Nicolaescu 2007-10-23 18:41 ` Tassilo Horn 0 siblings, 1 reply; 38+ messages in thread From: Dan Nicolaescu @ 2007-10-23 18:35 UTC (permalink / raw) To: rms; +Cc: emacs-devel Tassilo Horn <tassilo@member.fsf.org> writes: > Dan Nicolaescu <dann@ics.uci.edu> writes: > > > > This way it only affects users that want to use doc-view (by > > > requiring it explicitly). If we say that it should be loaded by > > > default, then I agree with you. But I'm sure there are a lot > > > people that prefer it not to be loaded by default. > > > > I am not sure I get what you are trying to say. Adding autoloads like > > that will result that code to be loaded by default... > > Yes, you're right. So I removed the autoload cookies there and from > `doc-view-mode-maybe'. > > > +(push '("\\.[eE]?[pP][sS]\\'" . doc-view-mode-maybe) auto-mode-alist) > +(push '("\\.[Dd][Vv][Ii]\\'" . doc-view-mode-maybe) auto-mode-alist) > +(push '("\\.[Pp][Dd][Ff]\\'" . doc-view-mode-maybe) auto-mode-alist) In general loading a file should not have side effects like this. IMHO, it is not idea to do things this way... ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 18:35 ` Dan Nicolaescu @ 2007-10-23 18:41 ` Tassilo Horn 2007-10-23 19:00 ` Stefan Monnier 2007-10-24 8:32 ` Richard Stallman 0 siblings, 2 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-23 18:41 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman Dan Nicolaescu <dann@ics.uci.edu> writes: > > +(push '("\\.[eE]?[pP][sS]\\'" . doc-view-mode-maybe) auto-mode-alist) > > +(push '("\\.[Dd][Vv][Ii]\\'" . doc-view-mode-maybe) auto-mode-alist) > > +(push '("\\.[Pp][Dd][Ff]\\'" . doc-view-mode-maybe) auto-mode-alist) > > In general loading a file should not have side effects like this. > IMHO, it is not idea to do things this way... So what would you suggest? A function `doc-view-initialize' that does this? Oh, and the code has another problem: `push' is a cl function which may not be used at runtime... Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 18:41 ` Tassilo Horn @ 2007-10-23 19:00 ` Stefan Monnier 2007-10-23 20:00 ` Tassilo Horn 2007-10-24 8:32 ` Richard Stallman 1 sibling, 1 reply; 38+ messages in thread From: Stefan Monnier @ 2007-10-23 19:00 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman >> > +(push '("\\.[eE]?[pP][sS]\\'" . doc-view-mode-maybe) auto-mode-alist) >> > +(push '("\\.[Dd][Vv][Ii]\\'" . doc-view-mode-maybe) auto-mode-alist) >> > +(push '("\\.[Pp][Dd][Ff]\\'" . doc-view-mode-maybe) auto-mode-alist) >> >> In general loading a file should not have side effects like this. >> IMHO, it is not idea to do things this way... > So what would you suggest? A function `doc-view-initialize' that does > this? You could put it directly into files.el. Or (tho less good) put it into `doc-view-mode' (so loading the file doesn't have any side-effect, though using doc-view does). > Oh, and the code has another problem: `push' is a cl function which may > not be used at runtime... No: `push' has never been a CL function: it used to be a CL macro and nowadays it's a standard ELisp macro (tho CL replaces it with a turbocharged version of it). So you can use it alright (tho you may prefer add-to-list in order to avoid adding the entry several times). Stefan ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 19:00 ` Stefan Monnier @ 2007-10-23 20:00 ` Tassilo Horn 2007-10-23 21:53 ` Stefan Monnier 2007-10-24 8:33 ` Richard Stallman 0 siblings, 2 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-23 20:00 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman Stefan Monnier <monnier@iro.umontreal.ca> writes: Hi Stefan, >>> > +(push '("\\.[eE]?[pP][sS]\\'" . doc-view-mode-maybe) auto-mode-alist) >>> > +(push '("\\.[Dd][Vv][Ii]\\'" . doc-view-mode-maybe) auto-mode-alist) >>> > +(push '("\\.[Pp][Dd][Ff]\\'" . doc-view-mode-maybe) auto-mode-alist) >>> >>> In general loading a file should not have side effects like this. >>> IMHO, it is not idea to do things this way... > >> So what would you suggest? A function `doc-view-initialize' that >> does this? > > You could put it directly into files.el. That would load doc-view unconditionally when a user opens a pdf/ps/dvi file. That's ok with me, but others might think different. But someone should decide: Is loading doc-view when opening ps/pdf/dvi files ok? > Or (tho less good) put it into `doc-view-mode' (so loading the file > doesn't have any side-effect, though using doc-view does). But then a user would need to open a document and enable d-v-m manually in order to have it (or its minor mode) activated automatically when opening another doc. IMO a setup function would be better then. Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 20:00 ` Tassilo Horn @ 2007-10-23 21:53 ` Stefan Monnier 2007-10-24 7:59 ` Tassilo Horn 2007-10-24 8:33 ` Richard Stallman 1 sibling, 1 reply; 38+ messages in thread From: Stefan Monnier @ 2007-10-23 21:53 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman >>>> > +(push '("\\.[eE]?[pP][sS]\\'" . doc-view-mode-maybe) auto-mode-alist) >>>> > +(push '("\\.[Dd][Vv][Ii]\\'" . doc-view-mode-maybe) auto-mode-alist) >>>> > +(push '("\\.[Pp][Dd][Ff]\\'" . doc-view-mode-maybe) auto-mode-alist) >>>> >>>> In general loading a file should not have side effects like this. >>>> IMHO, it is not idea to do things this way... >> >>> So what would you suggest? A function `doc-view-initialize' that >>> does this? >> >> You could put it directly into files.el. > That would load doc-view unconditionally when a user opens a pdf/ps/dvi > file. That's ok with me, but others might think different. > But someone should decide: Is loading doc-view when opening ps/pdf/dvi > files ok? It doesn't look like a problem to me, as long as it doesn't show PS files using doc-view by default. Note that it may be simpler to setup auto-mode-alist to map *.ps to ps-mode and dvi and pdf files to doc-view-mode and then change ps-mode to activate doc-view-minor-mode explicitly and unconditionally. That will save you from defining doc-view-mode-maybe. I'd also be very happy to get rid of the doc-view-clean-auto-mode-alist monstrosity by just saying "if you're not using doc-view-minor-mode, then toggling off doc-view puts you in fundamental-mode", or if you want to be fancier, then save the previous major-mode when entering doc-view-mode (when possible) and reuse that value when exiting it (like picture-mode does). Stefan ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 21:53 ` Stefan Monnier @ 2007-10-24 7:59 ` Tassilo Horn 2007-10-24 11:40 ` Tassilo Horn 2007-10-24 13:55 ` doc-view compilation warnings Stefan Monnier 0 siblings, 2 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-24 7:59 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman Stefan Monnier <monnier@IRO.UMontreal.CA> writes: >> But someone should decide: Is loading doc-view when opening >> ps/pdf/dvi files ok? > > It doesn't look like a problem to me, as long as it doesn't show PS > files using doc-view by default. > > Note that it may be simpler to setup auto-mode-alist to map *.ps to > ps-mode and dvi and pdf files to doc-view-mode and then change ps-mode > to activate doc-view-minor-mode explicitly and unconditionally. That > will save you from defining doc-view-mode-maybe. Ok, I'll do that. But still: what keybinding can I use for toggling? ps-mode aldeady binds `C-c C-c'. Or maybe we should change the binding for `ps-run-clear' in ps-mode to some other key that `C-c C-c'? > I'd also be very happy to get rid of the > doc-view-clean-auto-mode-alist monstrosity by just saying "if you're > not using doc-view-minor-mode, then toggling off doc-view puts you in > fundamental-mode", I don't get you here. If someone has his buffer in d-v-m and toggles to an editing mode I can activate d-v-minor-mode unconditionally. > or if you want to be fancier, then save the previous major-mode when > entering doc-view-mode (when possible) and reuse that value when > exiting it (like picture-mode does). Ok, that sounds reasonable. And if there was no previous major mode (or it was doc-view-mode) I can fall back to fundamental mode. I'll implement those changes later today. Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-24 7:59 ` Tassilo Horn @ 2007-10-24 11:40 ` Tassilo Horn 2007-10-24 15:24 ` Tassilo Horn 2007-10-24 13:55 ` doc-view compilation warnings Stefan Monnier 1 sibling, 1 reply; 38+ messages in thread From: Tassilo Horn @ 2007-10-24 11:40 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman [-- Attachment #1: Type: text/plain, Size: 2675 bytes --] Tassilo Horn <tassilo@member.fsf.org> writes: >>> But someone should decide: Is loading doc-view when opening >>> ps/pdf/dvi files ok? >> >> It doesn't look like a problem to me, as long as it doesn't show PS >> files using doc-view by default. >> >> Note that it may be simpler to setup auto-mode-alist to map *.ps to >> ps-mode and dvi and pdf files to doc-view-mode and then change >> ps-mode to activate doc-view-minor-mode explicitly and >> unconditionally. That will save you from defining >> doc-view-mode-maybe. > > Ok, I'll do that. Done! > But still: what keybinding can I use for toggling? ps-mode aldeady > binds `C-c C-c'. Or maybe we should change the binding for > `ps-run-clear' in ps-mode to some other key that `C-c C-c'? Now ps-mode uses C-c C-l for ps-run-clear and doc-view uses C-c C-c as RMS suggested. >> I'd also be very happy to get rid of the >> doc-view-clean-auto-mode-alist monstrosity by just saying "if you're >> not using doc-view-minor-mode, then toggling off doc-view puts you in >> fundamental-mode", > > I don't get you here. If someone has his buffer in d-v-m and toggles to > an editing mode I can activate d-v-minor-mode unconditionally. > >> or if you want to be fancier, then save the previous major-mode when >> entering doc-view-mode (when possible) and reuse that value when >> exiting it (like picture-mode does). > > Ok, that sounds reasonable. And if there was no previous major mode > (or it was doc-view-mode) I can fall back to fundamental mode. Done! Here's the ChangeLog entry: --8<---------------cut here---------------start------------->8--- 2007-10-24 Tassilo Horn <tassilo@member.fsf.org> * progmodes/ps-mode.el (ps-mode-map): Change bindinc C-c C-c to C-c C-l and remove binding C-c v. * doc-view.el (doc-view-mode): Remove text/image switching code. Use plain defun. (doc-view-minor-mode): New minor mode. (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-view-buffer-message): Mention new binding K. (doc-view-display-maybe): Remove function. (doc-view-pdf/ps->png): Timer calls d-v-display instead d-v-display-maybe. (doc-view-ps->pdf): Resort args to make ps2pdf happy. (doc-view-current-cache-dir): Better cache dir naming. (doc-view-remove-if): New function. (doc-view-search-next-match, doc-view-search-previous-match): Use it. * files.el (auto-mode-alist): Change entries: pdf/dvi -> doc-view-mode, ps -> ps-mode. --8<---------------cut here---------------end--------------->8--- And here's the patch (or get it from [1]): [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: doc-view.patch --] [-- Type: text/x-patch, Size: 16352 bytes --] Index: lisp/progmodes/ps-mode.el =================================================================== RCS file: /sources/emacs/emacs/lisp/progmodes/ps-mode.el,v retrieving revision 1.21 diff -u -r1.21 ps-mode.el --- lisp/progmodes/ps-mode.el 26 Jul 2007 05:27:29 -0000 1.21 +++ lisp/progmodes/ps-mode.el 24 Oct 2007 10:34:56 -0000 @@ -408,7 +408,6 @@ (unless ps-mode-map (setq ps-mode-map (make-sparse-keymap)) - (define-key ps-mode-map "\C-cv" 'ps-mode-show-version) (define-key ps-mode-map "\C-c\C-v" 'ps-run-boundingbox) (define-key ps-mode-map "\C-c\C-u" 'ps-mode-uncomment-region) (define-key ps-mode-map "\C-c\C-t" 'ps-mode-epsf-rich) @@ -419,7 +418,7 @@ (define-key ps-mode-map "\C-c\C-o" 'ps-mode-comment-out-region) (define-key ps-mode-map "\C-c\C-k" 'ps-run-kill) (define-key ps-mode-map "\C-c\C-j" 'ps-mode-other-newline) - (define-key ps-mode-map "\C-c\C-c" 'ps-run-clear) + (define-key ps-mode-map "\C-c\C-l" 'ps-run-clear) (define-key ps-mode-map "\C-c\C-b" 'ps-run-buffer) (define-key ps-mode-map ">" 'ps-mode-r-gt) (define-key ps-mode-map "]" 'ps-mode-r-angle) @@ -530,7 +529,10 @@ t)) (set (make-local-variable 'comment-start) "%") ;; NOTE: `\' has a special meaning in strings only - (set (make-local-variable 'comment-start-skip) "%+[ \t]*")) + (set (make-local-variable 'comment-start-skip) "%+[ \t]*") + ;; enable doc-view-minor-mode => C-c C-c starts viewing the current ps file + ;; with doc-view-mode. + (doc-view-minor-mode 1)) (defun ps-mode-show-version () "Show current version of PostScript mode." Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.936 diff -u -r1.936 files.el --- lisp/files.el 21 Oct 2007 10:48:28 -0000 1.936 +++ lisp/files.el 24 Oct 2007 10:35:01 -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) + ("\\.[Dd][Vv][Ii]\\'" . doc-view-mode) + ("\\.[Pp][Dd][Ff]\\'" . doc-view-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 24 Oct 2007 10:35:02 -0000 @@ -102,7 +102,6 @@ (require 'dired) (require 'image-mode) -(eval-when-compile (require 'cl)) ;;;; Customization Options @@ -202,7 +201,7 @@ (defvar doc-view-current-info nil "Only used internally.") -(defvar doc-view-current-display nil +(defvar doc-view-previous-major-mode nil "Only used internally.") ;;;; DocView Keymaps @@ -224,6 +223,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 +242,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 +333,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,6 +353,28 @@ (when (eq major-mode 'doc-view-mode) (kill-buffer (current-buffer)))) +(defun doc-view-current-cache-dir () + "Return the directory where the png files of the current doc should be saved. +It's a subdirectory of `doc-view-cache-directory'." + (if doc-view-current-cache-dir + doc-view-current-cache-dir + (setq doc-view-current-cache-dir + (file-name-as-directory + (concat (file-name-as-directory doc-view-cache-directory) + (let ((doc doc-view-current-doc)) + (concat (file-name-nondirectory doc) + "-" + (with-temp-buffer + (insert-file-contents-literally doc) + (md5 (current-buffer)))))))))) + +(defun doc-view-remove-if (predicate list) + "Return LIST with all items removed that satisfy PREDICATE." + (let (new-list) + (dolist (item list (nreverse new-list)) + (when (not (funcall predicate item)) + (setq new-list (cons item new-list)))))) + ;;;; Conversion Functions (defun doc-view-reconvert-doc (&rest args) @@ -368,21 +387,7 @@ ;; 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-current-cache-dir () - "Return the directory where the png files of the current doc should be saved. -It's a subdirectory of `doc-view-cache-directory'." - (if doc-view-current-cache-dir - doc-view-current-cache-dir - (setq doc-view-current-cache-dir - (file-name-as-directory - (concat (file-name-as-directory doc-view-cache-directory) - (let ((doc doc-view-current-doc)) - (with-temp-buffer - (insert-file-contents-literally doc) - (md5 (current-buffer))))))))) + (doc-view-mode))) (defun doc-view-dvi->pdf-sentinel (proc event) "If DVI->PDF conversion was successful, convert the PDF to PNG now." @@ -439,7 +444,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 +487,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 +505,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 +582,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 +604,39 @@ 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 + (progn + (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) + ;; Switch to the previously used major mode or fall back to fundamental + ;; mode. + (if doc-view-previous-major-mode + (funcall doc-view-previous-major-mode) + (fundamental-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 @@ -742,8 +724,9 @@ (defun doc-view-search-next-match (arg) "Go to the ARGth next matching page." (interactive "p") - (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((next-pages (doc-view-remove-if + (lambda (i) (<= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) next-pages)))) (if page (doc-view-goto-page page) @@ -755,8 +738,9 @@ (defun doc-view-search-previous-match (arg) "Go to the ARGth previous matching page." (interactive "p") - (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((prev-pages (doc-view-remove-if + (lambda (i) (>= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) (nreverse prev-pages))))) (if page (doc-view-goto-page page) @@ -770,37 +754,69 @@ (put 'doc-view-mode 'mode-class 'special) ;;;###autoload -(define-derived-mode doc-view-mode nil "DocView" +(defun doc-view-mode () "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." - :group 'doc-view - (make-local-variable 'doc-view-current-files) - (make-local-variable 'doc-view-current-doc) - (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) - (setq doc-view-current-doc (buffer-file-name)) +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) + (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-doc) buffer-file-name) + (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) (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) + revert-buffer-function 'doc-view-reconvert-doc + major-mode 'doc-view-mode) ;; 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.")))) (defun doc-view-clear-cache () "Delete the whole cache (`doc-view-cache-directory')." [-- Attachment #3: Type: text/plain, Size: 69 bytes --] Bye, Tassilo __________ [1] http://www.tsdh.de/stuff/doc-view.patch [-- 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] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-24 11:40 ` Tassilo Horn @ 2007-10-24 15:24 ` Tassilo Horn 2007-10-26 10:52 ` doc-view.patch waiting for installation (was: doc-view compilation warnings) Tassilo Horn 0 siblings, 1 reply; 38+ messages in thread From: Tassilo Horn @ 2007-10-24 15:24 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman [-- Attachment #1: Type: text/plain, Size: 1303 bytes --] Stefan told me the patch is ok now, except that I should call `suppress-keymap' first in the keymap definition, not last. So here's an updated patch: --8<---------------cut here---------------start------------->8--- 2007-10-24 Tassilo Horn <tassilo@member.fsf.org> * progmodes/ps-mode.el (ps-mode-map): Change bindinc C-c C-c to C-c C-l and remove binding C-c v. * doc-view.el (doc-view-mode): Remove text/image switching code. Use plain defun. (doc-view-minor-mode): New minor mode. (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-view-buffer-message): Mention new binding K. (doc-view-display-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-current-cache-dir): Better cache dir naming. (doc-view-remove-if): New function. (doc-view-search-next-match, doc-view-search-previous-match): Use it. * files.el (auto-mode-alist): Change entries: pdf/dvi -> doc-view-mode, ps -> ps-mode. --8<---------------cut here---------------end--------------->8--- [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: doc-view.patch --] [-- Type: text/x-patch, Size: 16606 bytes --] Index: lisp/progmodes/ps-mode.el =================================================================== RCS file: /sources/emacs/emacs/lisp/progmodes/ps-mode.el,v retrieving revision 1.21 diff -u -r1.21 ps-mode.el --- lisp/progmodes/ps-mode.el 26 Jul 2007 05:27:29 -0000 1.21 +++ lisp/progmodes/ps-mode.el 24 Oct 2007 15:11:41 -0000 @@ -408,7 +408,6 @@ (unless ps-mode-map (setq ps-mode-map (make-sparse-keymap)) - (define-key ps-mode-map "\C-cv" 'ps-mode-show-version) (define-key ps-mode-map "\C-c\C-v" 'ps-run-boundingbox) (define-key ps-mode-map "\C-c\C-u" 'ps-mode-uncomment-region) (define-key ps-mode-map "\C-c\C-t" 'ps-mode-epsf-rich) @@ -419,7 +418,7 @@ (define-key ps-mode-map "\C-c\C-o" 'ps-mode-comment-out-region) (define-key ps-mode-map "\C-c\C-k" 'ps-run-kill) (define-key ps-mode-map "\C-c\C-j" 'ps-mode-other-newline) - (define-key ps-mode-map "\C-c\C-c" 'ps-run-clear) + (define-key ps-mode-map "\C-c\C-l" 'ps-run-clear) (define-key ps-mode-map "\C-c\C-b" 'ps-run-buffer) (define-key ps-mode-map ">" 'ps-mode-r-gt) (define-key ps-mode-map "]" 'ps-mode-r-angle) @@ -530,7 +529,10 @@ t)) (set (make-local-variable 'comment-start) "%") ;; NOTE: `\' has a special meaning in strings only - (set (make-local-variable 'comment-start-skip) "%+[ \t]*")) + (set (make-local-variable 'comment-start-skip) "%+[ \t]*") + ;; enable doc-view-minor-mode => C-c C-c starts viewing the current ps file + ;; with doc-view-mode. + (doc-view-minor-mode 1)) (defun ps-mode-show-version () "Show current version of PostScript mode." Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.936 diff -u -r1.936 files.el --- lisp/files.el 21 Oct 2007 10:48:28 -0000 1.936 +++ lisp/files.el 24 Oct 2007 15:11:47 -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) + ("\\.[Dd][Vv][Ii]\\'" . doc-view-mode) + ("\\.[Pp][Dd][Ff]\\'" . doc-view-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 24 Oct 2007 15:11:47 -0000 @@ -102,7 +102,6 @@ (require 'dired) (require 'image-mode) -(eval-when-compile (require 'cl)) ;;;; Customization Options @@ -202,13 +201,14 @@ (defvar doc-view-current-info nil "Only used internally.") -(defvar doc-view-current-display nil +(defvar doc-view-previous-major-mode nil "Only used internally.") ;;;; DocView Keymaps (defvar doc-view-mode-map (let ((map (make-sparse-keymap))) + (suppress-keymap map) ;; Navigation in the document (define-key map (kbd "n") 'doc-view-next-page) (define-key map (kbd "p") 'doc-view-previous-page) @@ -224,6 +224,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 +243,17 @@ (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 +333,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,6 +353,28 @@ (when (eq major-mode 'doc-view-mode) (kill-buffer (current-buffer)))) +(defun doc-view-current-cache-dir () + "Return the directory where the png files of the current doc should be saved. +It's a subdirectory of `doc-view-cache-directory'." + (if doc-view-current-cache-dir + doc-view-current-cache-dir + (setq doc-view-current-cache-dir + (file-name-as-directory + (concat (file-name-as-directory doc-view-cache-directory) + (let ((doc doc-view-current-doc)) + (concat (file-name-nondirectory doc) + "-" + (with-temp-buffer + (insert-file-contents-literally doc) + (md5 (current-buffer)))))))))) + +(defun doc-view-remove-if (predicate list) + "Return LIST with all items removed that satisfy PREDICATE." + (let (new-list) + (dolist (item list (nreverse new-list)) + (when (not (funcall predicate item)) + (setq new-list (cons item new-list)))))) + ;;;; Conversion Functions (defun doc-view-reconvert-doc (&rest args) @@ -368,21 +387,7 @@ ;; 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-current-cache-dir () - "Return the directory where the png files of the current doc should be saved. -It's a subdirectory of `doc-view-cache-directory'." - (if doc-view-current-cache-dir - doc-view-current-cache-dir - (setq doc-view-current-cache-dir - (file-name-as-directory - (concat (file-name-as-directory doc-view-cache-directory) - (let ((doc doc-view-current-doc)) - (with-temp-buffer - (insert-file-contents-literally doc) - (md5 (current-buffer))))))))) + (doc-view-mode))) (defun doc-view-dvi->pdf-sentinel (proc event) "If DVI->PDF conversion was successful, convert the PDF to PNG now." @@ -439,7 +444,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 +487,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 +505,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 +582,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 +604,39 @@ 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 + (progn + (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) + ;; Switch to the previously used major mode or fall back to fundamental + ;; mode. + (if doc-view-previous-major-mode + (funcall doc-view-previous-major-mode) + (fundamental-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 @@ -742,8 +724,9 @@ (defun doc-view-search-next-match (arg) "Go to the ARGth next matching page." (interactive "p") - (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((next-pages (doc-view-remove-if + (lambda (i) (<= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) next-pages)))) (if page (doc-view-goto-page page) @@ -755,8 +738,9 @@ (defun doc-view-search-previous-match (arg) "Go to the ARGth previous matching page." (interactive "p") - (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((prev-pages (doc-view-remove-if + (lambda (i) (>= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) (nreverse prev-pages))))) (if page (doc-view-goto-page page) @@ -770,37 +754,69 @@ (put 'doc-view-mode 'mode-class 'special) ;;;###autoload -(define-derived-mode doc-view-mode nil "DocView" +(defun doc-view-mode () "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." - :group 'doc-view - (make-local-variable 'doc-view-current-files) - (make-local-variable 'doc-view-current-doc) - (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) - (setq doc-view-current-doc (buffer-file-name)) +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) + (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-doc) buffer-file-name) + (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) (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) + revert-buffer-function 'doc-view-reconvert-doc + major-mode 'doc-view-mode) ;; 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.")))) (defun doc-view-clear-cache () "Delete the whole cache (`doc-view-cache-directory')." [-- 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] 38+ messages in thread
* doc-view.patch waiting for installation (was: doc-view compilation warnings) 2007-10-24 15:24 ` Tassilo Horn @ 2007-10-26 10:52 ` Tassilo Horn 2007-10-29 1:52 ` doc-view.patch waiting for installation Glenn Morris 0 siblings, 1 reply; 38+ messages in thread From: Tassilo Horn @ 2007-10-26 10:52 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman Hi all, since my patch (<87y7dsh6xt.fsf@baldur.tsdh.de>) was approved by Stefan and I made all changes suggested by RMS and others, would somebody go on and install it? Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view.patch waiting for installation 2007-10-26 10:52 ` doc-view.patch waiting for installation (was: doc-view compilation warnings) Tassilo Horn @ 2007-10-29 1:52 ` Glenn Morris 2007-10-29 9:36 ` Tassilo Horn 0 siblings, 1 reply; 38+ messages in thread From: Glenn Morris @ 2007-10-29 1:52 UTC (permalink / raw) To: emacs-devel Tassilo Horn wrote: > since my patch (<87y7dsh6xt.fsf@baldur.tsdh.de>) was approved by Stefan > and I made all changes suggested by RMS and others, would somebody go on > and install it? The supplied ChangeLog entry seems incomplete. Eg doc-view-toggle-display is not mentioned, nor is not requiring 'cl any more, nor doc-view-previous-major-mode, the stuff about "Use image-mode scrolling for mouse-wheel." seems not apply, etc. I got as far as this version: 2007-10-29 Tassilo Horn <tassilo@member.fsf.org> * doc-view.el: No longer require cl at compile time. (doc-view-current-display): Remove variable. (doc-view-previous-major-mode): New internal variable. (doc-view-mode-map): New binding K to kill the converter process. Remove doc-view-edit-doc binding. (doc-view-mode-text-map): Remove keymap. (doc-view-minor-mode-map): New keymap. (doc-view-kill-proc): Set doc-view-current-converter-process nil after killing process. (doc-view-current-cache-dir): Better cache dir naming. (doc-view-remove-if): New function. (doc-view-search-next-match, doc-view-search-previous-match): Use it. (doc-view-pdf/ps->png): Timer calls d-v-display instead d-v-display-maybe. (doc-view-ps->pdf): Resort args to make ps2pdf happy. (doc-view-convert-current-doc): Use doc-view-current-cache-dir as a function, not a variable. (doc-view-display-maybe): Remove function. (doc-view-buffer-message): Mention new binding K. (doc-view-toggle-display): Do stuff. *** FIXME (doc-view-mode): Remove text/image switching code. Use plain defun. (doc-view-minor-mode): New minor mode. * progmodes/ps-mode.el (ps-mode): Enable doc-view-minor-mode. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view.patch waiting for installation 2007-10-29 1:52 ` doc-view.patch waiting for installation Glenn Morris @ 2007-10-29 9:36 ` Tassilo Horn 2007-10-30 6:33 ` Glenn Morris 0 siblings, 1 reply; 38+ messages in thread From: Tassilo Horn @ 2007-10-29 9:36 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1665 bytes --] Glenn Morris <rgm@gnu.org> writes: Hi Glenn, > The supplied ChangeLog entry seems incomplete. Ups, sorry. I went through all changes of the updated version of my patch (attached to this mail). Here's the ChangeLog entry: --8<---------------cut here---------------start------------->8--- 2007-10-29 Tassilo Horn <tassilo@member.fsf.org> * doc-view.el: Remove cl-dependency. (doc-view-buffer-message): Mention new binding K. (doc-view-convert-current-doc): Use function d-v-current-cache-dir instead of variable. (doc-view-current-cache-dir): Better cache dir naming. (doc-view-current-display): Remove variable. (doc-view-edit-doc, doc-view-display-maybe): Remove functions. (doc-view-kill-proc): Set converter process to nil. (doc-view-minor-mode): New minor mode. (doc-view-minor-mode-map): New keymap. (doc-view-mode): Remove text/image switching code. Use plain defun. (doc-view-mode-map): New binding K kills converter process. Remove C-c C-e binding. (doc-view-mode-text-map): Remove keymap. (doc-view-pdf/ps->png): Timer calls d-v-display instead d-v-display-maybe. (doc-view-previous-major-mode): New variable. (doc-view-ps->pdf): Resort args to make ps2pdf happy. (doc-view-remove-if): New function. (doc-view-search-next-match, doc-view-search-previous-match): Use it. (doc-view-toggle-display): Toggle modes instead of display styles. (doc-view-reconvert-doc): Adapt to new way of doing things. * files.el (auto-mode-alist): Allow mixed-case for pdf and dvi extensions. * progmodes/ps-mode.el (ps-mode-map): Enable doc-view-minor-mode. --8<---------------cut here---------------end--------------->8--- Bye, Tassilo [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: doc-view.patch --] [-- Type: text/x-patch, Size: 15821 bytes --] Index: lisp/progmodes/ps-mode.el =================================================================== RCS file: /sources/emacs/emacs/lisp/progmodes/ps-mode.el,v retrieving revision 1.22 diff -u -r1.22 ps-mode.el --- lisp/progmodes/ps-mode.el 26 Oct 2007 09:53:14 -0000 1.22 +++ lisp/progmodes/ps-mode.el 29 Oct 2007 09:33:23 -0000 @@ -529,7 +529,10 @@ t)) (set (make-local-variable 'comment-start) "%") ;; NOTE: `\' has a special meaning in strings only - (set (make-local-variable 'comment-start-skip) "%+[ \t]*")) + (set (make-local-variable 'comment-start-skip) "%+[ \t]*") + ;; enable doc-view-minor-mode => C-c C-c starts viewing the current ps file + ;; with doc-view-mode. + (doc-view-minor-mode 1)) (defun ps-mode-show-version () "Show current version of PostScript mode." Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.937 diff -u -r1.937 files.el --- lisp/files.el 26 Oct 2007 14:25:17 -0000 1.937 +++ lisp/files.el 29 Oct 2007 09:33:29 -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) + ("\\.[Dd][Vv][Ii]\\'" . doc-view-mode) + ("\\.[Pp][Dd][Ff]\\'" . doc-view-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 29 Oct 2007 09:33:29 -0000 @@ -102,7 +102,6 @@ (require 'dired) (require 'image-mode) -(eval-when-compile (require 'cl)) ;;;; Customization Options @@ -202,13 +201,14 @@ (defvar doc-view-current-info nil "Only used internally.") -(defvar doc-view-current-display nil +(defvar doc-view-previous-major-mode nil "Only used internally.") ;;;; DocView Keymaps (defvar doc-view-mode-map (let ((map (make-sparse-keymap))) + (suppress-keymap map) ;; Navigation in the document (define-key map (kbd "n") 'doc-view-next-page) (define-key map (kbd "p") 'doc-view-previous-page) @@ -224,6 +224,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 +243,17 @@ (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 +333,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,6 +353,28 @@ (when (eq major-mode 'doc-view-mode) (kill-buffer (current-buffer)))) +(defun doc-view-current-cache-dir () + "Return the directory where the png files of the current doc should be saved. +It's a subdirectory of `doc-view-cache-directory'." + (if doc-view-current-cache-dir + doc-view-current-cache-dir + (setq doc-view-current-cache-dir + (file-name-as-directory + (concat (file-name-as-directory doc-view-cache-directory) + (let ((doc doc-view-current-doc)) + (concat (file-name-nondirectory doc) + "-" + (with-temp-buffer + (insert-file-contents-literally doc) + (md5 (current-buffer)))))))))) + +(defun doc-view-remove-if (predicate list) + "Return LIST with all items removed that satisfy PREDICATE." + (let (new-list) + (dolist (item list (nreverse new-list)) + (when (not (funcall predicate item)) + (setq new-list (cons item new-list)))))) + ;;;; Conversion Functions (defun doc-view-reconvert-doc (&rest args) @@ -368,21 +387,7 @@ ;; 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-current-cache-dir () - "Return the directory where the png files of the current doc should be saved. -It's a subdirectory of `doc-view-cache-directory'." - (if doc-view-current-cache-dir - doc-view-current-cache-dir - (setq doc-view-current-cache-dir - (file-name-as-directory - (concat (file-name-as-directory doc-view-cache-directory) - (let ((doc doc-view-current-doc)) - (with-temp-buffer - (insert-file-contents-literally doc) - (md5 (current-buffer))))))))) + (doc-view-mode))) (defun doc-view-dvi->pdf-sentinel (proc event) "If DVI->PDF conversion was successful, convert the PDF to PNG now." @@ -439,7 +444,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 +487,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 +505,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 +582,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 +604,39 @@ 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 + (progn + (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) + ;; Switch to the previously used major mode or fall back to fundamental + ;; mode. + (if doc-view-previous-major-mode + (funcall doc-view-previous-major-mode) + (fundamental-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 @@ -742,8 +724,9 @@ (defun doc-view-search-next-match (arg) "Go to the ARGth next matching page." (interactive "p") - (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((next-pages (doc-view-remove-if + (lambda (i) (<= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) next-pages)))) (if page (doc-view-goto-page page) @@ -755,8 +738,9 @@ (defun doc-view-search-previous-match (arg) "Go to the ARGth previous matching page." (interactive "p") - (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page)) - doc-view-current-search-matches)) + (let* ((prev-pages (doc-view-remove-if + (lambda (i) (>= (car i) doc-view-current-page)) + doc-view-current-search-matches)) (page (car (nth (1- arg) (nreverse prev-pages))))) (if page (doc-view-goto-page page) @@ -770,37 +754,69 @@ (put 'doc-view-mode 'mode-class 'special) ;;;###autoload -(define-derived-mode doc-view-mode nil "DocView" +(defun doc-view-mode () "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." - :group 'doc-view - (make-local-variable 'doc-view-current-files) - (make-local-variable 'doc-view-current-doc) - (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) - (setq doc-view-current-doc (buffer-file-name)) +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) + (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-doc) buffer-file-name) + (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) (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) + revert-buffer-function 'doc-view-reconvert-doc + major-mode 'doc-view-mode) ;; 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.")))) (defun doc-view-clear-cache () "Delete the whole cache (`doc-view-cache-directory')." [-- Attachment #3: 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] 38+ messages in thread
* Re: doc-view.patch waiting for installation 2007-10-29 9:36 ` Tassilo Horn @ 2007-10-30 6:33 ` Glenn Morris 2007-10-30 18:07 ` Case folding for auto-mode-alist (was: doc-view.patch waiting for installation) Reiner Steib 0 siblings, 1 reply; 38+ messages in thread From: Glenn Morris @ 2007-10-30 6:33 UTC (permalink / raw) To: emacs-devel Tassilo Horn wrote: > Here's the ChangeLog entry: Thanks, applied. > * files.el (auto-mode-alist): Allow mixed-case for pdf and dvi > extensions. Apart from that. I don't think people using .dVi as a file extension should be encouraged... :) ^ permalink raw reply [flat|nested] 38+ messages in thread
* Case folding for auto-mode-alist (was: doc-view.patch waiting for installation) 2007-10-30 6:33 ` Glenn Morris @ 2007-10-30 18:07 ` Reiner Steib 2007-10-30 19:00 ` Case folding for auto-mode-alist Stefan Monnier 0 siblings, 1 reply; 38+ messages in thread From: Reiner Steib @ 2007-10-30 18:07 UTC (permalink / raw) To: emacs-devel On Tue, Oct 30 2007, Glenn Morris wrote: > Tassilo Horn wrote: >> * files.el (auto-mode-alist): Allow mixed-case for pdf and dvi >> extensions. > > Apart from that. I don't think people using .dVi as a file extension > should be encouraged... :) There was some discussion about `auto-mode-alist' before the release of 22.1. IIRC it has been suggested to first go through it case-sensitively and if no match was found, try it ignoring case. http://thread.gmane.org/gmane.emacs.pretest.bugs/16071/focus=16288 ,---- | From: Richard Stallman | Subject: Re: python-mode.el doesn't associate python-mode with .PY files | Newsgroups: gmane.emacs.pretest.bugs | Date: 2006-12-30 18:23:42 GMT | | What was the conclusion on how to associate .PY files with python-mode? | And what about .TXT files, .HTM files, .TAR files, and so on? | | I think it is a mistake to do that, in general. | I would not object to a user option to enable such matching, | but it should not be enabled by default. `---- Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: Case folding for auto-mode-alist 2007-10-30 18:07 ` Case folding for auto-mode-alist (was: doc-view.patch waiting for installation) Reiner Steib @ 2007-10-30 19:00 ` Stefan Monnier 2007-10-31 7:47 ` Richard Stallman 0 siblings, 1 reply; 38+ messages in thread From: Stefan Monnier @ 2007-10-30 19:00 UTC (permalink / raw) To: emacs-devel >>> * files.el (auto-mode-alist): Allow mixed-case for pdf and dvi >>> extensions. >> >> Apart from that. I don't think people using .dVi as a file extension >> should be encouraged... :) > There was some discussion about `auto-mode-alist' before the release > of 22.1. IIRC it has been suggested to first go through it > case-sensitively and if no match was found, try it ignoring case. Yes, you can get that by setting auto-mode-case-fold. But for some reason that still escapes me, Richard is strongly opposed to activating it by default. Stefan ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: Case folding for auto-mode-alist 2007-10-30 19:00 ` Case folding for auto-mode-alist Stefan Monnier @ 2007-10-31 7:47 ` Richard Stallman 2007-10-31 15:19 ` Stefan Monnier 0 siblings, 1 reply; 38+ messages in thread From: Richard Stallman @ 2007-10-31 7:47 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel Yes, you can get that by setting auto-mode-case-fold. But for some reason that still escapes me, Richard is strongly opposed to activating it by default. Because it is too drastic for the actual problem, and likely to often be wrong. If a certain file name extension is normally used in different case patterns, let's make its element in auto-mode-alist match them all. That is not drastic, and it does the job. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: Case folding for auto-mode-alist 2007-10-31 7:47 ` Richard Stallman @ 2007-10-31 15:19 ` Stefan Monnier 2007-10-31 15:30 ` David Kastrup 0 siblings, 1 reply; 38+ messages in thread From: Stefan Monnier @ 2007-10-31 15:19 UTC (permalink / raw) To: rms; +Cc: emacs-devel >>>>> "Richard" == Richard Stallman <rms@gnu.org> writes: > Yes, you can get that by setting auto-mode-case-fold. > But for some reason that still escapes me, Richard is strongly opposed to > activating it by default. > Because it is too drastic for the actual problem, and likely to often > be wrong. Yes, that is your claim. I have seen no evidence that it will "likely" and "often" be "wrong". As a matter of fact I have seen no evidence that it will ever be "wrong". Stefan ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: Case folding for auto-mode-alist 2007-10-31 15:19 ` Stefan Monnier @ 2007-10-31 15:30 ` David Kastrup 2007-10-31 16:17 ` Stefan Monnier 0 siblings, 1 reply; 38+ messages in thread From: David Kastrup @ 2007-10-31 15:30 UTC (permalink / raw) To: Stefan Monnier; +Cc: rms, emacs-devel Stefan Monnier <monnier@iro.umontreal.ca> writes: >>>>>> "Richard" == Richard Stallman <rms@gnu.org> writes: > >> Yes, you can get that by setting auto-mode-case-fold. >> But for some reason that still escapes me, Richard is strongly opposed to >> activating it by default. > >> Because it is too drastic for the actual problem, and likely to often >> be wrong. > > Yes, that is your claim. I have seen no evidence that it will "likely" and > "often" be "wrong". As a matter of fact I have seen no evidence that it will > ever be "wrong". .c vs .C for C vs. C++ files is probably the most relevant item, and .Z vs .z for compress vs uh, pack? files could be one, though in practice one would uncompress both of those "legacy" formats with gunzip. -- David Kastrup ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: Case folding for auto-mode-alist 2007-10-31 15:30 ` David Kastrup @ 2007-10-31 16:17 ` Stefan Monnier 0 siblings, 0 replies; 38+ messages in thread From: Stefan Monnier @ 2007-10-31 16:17 UTC (permalink / raw) To: David Kastrup; +Cc: rms, emacs-devel >>> Yes, you can get that by setting auto-mode-case-fold. >>> But for some reason that still escapes me, Richard is strongly opposed to >>> activating it by default. >> >>> Because it is too drastic for the actual problem, and likely to often >>> be wrong. >> >> Yes, that is your claim. I have seen no evidence that it will "likely" and >> "often" be "wrong". As a matter of fact I have seen no evidence that it will >> ever be "wrong". > .c vs .C for C vs. C++ files is probably the most relevant item, and > .Z vs .z for compress vs uh, pack? files could be one, though in > practice one would uncompress both of those "legacy" formats with > gunzip. Thanks for playing: the code tries the case-non-folded name first and only if that one fails, does it fallback to case-folding, so the above examples all work correctly. I.e. enabling auto-mode-case-fold only changes the behavior in the case where the buffer would otherwise be put in fundamental-mode. So the only possible downside is if the mode chosen by auto-mode-case-fold is worse than fundamental-mode. Stefan ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-24 7:59 ` Tassilo Horn 2007-10-24 11:40 ` Tassilo Horn @ 2007-10-24 13:55 ` Stefan Monnier 2007-10-24 14:32 ` Tassilo Horn 1 sibling, 1 reply; 38+ messages in thread From: Stefan Monnier @ 2007-10-24 13:55 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman >> I'd also be very happy to get rid of the doc-view-clean-auto-mode-alist >> monstrosity by just saying "if you're not using doc-view-minor-mode, then >> toggling off doc-view puts you in fundamental-mode", > I don't get you here. If someone has his buffer in d-v-m and toggles to > an editing mode I can activate d-v-minor-mode unconditionally. AFAICT doc-view-clean-auto-mode-alist was used when toggling to editing in order to find the major mode to use while editing. So I suggest to simply use fundamental-mode (unless you're currently using doc-view-minor-mode in which case you don't need to change the major mode). Of course, you can activate the minor-mode after putting the buffer in fundamental-mode. Stefan ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-24 13:55 ` doc-view compilation warnings Stefan Monnier @ 2007-10-24 14:32 ` Tassilo Horn 0 siblings, 0 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-24 14:32 UTC (permalink / raw) To: emacs-devel; +Cc: Richard Stallman Stefan Monnier <monnier@iro.umontreal.ca> writes: >>> I'd also be very happy to get rid of the >>> doc-view-clean-auto-mode-alist monstrosity by just saying "if you're >>> not using doc-view-minor-mode, then toggling off doc-view puts you >>> in fundamental-mode", > >> I don't get you here. If someone has his buffer in d-v-m and toggles >> to an editing mode I can activate d-v-minor-mode unconditionally. > > AFAICT doc-view-clean-auto-mode-alist was used when toggling to > editing in order to find the major mode to use while editing. So I > suggest to simply use fundamental-mode (unless you're currently using > doc-view-minor-mode in which case you don't need to change the major > mode). Now I use the major mode that was used before toggling to doc-view-mode as you suggested. See <877ilckafs.fsf@baldur.tsdh.de>. Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 20:00 ` Tassilo Horn 2007-10-23 21:53 ` Stefan Monnier @ 2007-10-24 8:33 ` Richard Stallman 1 sibling, 0 replies; 38+ messages in thread From: Richard Stallman @ 2007-10-24 8:33 UTC (permalink / raw) To: Tassilo Horn; +Cc: emacs-devel That would load doc-view unconditionally when a user opens a pdf/ps/dvi file. That's ok with me, but others might think different. But someone should decide: Is loading doc-view when opening ps/pdf/dvi files ok? For opening pdf/dvi files, we want themto use doc-view by default. For PS files, we don't want doc-view to be the default mode choice, but it is ok if visiting a PS file loads doc-view. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 18:41 ` Tassilo Horn 2007-10-23 19:00 ` Stefan Monnier @ 2007-10-24 8:32 ` Richard Stallman 1 sibling, 0 replies; 38+ messages in thread From: Richard Stallman @ 2007-10-24 8:32 UTC (permalink / raw) To: Tassilo Horn; +Cc: emacs-devel So what would you suggest? A function `doc-view-initialize' that does this? Please add the appropriate elements to the definition of auto-mode-alist in files.el. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 16:07 ` Dan Nicolaescu 2007-10-23 17:50 ` Tassilo Horn @ 2007-10-24 8:32 ` Richard Stallman 1 sibling, 0 replies; 38+ messages in thread From: Richard Stallman @ 2007-10-24 8:32 UTC (permalink / raw) To: Dan Nicolaescu; +Cc: emacs-devel It is not a good idea to do the add the ChangeLog entry as a diff, it rarely still applies cleanly at the time it is checked in. Include it as plain text before that patch, so that it is easier to see what the patch is about. I agree, that is the best way. However, he's right in saying that he DID provide the change log. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 15:54 ` Tassilo Horn 2007-10-23 16:07 ` Dan Nicolaescu @ 2007-10-24 8:32 ` Richard Stallman 1 sibling, 0 replies; 38+ messages in thread From: Richard Stallman @ 2007-10-24 8:32 UTC (permalink / raw) To: Tassilo Horn; +Cc: dann, emacs-devel This way it only affects users that want to use doc-view (by requiring it explicitly). Doc view is the preferred way to look at PDF and DVI files. It should be enabled for everyone, by default! ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 14:30 ` Dan Nicolaescu 2007-10-23 15:54 ` Tassilo Horn @ 2007-10-24 2:49 ` Richard Stallman 1 sibling, 0 replies; 38+ messages in thread From: Richard Stallman @ 2007-10-24 2:49 UTC (permalink / raw) To: Dan Nicolaescu; +Cc: emacs-devel Given that you are changing auto-mode-alist alist directly, why not put all the auto-mode-alist manipulation in files.el? It's a bit confusing to see this done in 2 places. I agree -- having parts of the variable's value come from different files will be confusing for maintenance. If an installed package that wants an item in auto-mode-alist, it should go in the defvar for auto-mode-alist. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-23 13:32 ` Tassilo Horn 2007-10-23 14:30 ` Dan Nicolaescu @ 2007-10-24 2:49 ` Richard Stallman 2007-10-24 8:11 ` Tassilo Horn 1 sibling, 1 reply; 38+ messages in thread From: Richard Stallman @ 2007-10-24 2:49 UTC (permalink / raw) To: Tassilo Horn; +Cc: emacs-devel The only thing that remains is to find another keybinding for toggling between editing and viewing with doc-view, because ps-mode already uses `C-c C-c'. Suggestions? C-c C-c is good for this, for consistency with Image mode. So maybe ps-mode should change its C-c C-c binding to something else. Any suggestions for what to change it to? ps-mode also has a C-c v binding, which violates the Emacs conventions for major modes, so that should be changed (or just deleted). ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-24 2:49 ` Richard Stallman @ 2007-10-24 8:11 ` Tassilo Horn 2007-10-24 8:19 ` David Kastrup 2007-10-25 2:10 ` Richard Stallman 0 siblings, 2 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-24 8:11 UTC (permalink / raw) To: rms; +Cc: emacs-devel Richard Stallman <rms@gnu.org> writes: > The only thing that remains is to find another keybinding for > toggling between editing and viewing with doc-view, because > ps-mode already uses `C-c C-c'. Suggestions? > > C-c C-c is good for this, for consistency with Image mode. So maybe > ps-mode should change its C-c C-c binding to something else. Any > suggestions for what to change it to? C-c C-l for ps-run-c_l_ear, or C-c C-g because ps-run-clear clears the PostStript _g_raphics. In that case maybe we should rename that function to ps-mode-clear-graphics to keep the mnemonics. > ps-mode also has a C-c v binding, which violates the Emacs conventions > for major modes, so that should be changed (or just deleted). I'd delete it. A command that only messages the version of a package doesn't need a key binding. Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-24 8:11 ` Tassilo Horn @ 2007-10-24 8:19 ` David Kastrup 2007-10-25 2:10 ` Richard Stallman 1 sibling, 0 replies; 38+ messages in thread From: David Kastrup @ 2007-10-24 8:19 UTC (permalink / raw) To: rms; +Cc: emacs-devel Tassilo Horn <tassilo@member.fsf.org> writes: > Richard Stallman <rms@gnu.org> writes: > >> The only thing that remains is to find another keybinding for >> toggling between editing and viewing with doc-view, because >> ps-mode already uses `C-c C-c'. Suggestions? >> >> C-c C-c is good for this, for consistency with Image mode. So maybe >> ps-mode should change its C-c C-c binding to something else. Any >> suggestions for what to change it to? > > C-c C-l for ps-run-c_l_ear, or > C-c C-g because ps-run-clear clears the PostStript _g_raphics. Keybindings should not include C-g since that defaults to keyboard-quit which is used for aborting things in progress (which should include key sequences). -- David Kastrup ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-24 8:11 ` Tassilo Horn 2007-10-24 8:19 ` David Kastrup @ 2007-10-25 2:10 ` Richard Stallman 2007-10-25 8:09 ` Tassilo Horn 1 sibling, 1 reply; 38+ messages in thread From: Richard Stallman @ 2007-10-25 2:10 UTC (permalink / raw) To: Tassilo Horn; +Cc: emacs-devel C-c C-l for ps-run-c_l_ear, or C-c C-g because ps-run-clear clears the PostStript _g_raphics. C-c C-l is a good choice, because C-l clears the screen. I will make that change, and delete C-c v. ^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: doc-view compilation warnings 2007-10-25 2:10 ` Richard Stallman @ 2007-10-25 8:09 ` Tassilo Horn 0 siblings, 0 replies; 38+ messages in thread From: Tassilo Horn @ 2007-10-25 8:09 UTC (permalink / raw) To: rms; +Cc: emacs-devel Richard Stallman <rms@gnu.org> writes: > C-c C-l for ps-run-c_l_ear, or > C-c C-g because ps-run-clear clears the PostStript _g_raphics. > > C-c C-l is a good choice, because C-l clears the screen. > I will make that change, and delete C-c v. That change is already included in my latest patch. See message <87y7dsh6xt.fsf@baldur.tsdh.de>. Bye, Tassilo ^ permalink raw reply [flat|nested] 38+ messages in thread
end of thread, other threads:[~2007-10-31 16:17 UTC | newest] Thread overview: 38+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-10-21 2:38 doc-view compilation warnings Miles Bader 2007-10-21 8:55 ` Tassilo Horn 2007-10-22 9:00 ` Richard Stallman 2007-10-23 13:32 ` Tassilo Horn 2007-10-23 14:30 ` Dan Nicolaescu 2007-10-23 15:54 ` Tassilo Horn 2007-10-23 16:07 ` Dan Nicolaescu 2007-10-23 17:50 ` Tassilo Horn 2007-10-23 18:35 ` Dan Nicolaescu 2007-10-23 18:41 ` Tassilo Horn 2007-10-23 19:00 ` Stefan Monnier 2007-10-23 20:00 ` Tassilo Horn 2007-10-23 21:53 ` Stefan Monnier 2007-10-24 7:59 ` Tassilo Horn 2007-10-24 11:40 ` Tassilo Horn 2007-10-24 15:24 ` Tassilo Horn 2007-10-26 10:52 ` doc-view.patch waiting for installation (was: doc-view compilation warnings) Tassilo Horn 2007-10-29 1:52 ` doc-view.patch waiting for installation Glenn Morris 2007-10-29 9:36 ` Tassilo Horn 2007-10-30 6:33 ` Glenn Morris 2007-10-30 18:07 ` Case folding for auto-mode-alist (was: doc-view.patch waiting for installation) Reiner Steib 2007-10-30 19:00 ` Case folding for auto-mode-alist Stefan Monnier 2007-10-31 7:47 ` Richard Stallman 2007-10-31 15:19 ` Stefan Monnier 2007-10-31 15:30 ` David Kastrup 2007-10-31 16:17 ` Stefan Monnier 2007-10-24 13:55 ` doc-view compilation warnings Stefan Monnier 2007-10-24 14:32 ` Tassilo Horn 2007-10-24 8:33 ` Richard Stallman 2007-10-24 8:32 ` Richard Stallman 2007-10-24 8:32 ` Richard Stallman 2007-10-24 8:32 ` Richard Stallman 2007-10-24 2:49 ` Richard Stallman 2007-10-24 2:49 ` Richard Stallman 2007-10-24 8:11 ` Tassilo Horn 2007-10-24 8:19 ` David Kastrup 2007-10-25 2:10 ` Richard Stallman 2007-10-25 8:09 ` 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.