diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 3c0f36f1e..1252bbca1 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -1634,11 +1634,10 @@ setting the ~STYLE~ property for each sub-task. The change is breaking when ~org-use-property-inheritance~ is set to ~t~. -*** =ox-org= preserves header non-default arguments in src blocks +*** =ox-org= preserves header arguments in src blocks Previously, all the header arguments where stripped from src blocks -during export. Now, header arguments are preserved as long as their -values are not equal to the default header argument values. +during export. Now, header arguments are preserved. *** =ox-org= now exports special table rows by default diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 34f12fdcc..657cb2b52 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -370,7 +370,7 @@ The function respects the value of the :exports header argument." nil)))) (defcustom org-babel-exp-code-template - "#+begin_src %lang%switches%flags%header-args\n%body\n#+end_src" + "#+begin_src %lang%switches%header-args\n%body\n#+end_src" "Template used to export the body of code blocks. This template may be customized to include additional information such as the code block name, or the values of particular header @@ -381,8 +381,7 @@ and the following %keys may be used. name ------ the name of the code block body ------ the body of the code block switches -- the switches associated to the code block - flags ----- the flags passed to the code block - header-args the non-default header arguments of the code block + header-args the header arguments of the code block In addition to the keys mentioned above, every header argument defined for the code block may be used as a key and will be @@ -392,7 +391,7 @@ replaced with its value." :package-version '(Org . "9.7")) (defcustom org-babel-exp-inline-code-template - "src_%lang[%switches%flags%header-args]{%body}" + "src_%lang[%switches%header-args]{%body}" "Template used to export the body of inline code blocks. This template may be customized to include additional information such as the code block name, or the values of particular header @@ -403,8 +402,7 @@ and the following %keys may be used. name ------ the name of the code block body ------ the body of the code block switches -- the switches associated to the code block - flags ----- the flags passed to the code block - header-args the non-default header arguments of the code block + header-args the header arguments of the code block In addition to the keys mentioned above, every header argument defined for the code block may be used as a key and will be @@ -438,39 +436,9 @@ replaced with its value." (and f (concat " " (cdr f))))) ("header-args" . - ,(let* ((header-args - (mapcar - (lambda (pair) - ;; Do no include special parameters, parameters with - ;; their values equal to defaults. - (unless (or - ;; Special parameters that are not real header - ;; arguments. - (memq (car pair) - '( :result-params :result-type - ;; This is an obsolete parameter still - ;; used in some tests. - :flags)) - ;; Global defaults. - (equal (cdr pair) - (alist-get - (car pair) - (if (eq type 'inline) org-babel-default-inline-header-args - org-babel-default-header-args))) - ;; Per-language defaults. - (let ((lang-headers - (intern - (concat "org-babel-default-header-args:" - (nth 0 info))))) - (and (boundp lang-headers) - (equal (cdr pair) - (alist-get (car pair) - (eval lang-headers t)))))) - (format "%s %s" (car pair) (cdr pair)))) - (nth 2 info))) - (header-arg-string - (mapconcat #'identity (delq nil header-args) " "))) - (unless (seq-empty-p header-arg-string) (concat " " header-arg-string)))) + ,(org-babel-exp--at-source + (when-let ((params (org-element-property :parameters (org-element-context)))) + (concat " " params)))) ,@(mapcar (lambda (pair) (cons (substring (symbol-name (car pair)) 1) (format "%S" (cdr pair)))) diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el index d029dadfb..6749284d7 100644 --- a/testing/lisp/test-ob-exp.el +++ b/testing/lisp/test-ob-exp.el @@ -262,9 +262,9 @@ Here is one at the end of a line. {{{results(=2=)}}} (string-match (replace-regexp-in-string "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...} - (regexp-quote "Here is one in the middle src_sh[ :exports code]{echo 1} of a line. -Here is one at the end of a line. src_sh[ :exports code]{echo 2} -src_sh[ :exports code]{echo 3} Here is one at the beginning of a line. + (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line. +Here is one at the end of a line. src_sh[]{echo 2} +src_sh[]{echo 3} Here is one at the beginning of a line. Here is one that is also evaluated: src_sh[ :exports both]{echo 4} {{{results(=4=)}}}") nil t) (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076" @@ -430,7 +430,7 @@ be evaluated." "Test exporting a source block with a flag." (should (string-match - "\\`#\\+BEGIN_SRC emacs-lisp -some-flag$" + "\\`#\\+BEGIN_SRC emacs-lisp :flags -some-flag$" (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp :flags -some-flag\n\(+ 1 1)\n#+END_SRC" (org-babel-exp-process-buffer) @@ -570,7 +570,7 @@ src_emacs-lisp{(+ 1 1)}" (ert-deftest ob-export/body-with-coderef () "Test exporting a code block with coderefs." (should - (equal "#+begin_src emacs-lisp\n0 (ref:foo)\n#+end_src" + (equal "#+begin_src emacs-lisp :exports code\n0 (ref:foo)\n#+end_src" (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp :exports code\n0 (ref:foo)\n#+END_SRC" (let ((org-export-use-babel t) @@ -579,7 +579,7 @@ src_emacs-lisp{(+ 1 1)}" (buffer-string)))) (should (equal - "#+begin_src emacs-lisp -l \"r:%s\"\n1 r:foo\n#+end_src" + "#+begin_src emacs-lisp -l \"r:%s\" -lisp :exports code\n1 r:foo\n#+end_src" (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -l \"r:%s\" -lisp :exports code\n1 r:foo\n#+END_SRC" (let ((org-export-use-babel t))