diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 2a02554c4..60d07ff00 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -96,14 +96,10 @@ controlled by the :comments header argument." :group 'org-babel :type 'string) -(defcustom org-babel-tangle-named-block-combination nil +(defcustom org-babel-tangle-do-combine-named-blocks nil "Combine blocks of the same name during tangling." :group 'org-babel - :type '(choice - (const :tag "Default: no special handling" nil) - (const :tag "Append all blocks of the same name" append) - (const :tag "Only keep the first block of the same name" first) - (const :tag "Only keep the last block of the same name" last))) + :type 'bool) (defun org-babel-find-file-noselect-refresh (file) "Find file ensuring that the latest changes on disk are @@ -249,7 +245,9 @@ exported source code blocks by language." (setq block-counter (+ 1 block-counter)) (add-to-list 'path-collector file-name))))) specs))) - (org-babel-tangle-combine-named-blocks + (funcall (if org-babel-tangle-do-combine-named-blocks + #'org-babel-tangle-combine-named-blocks + #'identity) (org-babel-tangle-collect-blocks lang))) (message "tangled %d code block%s from %s" block-counter (if (= block-counter 1) "" "s") @@ -376,37 +374,25 @@ code blocks by language." "Combine blocks of the same name. This function follows noweb behavior of appending blocks of the same name in the order they appear in the file." - (if org-babel-tangle-named-block-combination - (let (tangled-names) - (mapcar - (lambda (by-lang) - (cons - (car by-lang) - (mapcar (lambda (spec) - (let ((name (nth 3 spec))) - (unless (member name tangled-names) - (when name - (setf - (nth 5 spec) - (let ((named (mapcar - (lambda (el) (nth 5 el)) - (delq - nil - (mapcar - (lambda (el) - (when (equal name (nth 3 el)) - el)) - (cdr by-lang)))))) - (case org-babel-tangle-named-block-combination - (append (mapconcat #'identity - named "\n")) - (first (first named)) - (last (car (last named)))))) - (add-to-list 'tangled-names name)) - spec))) - (cdr by-lang)))) - blocks)) - blocks)) + (let (tangled-names) + (mapcar + (lambda (by-lang) + (cons + (car by-lang) + (mapcar (lambda (spec) + (let ((name (nth 3 spec))) + (unless (member name tangled-names) + (when name + (setf (nth 5 spec) + (mapconcat + (lambda (el) (nth 5 el)) + (remove-if (lambda (el) (not (equal name (nth 3 el)))) + (cdr by-lang)) + "\n")) + (add-to-list 'tangled-names name)) + spec))) + (cdr by-lang)))) + blocks))) (defun org-babel-spec-to-string (spec) "Insert SPEC into the current file.