summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ecay <aaronecay@gmail.com>2016-09-01 18:44:30 +0100
committerAaron Ecay <aaronecay@gmail.com>2016-09-01 18:46:48 +0100
commitab21e2b72d504c13e035757a4765d02f8e938968 (patch)
treeaf463e295e766af52b727424c5d92d5f920adbf7
parentd4a073f5be948673044ce76a15f1d14c91f1700b (diff)
downloadorg-mode-ab21e2b72d504c13e035757a4765d02f8e938968.tar.gz
Use file-name-extension where appropriate
* lisp/ob-R.el (org-babel-R-construct-graphics-device-call): * lisp/ob-asymptote.el (org-babel-execute:asymptote): * lisp/ob-latex.el (org-babel-execute:latex): * lisp/org-agenda.el (org-agenda-write): * lisp/ox-odt.el (org-odt--copy-formula-file): Use `file-name-extension' instead of string munging.
-rw-r--r--lisp/ob-R.el3
-rw-r--r--lisp/ob-asymptote.el4
-rw-r--r--lisp/ob-latex.el17
-rw-r--r--lisp/org-agenda.el14
-rw-r--r--lisp/ox-odt.el6
5 files changed, 22 insertions, 22 deletions
diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index a17cf1d..8494c97 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -316,8 +316,7 @@ Each member of this list is a list with three members:
:type :family :title :fonts :version
:paper :encoding :pagecentre :colormodel
:useDingbats :horizontal))
- (device (and (string-match ".+\\.\\([^.]+\\)" out-file)
- (match-string 1 out-file)))
+ (device (file-name-extension out-file))
(device-info (or (assq (intern (concat ":" device))
org-babel-R-graphics-devices)
(assq :png org-babel-R-graphics-devices)))
diff --git a/lisp/ob-asymptote.el b/lisp/ob-asymptote.el
index 7c6e781..a2091df 100644
--- a/lisp/ob-asymptote.el
+++ b/lisp/ob-asymptote.el
@@ -55,9 +55,7 @@
"Execute a block of Asymptote code.
This function is called by `org-babel-execute-src-block'."
(let* ((out-file (cdr (assoc :file params)))
- (format (or (and out-file
- (string-match ".+\\.\\(.+\\)" out-file)
- (match-string 1 out-file))
+ (format (or (file-name-extension out-file)
"pdf"))
(cmdline (cdr (assoc :cmdline params)))
(in-file (org-babel-temp-file "asymptote-"))
diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index e4327a2..5e009ed 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -93,6 +93,7 @@ This function is called by `org-babel-execute-src-block'."
(setq body (org-babel-expand-body:latex body params))
(if (cdr (assoc :file params))
(let* ((out-file (cdr (assoc :file params)))
+ (extension (file-name-extension out-file))
(tex-file (org-babel-temp-file "latex-" ".tex"))
(border (cdr (assoc :border params)))
(imagemagick (cdr (assoc :imagemagick params)))
@@ -113,8 +114,8 @@ This function is called by `org-babel-execute-src-block'."
(when (file-exists-p out-file) (delete-file out-file))
(with-temp-file out-file
(insert body)))
- ((and (or (string-suffix-p ".svg" out-file)
- (string-suffix-p ".html" out-file))
+ ((and (or (string= "svg" extension)
+ (string= "html" extension))
(executable-find org-babel-latex-htlatex))
;; TODO: this is a very different way of generating the
;; frame latex document than in the pdf case. Ideally, both
@@ -158,7 +159,7 @@ This function is called by `org-babel-execute-src-block'."
".html")
out-file)
(error "HTML file produced but SVG file requested")))))
- ((or (string-suffix-p ".pdf" out-file) imagemagick)
+ ((or (string= "pdf" extension) imagemagick)
(with-temp-file tex-file
(require 'ox-latex)
(insert
@@ -191,16 +192,16 @@ This function is called by `org-babel-execute-src-block'."
(when (file-exists-p out-file) (delete-file out-file))
(let ((transient-pdf-file (org-babel-latex-tex-to-pdf tex-file)))
(cond
- ((string-match "\\.pdf$" out-file)
+ ((string= "pdf" extension)
(rename-file transient-pdf-file out-file))
(imagemagick
(org-babel-latex-convert-pdf
transient-pdf-file out-file im-in-options im-out-options)
(when (file-exists-p transient-pdf-file)
- (delete-file transient-pdf-file))))))
- ((string-match "\\.\\([^\\.]+\\)$" out-file)
- (error "Can not create %s files, please specify a .png or .pdf file or try the :imagemagick header argument"
- (match-string 1 out-file))))
+ (delete-file transient-pdf-file)))
+ (t
+ (error "Can not create %s files, please specify a .png or .pdf file or try the :imagemagick header argument"
+ extension))))))
nil) ;; signal that output has already been written to file
body))
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index feeeedc..114d579 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3339,7 +3339,9 @@ the agenda to write."
(org-let (if nosettings nil org-agenda-exporter-settings)
'(save-excursion
(save-window-excursion
- (let ((bs (copy-sequence (buffer-string))) beg content)
+ (let ((bs (copy-sequence (buffer-string)))
+ (extension (file-name-extension file))
+ beg content)
(with-temp-buffer
(rename-buffer org-agenda-write-buffer-name t)
(set-buffer-modified-p nil)
@@ -3349,7 +3351,7 @@ the agenda to write."
(cond
((bound-and-true-p org-mobile-creating-agendas)
(org-mobile-write-agenda-for-mobile file))
- ((string-match "\\.org\\'" file)
+ ((string= "org" extension)
(let (content p m message-log-max)
(goto-char (point-min))
(while (setq p (next-single-property-change (point) 'org-hd-marker nil))
@@ -3368,7 +3370,7 @@ the agenda to write."
(write-file file)
(kill-buffer (current-buffer))
(message "Org file written to %s" file)))
- ((string-match "\\.html?\\'" file)
+ ((string= "html" extension)
(require 'htmlize)
(set-buffer (htmlize-buffer (current-buffer)))
(when org-agenda-export-html-style
@@ -3380,11 +3382,11 @@ the agenda to write."
(write-file file)
(kill-buffer (current-buffer))
(message "HTML written to %s" file))
- ((string-match "\\.ps\\'" file)
+ ((string= "ps" extension)
(require 'ps-print)
(ps-print-buffer-with-faces file)
(message "Postscript written to %s" file))
- ((string-match "\\.pdf\\'" file)
+ ((string= "pdf" extension)
(require 'ps-print)
(ps-print-buffer-with-faces
(concat (file-name-sans-extension file) ".ps"))
@@ -3394,7 +3396,7 @@ the agenda to write."
(expand-file-name file))
(delete-file (concat (file-name-sans-extension file) ".ps"))
(message "PDF written to %s" file))
- ((string-match "\\.ics\\'" file)
+ ((string= "ics" extension)
(require 'ox-icalendar)
(org-icalendar-export-current-agenda (expand-file-name file)))
(t
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 9978c1e..23a0129 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -2388,13 +2388,13 @@ used as a communication channel."
;; Copy over the formula file from user directory to zip
;; directory.
(message "Embedding %s as %s..." src-file target-file)
- (let ((case-fold-search nil))
+ (let ((ext (file-name-extension src-file)))
(cond
;; Case 1: Mathml.
- ((string-match "\\.\\(mathml\\|mml\\)\\'" src-file)
+ ((member ext '("mathml" "mml"))
(copy-file src-file (concat org-odt-zip-dir target-file) 'overwrite))
;; Case 2: OpenDocument formula.
- ((string-match "\\.odf\\'" src-file)
+ ((string= ext "odf")
(org-odt--zip-extract src-file "content.xml"
(concat org-odt-zip-dir target-dir)))
(t (error "%s is not a formula file" src-file))))