Browse Source

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.
Aaron Ecay 8 years ago
parent
commit
ab21e2b72d
5 changed files with 22 additions and 22 deletions
  1. 1 2
      lisp/ob-R.el
  2. 1 3
      lisp/ob-asymptote.el
  3. 9 8
      lisp/ob-latex.el
  4. 8 6
      lisp/org-agenda.el
  5. 3 3
      lisp/ox-odt.el

+ 1 - 2
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)))

+ 1 - 3
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-"))

+ 9 - 8
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))
 

+ 8 - 6
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

+ 3 - 3
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))))