diff options
Diffstat (limited to 'lisp/doc-view.el')
| -rw-r--r-- | lisp/doc-view.el | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index fa54eef828d..0cfdc9a22d1 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -231,14 +231,37 @@ If this and `doc-view-dvipdfm-program' are set, :type 'file :group 'doc-view) -(defcustom doc-view-unoconv-program "unoconv" +(define-obsolete-variable-alias 'doc-view-unoconv-program + 'doc-view-odf->pdf-converter-program + "24.4") + +(defcustom doc-view-odf->pdf-converter-program + (cond + ((executable-find "soffice") "soffice") + ((executable-find "unoconv") "unoconv") + (t "soffice")) "Program to convert any file type readable by OpenOffice.org to PDF. Needed for viewing OpenOffice.org (and MS Office) files." - :version "24.1" + :version "24.4" :type 'file :group 'doc-view) +(defcustom doc-view-odf->pdf-converter-function + (cond + ((string-match "unoconv\\'" doc-view-odf->pdf-converter-program) + #'doc-view-odf->pdf-converter-unoconv) + ((string-match "soffice\\'" doc-view-odf->pdf-converter-program) + #'doc-view-odf->pdf-converter-soffice)) + "Function to call to convert a ODF file into a PDF file." + :type '(radio + (function-item doc-view-odf->pdf-converter-unoconv + :doc "Use unoconv") + (function-item doc-view-odf->pdf-converter-soffice + :doc "Use LibreOffice") + function) + :version "24.4") + (defcustom doc-view-ps2pdf-program "ps2pdf" "Program to convert PS files to PDF. @@ -367,6 +390,7 @@ Typically \"page-%s.png\".") (define-key map [remap forward-page] 'doc-view-next-page) (define-key map [remap backward-page] 'doc-view-previous-page) (define-key map (kbd "SPC") 'doc-view-scroll-up-or-next-page) + (define-key map (kbd "S-SPC") 'doc-view-scroll-down-or-previous-page) (define-key map (kbd "DEL") 'doc-view-scroll-down-or-previous-page) (define-key map (kbd "C-n") 'doc-view-next-line-or-next-page) (define-key map (kbd "<down>") 'doc-view-next-line-or-next-page) @@ -461,8 +485,7 @@ Typically \"page-%s.png\".") (defun doc-view-goto-page (page) "View the page given by PAGE." (interactive "nPage: ") - (let ((len (doc-view-last-page-number)) - (hscroll (window-hscroll))) + (let ((len (doc-view-last-page-number))) (if (< page 1) (setq page 1) (when (and (> page len) @@ -496,7 +519,6 @@ Typically \"page-%s.png\".") (format doc-view--image-file-pattern page) (doc-view-current-cache-dir)))) (doc-view-insert-image file :pointer 'arrow) - (set-window-hscroll (selected-window) hscroll) (when (and (not (file-exists-p file)) doc-view-current-converter-processes) ;; The PNG file hasn't been generated yet. @@ -663,7 +685,8 @@ It's a subdirectory of `doc-view-cache-directory'." (setq doc-view-current-cache-dir (file-name-as-directory (expand-file-name - (concat (file-name-nondirectory doc-view-buffer-file-name) + (concat (subst-char-in-string ?% ?_ ;; bug#13679 + (file-name-nondirectory doc-view-buffer-file-name)) "-" (let ((file doc-view-buffer-file-name)) (with-temp-buffer @@ -700,8 +723,8 @@ OpenDocument format)." (and doc-view-ghostscript-program (executable-find doc-view-ghostscript-program))) ((eq type 'odf) - (and doc-view-unoconv-program - (executable-find doc-view-unoconv-program) + (and doc-view-odf->pdf-converter-program + (executable-find doc-view-odf->pdf-converter-program) (doc-view-mode-p 'pdf))) ((eq type 'djvu) (executable-find "ddjvu")) @@ -903,14 +926,34 @@ If PAGE is nil, convert the whole document." ,@(if page `(,(format "%d" page)))) callback)) -(defun doc-view-odf->pdf (odf callback) +(defun doc-view-odf->pdf-converter-unoconv (odf callback) "Convert ODF to PDF asynchronously and call CALLBACK when finished. The converted PDF is put into the current cache directory, and it is named like ODF with the extension turned to pdf." - (doc-view-start-process "odf->pdf" doc-view-unoconv-program + (doc-view-start-process "odf->pdf" doc-view-odf->pdf-converter-program (list "-f" "pdf" "-o" (doc-view-current-cache-dir) odf) callback)) +(defun doc-view-odf->pdf-converter-soffice (odf callback) + "Convert ODF to PDF asynchronously and call CALLBACK when finished. +The converted PDF is put into the current cache directory, and it +is named like ODF with the extension turned to pdf." + ;; FIXME: soffice doesn't work when there's another running + ;; LibreOffice instance, in which case it returns success without + ;; actually doing anything. See LibreOffice bug + ;; https://bugs.freedesktop.org/show_bug.cgi?id=37531. A workaround + ;; is to start soffice with a separate UserInstallation directory. + (let ((tmp-user-install-dir (make-temp-file "libreoffice-docview" t))) + (doc-view-start-process "odf->pdf" doc-view-odf->pdf-converter-program + (list + (concat "-env:UserInstallation=file://" + tmp-user-install-dir) + "--headless" "--convert-to" "pdf" + "--outdir" (doc-view-current-cache-dir) odf) + (lambda () + (delete-directory tmp-user-install-dir t) + (funcall callback))))) + (defun doc-view-pdf/ps->png (pdf-ps png) ;; FIXME: Fix name and docstring to account for djvu&tiff. "Convert PDF-PS to PNG asynchronously." @@ -1058,7 +1101,7 @@ Those files are saved in the directory given by the function ;; The unoconv tool only supports an output directory, but no ;; file name. It's named like the input file with the ;; extension replaced by pdf. - (doc-view-odf->pdf doc-view-buffer-file-name + (funcall doc-view-odf->pdf-converter-function doc-view-buffer-file-name (lambda () ;; Rename to doc.pdf (rename-file opdf pdf) @@ -1265,6 +1308,8 @@ have the page we want to view." "[0-9]+") t) 'doc-view-sort)) + (unless (eq (length prev-pages) (length doc-view-current-files)) + (force-mode-line-update)) (dolist (win (or (get-buffer-window-list buffer nil t) (list t))) (let* ((page (doc-view-current-page win)) @@ -1334,8 +1379,6 @@ For now these keys are useful: (progn (doc-view-kill-proc) (setq buffer-read-only nil) - (remove-overlays (point-min) (point-max) 'doc-view t) - (setq-local image-mode-winprops-alist t) ;; Switch to the previously used major mode or fall back to ;; normal mode. (doc-view-fallback-mode) @@ -1678,6 +1721,7 @@ toggle between displaying the document or editing it as text. (mapcar (lambda (var) (cons var (symbol-value var))) '(doc-view-resolution image-mode-winprops-alist))))) + (remove-overlays (point-min) (point-max) 'doc-view t) (if doc-view-previous-major-mode (funcall doc-view-previous-major-mode) (let ((auto-mode-alist |
