summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-09-15 16:00:10 -0600
committerEric Schulte <schulte.eric@gmail.com>2011-09-16 09:52:34 -0600
commitb9922ba879b9abf05532b9e9fd967cf8a63360e3 (patch)
tree7f463d4123ec04fc90034adbefc7709f0355eee7
parent37db5deea5ef75186bb7413b196fa0c96e5bdfb9 (diff)
downloadorg-mode-b9922ba879b9abf05532b9e9fd967cf8a63360e3.tar.gz
customizable processing of Org-mode text used as comments in tangled source-code files
* lisp/ob-tangle.el (org-babel-process-comment-text): Customizable function to process comment text. (org-babel-tangle-collect-blocks): Make use of new customizable processing function. (org-babel-spec-to-string): Call customizable function rather than `org-babel-trim'.
-rw-r--r--lisp/ob-tangle.el41
1 files changed, 25 insertions, 16 deletions
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index d1e26c0..10fc120 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -95,6 +95,14 @@ controlled by the :comments header argument."
:group 'org-babel
:type 'string)
+(defcustom org-babel-process-comment-text #'org-babel-trim
+ "Function called to process raw Org-mode text collected to be
+inserted as comments in tangled source-code files. The function
+should take a single string argument and return a string
+result. The default value is `org-babel-trim'."
+ :group 'org-babel
+ :type 'function)
+
(defun org-babel-find-file-noselect-refresh (file)
"Find file ensuring that the latest changes on disk are
represented in the file."
@@ -345,16 +353,18 @@ code blocks by language."
(when (or (string= "both" (cdr (assoc :comments params)))
(string= "org" (cdr (assoc :comments params))))
;; from the previous heading or code-block end
- (buffer-substring
- (max (condition-case nil
- (save-excursion
- (org-back-to-heading t) (point))
- (error 0))
- (save-excursion
- (re-search-backward
- org-babel-src-block-regexp nil t)
- (match-end 0)))
- (point))))
+ (funcall
+ org-babel-process-comment-text
+ (buffer-substring
+ (max (condition-case nil
+ (save-excursion
+ (org-back-to-heading t) (point))
+ (error 0))
+ (save-excursion
+ (re-search-backward
+ org-babel-src-block-regexp nil t)
+ (match-end 0)))
+ (point)))))
by-lang)
;; add the spec for this block to blocks under it's language
(setq by-lang (cdr (assoc src-lang blocks)))
@@ -396,12 +406,11 @@ form
(eval el))))
'(start-line file link source-name))))
(flet ((insert-comment (text)
- (let ((text (org-babel-trim text)))
- (when (and comments (not (string= comments "no"))
- (> (length text) 0))
- (when padline (insert "\n"))
- (comment-region (point) (progn (insert text) (point)))
- (end-of-line nil) (insert "\n")))))
+ (when (and comments (not (string= comments "no"))
+ (> (length text) 0))
+ (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