Browse Source

added function: org-babel-tangle-clean, for cleaning up tangled files

Eric Schulte 16 years ago
parent
commit
beed8c097b
1 changed files with 14 additions and 2 deletions
  1. 14 2
      lisp/org-babel-tangle.el

+ 14 - 2
lisp/org-babel-tangle.el

@@ -136,6 +136,19 @@ exported source code blocks by language."
                (if (> block-counter 1) "s" ""))
                (if (> block-counter 1) "s" ""))
       path-collector)))
       path-collector)))
 
 
+(defun org-babel-tangle-clean ()
+  "Call this function inside of a source-code file generated by
+`org-babel-tangle' to remove all comments inserted automatically
+by `org-babel-tangle'.  Warning, this comment removes any lines
+containing constructs which resemble org-mode file links or noweb
+references."
+  (interactive)
+  (goto-char (point-min))
+  (while (or (re-search-forward "\\[\\[file:.*\\]\\[.*\\]\\]" nil t)
+             (re-search-forward "<<[^[:space:]]*>>" nil t))
+    (delete-region (save-excursion (move-beginning-of-line 1) (point))
+                   (save-excursion (move-end-of-line 1) (forward-char 1) (point)))))
+
 (defun org-babel-tangle-collect-blocks (&optional lang)
 (defun org-babel-tangle-collect-blocks (&optional lang)
   "Collect all source blocks in the current org-mode file.
   "Collect all source blocks in the current org-mode file.
 Return an association list of source-code block specifications of
 Return an association list of source-code block specifications of
@@ -191,8 +204,7 @@ form
 
 
 (defun org-babel-expand-noweb-references (&optional info parent-buffer)
 (defun org-babel-expand-noweb-references (&optional info parent-buffer)
   "This function expands Noweb style references in the body of
   "This function expands Noweb style references in the body of
-the current source-code block.  The reference must be inside of a
-comment or it will be skipped.  For example the following
+the current source-code block.  For example the following
 reference would be replaced with the body of the source-code
 reference would be replaced with the body of the source-code
 block named 'example-block' (assuming the '#' character starts a
 block named 'example-block' (assuming the '#' character starts a
 comment) .
 comment) .