Mercurial > emacs
comparison lisp/textmodes/rst.el @ 112110:5f273d1516d7
Small rst.el stuff.
* lisp/textmodes/rst.el (rst-compile-toolsets): Make it a defcustom.
Add `pdf' and `s5' entries. Use `prog.py' if found, otherwise
default to `prog' without a .py extension.
(rst-compile-pdf-preview, rst-compile-slides-preview):
Use program names from rst-compile-toolsets, rather than hard-coding.
(rst-portable-mark-active-p): Fix presumed typo.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Mon, 03 Jan 2011 20:47:39 -0800 |
parents | 40af77a50adc |
children | 4e3dc3aca537 |
comparison
equal
deleted
inserted
replaced
112109:5284aa9ea62d | 112110:5f273d1516d7 |
---|---|
1 ;;; rst.el --- Mode for viewing and editing reStructuredText-documents. | 1 ;;; rst.el --- Mode for viewing and editing reStructuredText-documents. |
2 | 2 |
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 | 3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
4 ;; Free Software Foundation, Inc. | 4 ;; Free Software Foundation, Inc. |
5 | 5 |
6 ;; Authors: Martin Blais <blais@furius.ca>, | 6 ;; Authors: Martin Blais <blais@furius.ca>, |
7 ;; Stefan Merten <smerten@oekonux.de>, | 7 ;; Stefan Merten <smerten@oekonux.de>, |
8 ;; David Goodger <goodger@python.org> | 8 ;; David Goodger <goodger@python.org> |
3232 "Settings for support of conversion of reStructuredText | 3232 "Settings for support of conversion of reStructuredText |
3233 document with \\[rst-compile]." | 3233 document with \\[rst-compile]." |
3234 :group 'rst | 3234 :group 'rst |
3235 :version "21.1") | 3235 :version "21.1") |
3236 | 3236 |
3237 (defvar rst-compile-toolsets | 3237 (defcustom rst-compile-toolsets |
3238 '((html . ("rst2html.py" ".html" nil)) | 3238 `((html ,(if (executable-find "rst2html.py") "rst2html.py" "rst2html") |
3239 (latex . ("rst2latex.py" ".tex" nil)) | 3239 ".html" nil) |
3240 (newlatex . ("rst2newlatex.py" ".tex" nil)) | 3240 (latex ,(if (executable-find "rst2latex.py") "rst2latex.py" "rst2latex") |
3241 (pseudoxml . ("rst2pseudoxml.py" ".xml" nil)) | 3241 ".tex" nil) |
3242 (xml . ("rst2xml.py" ".xml" nil))) | 3242 (newlatex ,(if (executable-find "rst2newlatex.py") "rst2newlatex.py" |
3243 "rst2newlatex") | |
3244 ".tex" nil) | |
3245 (pseudoxml ,(if (executable-find "rst2pseudoxml.py") "rst2pseudoxml.py" | |
3246 "rst2pseudoxml") | |
3247 ".xml" nil) | |
3248 (xml ,(if (executable-find "rst2xml.py") "rst2xml.py" "rst2xml") | |
3249 ".xml" nil) | |
3250 (pdf ,(if (executable-find "rst2pdf.py") "rst2pdf.py" "rst2pdf") | |
3251 ".pdf" nil) | |
3252 (s5 ,(if (executable-find "rst2s5.py") "rst2s5.py" "rst2s5") | |
3253 ".html" nil)) | |
3243 "Table describing the command to use for each toolset. | 3254 "Table describing the command to use for each toolset. |
3244 An association list of the toolset to a list of the (command to use, | 3255 An association list of the toolset to a list of the (command to use, |
3245 extension of produced filename, options to the tool (nil or a | 3256 extension of produced filename, options to the tool (nil or a |
3246 string)) to be used for converting the document.") | 3257 string)) to be used for converting the document." |
3258 :type '(alist :options (html latex newlatex pseudoxml xml) | |
3259 :key-type symbol | |
3260 :value-type (list :tag "Specification" | |
3261 (file :tag "Command") | |
3262 (string :tag "File extension") | |
3263 (choice :tag "Command options" | |
3264 (const :tag "No options" nil) | |
3265 (string :tag "Options")))) | |
3266 :group 'rst | |
3267 :version "24.1") | |
3247 | 3268 |
3248 ;; Note for Python programmers not familiar with association lists: you can set | 3269 ;; Note for Python programmers not familiar with association lists: you can set |
3249 ;; values in an alists like this, e.g. : | 3270 ;; values in an alists like this, e.g. : |
3250 ;; (setcdr (assq 'html rst-compile-toolsets) | 3271 ;; (setcdr (assq 'html rst-compile-toolsets) |
3251 ;; '("rst2html.py" ".htm" "--stylesheet=/docutils.css")) | 3272 ;; '("rst2html.py" ".htm" "--stylesheet=/docutils.css")) |
3329 (interactive) | 3350 (interactive) |
3330 (with-output-to-temp-buffer "*pseudoxml*" | 3351 (with-output-to-temp-buffer "*pseudoxml*" |
3331 (shell-command-on-region | 3352 (shell-command-on-region |
3332 (if mark-active (region-beginning) (point-min)) | 3353 (if mark-active (region-beginning) (point-min)) |
3333 (if mark-active (region-end) (point-max)) | 3354 (if mark-active (region-end) (point-max)) |
3334 "rst2pseudoxml.py" | 3355 (cadr (assq 'pseudoxml rst-compile-toolsets)) |
3335 standard-output))) | 3356 standard-output))) |
3336 | 3357 |
3337 (defvar rst-pdf-program "xpdf" | 3358 (defvar rst-pdf-program "xpdf" |
3338 "Program used to preview PDF files.") | 3359 "Program used to preview PDF files.") |
3339 | 3360 |
3340 (defun rst-compile-pdf-preview () | 3361 (defun rst-compile-pdf-preview () |
3341 "Convert the document to a PDF file and launch a preview program." | 3362 "Convert the document to a PDF file and launch a preview program." |
3342 (interactive) | 3363 (interactive) |
3343 (let* ((tmp-filename (make-temp-file "rst-out" nil ".pdf")) | 3364 (let* ((tmp-filename (make-temp-file "rst-out" nil ".pdf")) |
3365 (command (format "%s %s %s && %s %s" | |
3366 (cadr (assq 'pdf rst-compile-toolsets)) | |
3344 (command (format "rst2pdf.py %s %s && %s %s" | 3367 (command (format "rst2pdf.py %s %s && %s %s" |
3345 buffer-file-name tmp-filename | 3368 buffer-file-name tmp-filename |
3346 rst-pdf-program tmp-filename))) | 3369 rst-pdf-program tmp-filename))) |
3347 (start-process-shell-command "rst-pdf-preview" nil command) | 3370 (start-process-shell-command "rst-pdf-preview" nil command) |
3348 ;; Note: you could also use (compile command) to view the compilation | 3371 ;; Note: you could also use (compile command) to view the compilation |
3354 | 3377 |
3355 (defun rst-compile-slides-preview () | 3378 (defun rst-compile-slides-preview () |
3356 "Convert the document to an S5 slide presentation and launch a preview program." | 3379 "Convert the document to an S5 slide presentation and launch a preview program." |
3357 (interactive) | 3380 (interactive) |
3358 (let* ((tmp-filename (make-temp-file "rst-slides" nil ".html")) | 3381 (let* ((tmp-filename (make-temp-file "rst-slides" nil ".html")) |
3382 (command (format "%s %s %s && %s %s" | |
3383 (cadr (assq 's5 rst-compile-toolsets)) | |
3359 (command (format "rst2s5.py %s %s && %s %s" | 3384 (command (format "rst2s5.py %s %s && %s %s" |
3385 | |
3360 buffer-file-name tmp-filename | 3386 buffer-file-name tmp-filename |
3361 rst-slides-program tmp-filename))) | 3387 rst-slides-program tmp-filename))) |
3362 (start-process-shell-command "rst-slides-preview" nil command) | 3388 (start-process-shell-command "rst-slides-preview" nil command) |
3363 ;; Note: you could also use (compile command) to view the compilation | 3389 ;; Note: you could also use (compile command) to view the compilation |
3364 ;; output. | 3390 ;; output. |
3452 | 3478 |
3453 (defun rst-portable-mark-active-p () | 3479 (defun rst-portable-mark-active-p () |
3454 "A portable function that returns non-nil if the mark is active." | 3480 "A portable function that returns non-nil if the mark is active." |
3455 (cond | 3481 (cond |
3456 ((fboundp 'region-active-p) (region-active-p)) | 3482 ((fboundp 'region-active-p) (region-active-p)) |
3457 ((boundp 'transient-mark-mode) transient-mark-mode mark-active))) | 3483 ((boundp 'transient-mark-mode) (and transient-mark-mode mark-active)) |
3458 | 3484 (t mark-active))) |
3459 | 3485 |
3460 | 3486 |
3461 (provide 'rst) | 3487 (provide 'rst) |
3462 | 3488 |
3463 ;; arch-tag: 255ac0a3-a689-44cb-8643-04ca55ae490d | |
3464 ;;; rst.el ends here | 3489 ;;; rst.el ends here |