org-e-man, org-e-groff: Update compile functions

* contrib/lisp/org-e-groff.el (org-e-groff-compile): Mirror recent
  changes about base filename and default-directory made to
  `org-e-latex-compile'.
* contrib/lisp/org-e-man.el (org-e-man-compile): Mirror recent changes
  about base filename and default-directory made to
  `org-e-latex-compile'.
This commit is contained in:
Nicolas Goaziou 2012-10-25 16:06:18 +02:00
parent 4bb5a06b15
commit ec40ba021a
2 changed files with 105 additions and 105 deletions

View File

@ -1989,63 +1989,63 @@ Return PDF file's name."
(org-e-groff-export-to-groff (org-e-groff-export-to-groff
subtreep visible-only body-only ext-plist pub-dir))) subtreep visible-only body-only ext-plist pub-dir)))
(defun org-e-groff-compile (grofffile) (defun org-e-groff-compile (file)
"Compile a Groff file. "Compile a Groff file.
GROFFFILE is the name of the file being compiled. Processing is FILE is the name of the file being compiled. Processing is done
done through the command specified in `org-e-groff-pdf-process'. through the command specified in `org-e-groff-pdf-process'.
Return PDF file name or an error if it couldn't be produced." Return PDF file name or an error if it couldn't be produced."
(let* ((wconfig (current-window-configuration)) (let* ((base-name (file-name-sans-extension (file-name-nondirectory file)))
(grofffile (file-truename grofffile)) (full-name (file-truename file))
(base (file-name-sans-extension grofffile)) (out-dir (file-name-directory file))
;; Make sure `default-directory' is set to FILE directory,
;; not to whatever value the current buffer may have.
(default-directory (file-name-directory full-name))
errors) errors)
(message (format "Processing Groff file %s ..." grofffile)) (message (format "Processing Groff file %s ..." file))
(unwind-protect (save-window-excursion
(progn (cond
(cond ;; A function is provided: Apply it.
;; A function is provided: Apply it. ((functionp org-e-groff-pdf-process)
((functionp org-e-groff-pdf-process) (funcall org-e-groff-pdf-process (shell-quote-argument file)))
(funcall org-e-groff-pdf-process (shell-quote-argument grofffile))) ;; A list is provided: Replace %b, %f and %o with appropriate
;; A list is provided: Replace %b, %f and %o with appropriate ;; values in each command before applying it. Output is
;; values in each command before applying it. Output is ;; redirected to "*Org PDF Groff Output*" buffer.
;; redirected to "*Org PDF Groff Output*" buffer. ((consp org-e-groff-pdf-process)
((consp org-e-groff-pdf-process) (let ((outbuf (get-buffer-create "*Org PDF Groff Output*")))
(let* ((out-dir (or (file-name-directory grofffile) "./")) (mapc
(outbuf (get-buffer-create "*Org PDF Groff Output*"))) (lambda (command)
(mapc (shell-command
(lambda (command) (replace-regexp-in-string
(shell-command "%b" (shell-quote-argument base-name)
(replace-regexp-in-string (replace-regexp-in-string
"%b" (shell-quote-argument base) "%f" (shell-quote-argument full-name)
(replace-regexp-in-string (replace-regexp-in-string
"%f" (shell-quote-argument grofffile) "%o" (shell-quote-argument out-dir) command t t)
(replace-regexp-in-string t t) t t)
"%o" (shell-quote-argument out-dir) command t t) outbuf))
t t) t t) org-e-groff-pdf-process)
outbuf)) ;; Collect standard errors from output buffer.
org-e-groff-pdf-process) (setq errors (org-e-groff-collect-errors outbuf))))
;; Collect standard errors from output buffer. (t (error "No valid command to process to PDF")))
(setq errors (org-e-groff-collect-errors outbuf)))) (let ((pdffile (concat out-dir base-name ".pdf")))
(t (error "No valid command to process to PDF"))) ;; Check for process failure. Provide collected errors if
(let ((pdffile (concat base ".pdf"))) ;; possible.
;; Check for process failure. Provide collected errors if (if (not (file-exists-p pdffile))
;; possible. (error (concat (format "PDF file %s wasn't produced" pdffile)
(if (not (file-exists-p pdffile)) (when errors (concat ": " errors))))
(error (concat (format "PDF file %s wasn't produced" pdffile) ;; Else remove log files, when specified, and signal end of
(when errors (concat ": " errors)))) ;; process to user, along with any error encountered.
;; Else remove log files, when specified, and signal end of (when org-e-groff-remove-logfiles
;; process to user, along with any error encountered. (dolist (ext org-e-groff-logfiles-extensions)
(when org-e-groff-remove-logfiles (let ((file (concat out-dir base-name "." ext)))
(dolist (ext org-e-groff-logfiles-extensions) (when (file-exists-p file) (delete-file file)))))
(let ((file (concat base "." ext))) (message (concat "Process completed"
(when (file-exists-p file) (delete-file file))))) (if (not errors) "."
(message (concat "Process completed" (concat " with errors: " errors)))))
(if (not errors) "." ;; Return output file name.
(concat " with errors: " errors))))) pdffile))))
;; Return output file name.
pdffile))
(set-window-configuration wconfig))))
(defun org-e-groff-collect-errors (buffer) (defun org-e-groff-collect-errors (buffer)
"Collect some kind of errors from \"groff\" output "Collect some kind of errors from \"groff\" output

View File

@ -253,8 +253,8 @@ string defines the replacement string for this quote."
"Commands to process a Man file to a PDF file. "Commands to process a Man file to a PDF file.
This is a list of strings, each of them will be given to the This is a list of strings, each of them will be given to the
shell as a command. %f in the command will be replaced by the shell as a command. %f in the command will be replaced by the
full file name, %b by the file base name \(i.e. without full file name, %b by the file base name (i.e. without directory
extension) and %o by the base directory of the file. and extension parts) and %o by the base directory of the file.
By default, Org uses 3 runs of to do the processing. By default, Org uses 3 runs of to do the processing.
@ -1261,62 +1261,62 @@ Return PDF file's name."
(org-e-man-export-to-man (org-e-man-export-to-man
subtreep visible-only body-only ext-plist pub-dir))) subtreep visible-only body-only ext-plist pub-dir)))
(defun org-e-man-compile (grofffile) (defun org-e-man-compile (file)
"Compile a Groff file. "Compile a Groff file.
GROFFFILE is the name of the file being compiled. Processing is FILE is the name of the file being compiled. Processing is done
done through the command specified in `org-e-man-pdf-process'. through the command specified in `org-e-man-pdf-process'.
Return PDF file name or an error if it couldn't be produced." Return PDF file name or an error if it couldn't be produced."
(let* ((wconfig (current-window-configuration)) (let* ((base-name (file-name-sans-extension (file-name-nondirectory file)))
(grofffile (file-truename grofffile)) (full-name (file-truename file))
(base (file-name-sans-extension grofffile)) (out-dir (file-name-directory file))
;; Make sure `default-directory' is set to FILE directory,
;; not to whatever value the current buffer may have.
(default-directory (file-name-directory full-name))
errors) errors)
(message (format "Processing Groff file %s ..." grofffile)) (message (format "Processing Groff file %s ..." file))
(unwind-protect (save-window-excursion
(progn (cond
(cond ;; A function is provided: Apply it.
;; A function is provided: Apply it. ((functionp org-e-man-pdf-process)
((functionp org-e-man-pdf-process) (funcall org-e-man-pdf-process (shell-quote-argument file)))
(funcall org-e-man-pdf-process (shell-quote-argument grofffile))) ;; A list is provided: Replace %b, %f and %o with appropriate
;; A list is provided: Replace %b, %f and %o with appropriate ;; values in each command before applying it. Output is
;; values in each command before applying it. Output is ;; redirected to "*Org PDF Groff Output*" buffer.
;; redirected to "*Org PDF Groff Output*" buffer. ((consp org-e-man-pdf-process)
((consp org-e-man-pdf-process) (let ((outbuf (get-buffer-create "*Org PDF Groff Output*")))
(let* ((out-dir (or (file-name-directory grofffile) "./")) (mapc
(outbuf (get-buffer-create "*Org PDF Groff Output*"))) (lambda (command)
(mapc (shell-command
(lambda (command) (replace-regexp-in-string
(shell-command "%b" (shell-quote-argument base-name)
(replace-regexp-in-string (replace-regexp-in-string
"%b" (shell-quote-argument base) "%f" (shell-quote-argument full-name)
(replace-regexp-in-string (replace-regexp-in-string
"%f" (shell-quote-argument grofffile) "%o" (shell-quote-argument out-dir) command t t) t t) t t)
(replace-regexp-in-string outbuf))
"%o" (shell-quote-argument out-dir) command t t) t t) t t) org-e-man-pdf-process)
outbuf)) ;; Collect standard errors from output buffer.
org-e-man-pdf-process) (setq errors (org-e-man-collect-errors outbuf))))
;; Collect standard errors from output buffer. (t (error "No valid command to process to PDF")))
(setq errors (org-e-man-collect-errors outbuf)))) (let ((pdffile (concat out-dir base-name ".pdf")))
(t (error "No valid command to process to PDF"))) ;; Check for process failure. Provide collected errors if
(let ((pdffile (concat base ".pdf"))) ;; possible.
;; Check for process failure. Provide collected errors if (if (not (file-exists-p pdffile))
;; possible. (error (concat (format "PDF file %s wasn't produced" pdffile)
(if (not (file-exists-p pdffile)) (when errors (concat ": " errors))))
(error (concat (format "PDF file %s wasn't produced" pdffile) ;; Else remove log files, when specified, and signal end of
(when errors (concat ": " errors)))) ;; process to user, along with any error encountered.
;; Else remove log files, when specified, and signal end of (when org-e-man-remove-logfiles
;; process to user, along with any error encountered. (dolist (ext org-e-man-logfiles-extensions)
(when org-e-man-remove-logfiles (let ((file (concat out-dir base-name "." ext)))
(dolist (ext org-e-man-logfiles-extensions) (when (file-exists-p file) (delete-file file)))))
(let ((file (concat base "." ext))) (message (concat "Process completed"
(when (file-exists-p file) (delete-file file))))) (if (not errors) "."
(message (concat "Process completed" (concat " with errors: " errors)))))
(if (not errors) "." ;; Return output file name.
(concat " with errors: " errors))))) pdffile))))
;; Return output file name.
pdffile))
(set-window-configuration wconfig))))
(defun org-e-man-collect-errors (buffer) (defun org-e-man-collect-errors (buffer)
"Collect some kind of errors from \"groff\" output "Collect some kind of errors from \"groff\" output