Browse Source

Merge branch 'maint'

Nicolas Goaziou 2 years ago
parent
commit
37bffbb347
6 changed files with 53 additions and 67 deletions
  1. 1 1
      contrib/lisp/ox-koma-letter.el
  2. 9 24
      lisp/org.el
  3. 1 1
      lisp/ox-beamer.el
  4. 33 32
      lisp/ox-latex.el
  5. 6 6
      lisp/ox.el
  6. 3 3
      testing/lisp/test-org-element.el

+ 1 - 1
contrib/lisp/ox-koma-letter.el

@@ -631,7 +631,7 @@ holding export options."
    ;; LaTeX compiler
    (org-latex--insert-compiler info)
    ;; Document class and packages.
-   (org-latex--make-preamble info)
+   (org-latex-make-preamble info)
    ;; Settings.  They can come from three locations, in increasing
    ;; order of precedence: global variables, LCO files and in-buffer
    ;; settings.  Thus, we first insert settings coming from global

+ 9 - 24
lisp/org.el

@@ -115,8 +115,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function isearch-no-upper-case-p "isearch" (string regexp-flag))
 (declare-function org-add-archive-files "org-archive" (files))
 (declare-function org-agenda-entry-get-agenda-timestamp "org-agenda" (pom))
-(declare-function org-agenda-list "org-agenda"
-		  (&optional arg start-day span with-hour))
+(declare-function org-agenda-list "org-agenda" (&optional arg start-day span with-hour))
 (declare-function org-agenda-redo "org-agenda" (&optional all))
 (declare-function org-babel-do-in-edit-buffer "ob-core" (&rest body) t)
 (declare-function org-babel-tangle-file "ob-tangle" (file &optional target-file lang))
@@ -172,6 +171,9 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function org-tags-view "org-agenda" (&optional todo-only match))
 (declare-function orgtbl-ascii-plot "org-table" (&optional ask))
 (declare-function orgtbl-mode "org-table" (&optional arg))
+(declare-function org-export-get-backend "ox" (name))
+(declare-function org-export-get-environment "ox" (&optional backend subtreep ext-plist))
+(declare-function org-latex-make-preamble "ox-latex" (info &optional template))
 
 (defsubst org-uniquify (list)
   "Non-destructively remove duplicate elements from LIST."
@@ -19350,26 +19352,6 @@ inspection."
       ;; Failed conversion.  Return the LaTeX fragment verbatim
       latex-frag)))
 
-(declare-function org-export-get-backend "ox" (name))
-(declare-function org-export--get-global-options "ox" (&optional backend))
-(declare-function org-export--get-inbuffer-options "ox" (&optional backend))
-(declare-function org-latex-guess-inputenc "ox-latex" (header))
-(declare-function org-latex-guess-babel-language "ox-latex" (header info))
-(defun org-create-formula--latex-header ()
-  "Return LaTeX header appropriate for previewing a LaTeX snippet."
-  (let ((info (org-combine-plists (org-export--get-global-options
-				   (org-export-get-backend 'latex))
-				  (org-export--get-inbuffer-options
-				   (org-export-get-backend 'latex)))))
-    (org-latex-guess-babel-language
-     (org-latex-guess-inputenc
-      (org-splice-latex-header
-       org-format-latex-header
-       org-latex-default-packages-alist
-       org-latex-packages-alist t
-       (plist-get info :latex-header)))
-     info)))
-
 (defun org--get-display-dpi ()
   "Get the DPI of the display.
 The function assumes that the display has the same pixel width in
@@ -19408,8 +19390,11 @@ a HTML file."
 	 (post-clean (or (plist-get processing-info :post-clean)
 			 '(".dvi" ".xdv" ".pdf" ".tex" ".aux" ".log"
 			   ".svg" ".png" ".jpg" ".jpeg" ".out")))
-	 (latex-header (or (plist-get processing-info :latex-header)
-			   (org-create-formula--latex-header)))
+	 (latex-header
+	  (or (plist-get processing-info :latex-header)
+	      (org-latex-make-preamble
+	       (org-export-get-environment (org-export-get-backend 'latex))
+	       org-format-latex-header)))
 	 (latex-compiler (plist-get processing-info :latex-compiler))
 	 (image-converter (plist-get processing-info :image-converter))
 	 (tmpdir temporary-file-directory)

+ 1 - 1
lisp/ox-beamer.el

@@ -797,7 +797,7 @@ holding export options."
      ;; LaTeX compiler
      (org-latex--insert-compiler info)
      ;; Document class and packages.
-     (org-latex--make-preamble info)
+     (org-latex-make-preamble info)
      ;; Insert themes.
      (let ((format-theme
 	    (function

+ 33 - 32
lisp/ox-latex.el

@@ -1586,37 +1586,6 @@ INFO is a plist used as a communication channel."
       (?L . ,(capitalize language))
       (?D . ,(org-export-get-date info)))))
 
-(defun org-latex--make-preamble (info)
-  "Return a formatted LaTeX preamble.
-INFO is a plist used as a communication channel."
-  (let* ((class (plist-get info :latex-class))
-	    (class-options (plist-get info :latex-class-options))
-	    (header (nth 1 (assoc class (plist-get info :latex-classes))))
-	    (document-class-string
-	     (and (stringp header)
-		  (if (not class-options) header
-		    (replace-regexp-in-string
-		     "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
-		     class-options header t nil 1)))))
-       (if (not document-class-string)
-	   (user-error "Unknown LaTeX class `%s'" class)
-	 (org-latex-guess-polyglossia-language
-	  (org-latex-guess-babel-language
-	   (org-latex-guess-inputenc
-	    (org-element-normalize-string
-	     (org-splice-latex-header
-	      document-class-string
-	      (org-latex--remove-packages
-	       org-latex-default-packages-alist info)
-	      (org-latex--remove-packages
-	       org-latex-packages-alist info)
-	      nil
-	      (mapconcat 'org-element-normalize-string
-			 (list (plist-get info :latex-header)
-			       (plist-get info :latex-header-extra)) ""))))
-	   info)
-	  info))))
-
 (defun org-latex--insert-compiler (info)
   "Insert LaTeX_compiler info into the document.
 INFO is a plist used as a communication channel."
@@ -1647,6 +1616,38 @@ INFO is a plist used as a communication channel."
 
 ;;; Template
 
+;;;###autoload
+(defun org-latex-make-preamble (info &optional template)
+  "Return a formatted LaTeX preamble.
+INFO is a plist used as a communication channel.  Optional
+argument TEMPLATE, when non-nil, is the header template string,
+as expected by `org-splice-latex-header'."
+  (let* ((class (plist-get info :latex-class))
+	 (class-options (plist-get info :latex-class-options))
+	 (header (nth 1 (assoc class (plist-get info :latex-classes))))
+	 (class-template
+	  (or template
+	      (and (stringp header)
+		   (if (not class-options) header
+		     (replace-regexp-in-string
+		      "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
+		      class-options header t nil 1)))
+	      (user-error "Unknown LaTeX class `%s'" class))))
+    (org-latex-guess-polyglossia-language
+     (org-latex-guess-babel-language
+      (org-latex-guess-inputenc
+       (org-element-normalize-string
+	(org-splice-latex-header
+	 class-template
+	 (org-latex--remove-packages org-latex-default-packages-alist info)
+	 (org-latex--remove-packages org-latex-packages-alist info)
+	 nil
+	 (mapconcat #'org-element-normalize-string
+		    (list (plist-get info :latex-header)
+			  (plist-get info :latex-header-extra)) ""))))
+      info)
+     info)))
+
 (defun org-latex-template (contents info)
   "Return complete document string after LaTeX conversion.
 CONTENTS is the transcoded contents string.  INFO is a plist
@@ -1660,7 +1661,7 @@ holding export options."
      ;; LaTeX compiler.
      (org-latex--insert-compiler info)
      ;; Document class and packages.
-     (org-latex--make-preamble info)
+     (org-latex-make-preamble info)
      ;; Possibly limit depth for headline numbering.
      (let ((sec-num (plist-get info :section-numbers)))
        (when (integerp sec-num)

+ 6 - 6
lisp/ox.el

@@ -77,12 +77,12 @@
 (require 'org-macro)
 (require 'tabulated-list)
 
+(declare-function org-src-coderef-format "org-src" (&optional element))
+(declare-function org-src-coderef-regexp "org-src" (fmt &optional label))
 (declare-function org-publish "ox-publish" (project &optional force async))
 (declare-function org-publish-all "ox-publish" (&optional force async))
 (declare-function org-publish-current-file "ox-publish" (&optional force async))
 (declare-function org-publish-current-project "ox-publish" (&optional force async))
-(declare-function org-src-coderef-format "org-src" (&optional element))
-(declare-function org-src-coderef-regexp "org-src" (fmt &optional label))
 
 (defvar org-publish-project-alist)
 (defvar org-table-number-fraction)
@@ -1019,13 +1019,12 @@ mode."
 				  (:copier nil))
   name parent transcoders options filters blocks menu)
 
+;;;###autoload
 (defun org-export-get-backend (name)
   "Return export back-end named after NAME.
 NAME is a symbol.  Return nil if no such back-end is found."
-  (catch 'found
-    (dolist (b org-export-registered-backends)
-      (when (eq (org-export-backend-name b) name)
-	(throw 'found b)))))
+  (cl-find-if (lambda (b) (and (eq name (org-export-backend-name b))))
+	      org-export-registered-backends))
 
 (defun org-export-register-backend (backend)
   "Register BACKEND as a known export back-end.
@@ -1355,6 +1354,7 @@ The back-end could then be called with, for example:
 ;; along with their value in order to set them as buffer local
 ;; variables later in the process.
 
+;;;###autoload
 (defun org-export-get-environment (&optional backend subtreep ext-plist)
   "Collect export options from the current buffer.
 

+ 3 - 3
testing/lisp/test-org-element.el

@@ -3585,9 +3585,9 @@ Text
   ;; Preserve local structures when re-parenting.
   (should
    (eq 'table
-       (org-test-with-temp-text
-	   "#+begin_center\nP0\n\n<point>\n\n  P1\n  | a | b |\n| c | d |\n#+end_center"
-	 (let ((org-element-use-cache t))
+       (let ((org-element-use-cache t))
+	 (org-test-with-temp-text
+	     "#+begin_center\nP0\n\n<point>\n\n  P1\n  | a | b |\n| c | d |\n#+end_center"
 	   (save-excursion (search-forward "| c |") (org-element-at-point))
 	   (insert "- item")
 	   (search-forward "| c |")