mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-23 07:18:53 +00:00
ob: new header argument `padline' controls newline padding around tangled code
* lisp/ob-tangle.el (org-babel-spec-to-string): Check value of padline on tangling, no longer use the now-removed variable `org-babel-tangle-pad-newline'. * lisp/ob.el (org-babel-header-arg-names): Add padline to the list of header argument names. (org-babel-default-header-args): Set the default value of padline to "yes". (org-babel-merge-params): Cleaned up the merge logic, added padline. * doc/org.texi (padline): Documentation of the new padline header argument.
This commit is contained in:
parent
ae68febfbb
commit
d0a4ed53f1
21
doc/org.texi
21
doc/org.texi
@ -675,6 +675,8 @@ Specific header arguments
|
||||
files during tangling
|
||||
* comments:: Toggle insertion of comments in tangled
|
||||
code files
|
||||
* padline:: Control insertion of padding lines in tangled
|
||||
code files
|
||||
* no-expand:: Turn off variable assignment and noweb
|
||||
expansion during tangling
|
||||
* session:: Preserve the state of code evaluation
|
||||
@ -11817,6 +11819,8 @@ The following header arguments are defined:
|
||||
files during tangling
|
||||
* comments:: Toggle insertion of comments in tangled
|
||||
code files
|
||||
* padline:: Control insertion of padding lines in tangled
|
||||
code files
|
||||
* no-expand:: Turn off variable assignment and noweb
|
||||
expansion during tangling
|
||||
* session:: Preserve the state of code evaluation
|
||||
@ -12276,7 +12280,7 @@ The @code{:mkdirp} header argument can be used to create parent directories
|
||||
of tangled files when missing. This can be set to @code{yes} to enable
|
||||
directory creation or to @code{no} to inhibit directory creation.
|
||||
|
||||
@node comments, no-expand, mkdirp, Specific header arguments
|
||||
@node comments, padline, mkdirp, Specific header arguments
|
||||
@subsubsection @code{:comments}
|
||||
By default code blocks are tangled to source-code files without any insertion
|
||||
of comments beyond those which may already exist in the body of the code
|
||||
@ -12303,7 +12307,20 @@ Turns on the ``link'' comment option, and additionally wraps expanded noweb
|
||||
references in the code block body in link comments.
|
||||
@end itemize
|
||||
|
||||
@node no-expand, session, comments, Specific header arguments
|
||||
@node padline, no-expand, comments, Specific header arguments
|
||||
Control in insertion of padding lines around code block bodies in tangled
|
||||
code files. The default value is @code{yes} which results in insertion of
|
||||
newlines before and after each tangled code block. The following arguments
|
||||
are accepted.
|
||||
|
||||
@itemize @bullet
|
||||
@item @code{yes}
|
||||
Insert newlines before and after each code block body in tangled code files.
|
||||
@item @code{no}
|
||||
Do not insert any newline padding in tangled output.
|
||||
@end itemize
|
||||
|
||||
@node no-expand, session, padline, Specific header arguments
|
||||
@subsubsection @code{:no-expand}
|
||||
|
||||
By default, code blocks are expanded with @code{org-babel-expand-src-block}
|
||||
|
@ -68,11 +68,6 @@ then the name of the language is used."
|
||||
:group 'org-babel
|
||||
:type 'hook)
|
||||
|
||||
(defcustom org-babel-tangle-pad-newline t
|
||||
"Switch indicating whether to pad tangled code with newlines."
|
||||
:group 'org-babel
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom org-babel-tangle-comment-format-beg "[[%link][%source-name]]"
|
||||
"Format of inserted comments in tangled code files.
|
||||
The following format strings can be used to insert special
|
||||
@ -378,6 +373,7 @@ form
|
||||
(body (nth 5 spec))
|
||||
(comment (nth 6 spec))
|
||||
(comments (cdr (assoc :comments (nth 4 spec))))
|
||||
(padline (not (string= "no" (cdr (assoc :padline (nth 4 spec))))))
|
||||
(link-p (or (string= comments "both") (string= comments "link")
|
||||
(string= comments "yes") (string= comments "noweb")))
|
||||
(link-data (mapcar (lambda (el)
|
||||
@ -390,14 +386,14 @@ form
|
||||
(let ((text (org-babel-trim text)))
|
||||
(when (and comments (not (string= comments "no"))
|
||||
(> (length text) 0))
|
||||
(when org-babel-tangle-pad-newline (insert "\n"))
|
||||
(when padline (insert "\n"))
|
||||
(comment-region (point) (progn (insert text) (point)))
|
||||
(end-of-line nil) (insert "\n")))))
|
||||
(when comment (insert-comment comment))
|
||||
(when link-p
|
||||
(insert-comment
|
||||
(org-fill-template org-babel-tangle-comment-format-beg link-data)))
|
||||
(when org-babel-tangle-pad-newline (insert "\n"))
|
||||
(when padline (insert "\n"))
|
||||
(insert
|
||||
(format
|
||||
"%s\n"
|
||||
|
28
lisp/ob.el
28
lisp/ob.el
@ -291,14 +291,15 @@ then run `org-babel-pop-to-session'."
|
||||
|
||||
(defconst org-babel-header-arg-names
|
||||
'(cache cmdline colnames dir exports file noweb results
|
||||
session tangle var eval noeval comments no-expand shebang)
|
||||
session tangle var eval noeval comments no-expand shebang padline)
|
||||
"Common header arguments used by org-babel.
|
||||
Note that individual languages may define their own language
|
||||
specific header arguments as well.")
|
||||
|
||||
(defvar org-babel-default-header-args
|
||||
'((:session . "none") (:results . "replace") (:exports . "code")
|
||||
(:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))
|
||||
(:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no")
|
||||
(:padnewline . "yes"))
|
||||
"Default arguments to use when evaluating a source block.")
|
||||
|
||||
(defvar org-babel-default-inline-header-args
|
||||
@ -1679,7 +1680,7 @@ parameters when merging lists."
|
||||
("output" "value")))
|
||||
(exports-exclusive-groups
|
||||
'(("code" "results" "both" "none")))
|
||||
params results exports tangle noweb cache vars shebang comments)
|
||||
params results exports tangle noweb cache vars shebang comments padline)
|
||||
(flet ((e-merge (exclusive-groups &rest result-params)
|
||||
;; maintain exclusivity of mutually exclusive parameters
|
||||
(let (output)
|
||||
@ -1746,6 +1747,9 @@ parameters when merging lists."
|
||||
(:cache
|
||||
(setq cache (e-merge '(("yes" "no")) cache
|
||||
(split-string (or (cdr pair) "")))))
|
||||
(:padline
|
||||
(setq padline (e-merge '(("yes" "no")) padline
|
||||
(split-string (or (cdr pair) "")))))
|
||||
(:shebang ;; take the latest -- always overwrite
|
||||
(setq shebang (or (list (cdr pair)) shebang)))
|
||||
(:comments
|
||||
@ -1756,17 +1760,13 @@ parameters when merging lists."
|
||||
plist))
|
||||
plists))
|
||||
(while vars (setq params (cons (cons :var (cddr (pop vars))) params)))
|
||||
(cons (cons :comments (mapconcat 'identity comments " "))
|
||||
(cons (cons :shebang (mapconcat 'identity shebang " "))
|
||||
(cons (cons :cache (mapconcat 'identity cache " "))
|
||||
(cons (cons :noweb (mapconcat 'identity noweb " "))
|
||||
(cons (cons :tangle (mapconcat 'identity tangle " "))
|
||||
(cons (cons :exports
|
||||
(mapconcat 'identity exports " "))
|
||||
(cons
|
||||
(cons :results
|
||||
(mapconcat 'identity results " "))
|
||||
params)))))))))
|
||||
(mapc
|
||||
(lambda (hd)
|
||||
(let ((key (intern (concat ":" (symbol-name hd))))
|
||||
(val (eval hd)))
|
||||
(setf params (cons (cons key (mapconcat 'identity val " ")) params))))
|
||||
'(results exports tangle noweb padline cache shebang comments))
|
||||
params))
|
||||
|
||||
(defun org-babel-expand-noweb-references (&optional info parent-buffer)
|
||||
"Expand Noweb references in the body of the current source code block.
|
||||
|
Loading…
Reference in New Issue
Block a user