[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Babel should not work in the subtree marked as not exported
From: |
Nicolas Goaziou |
Subject: |
Re: [O] Babel should not work in the subtree marked as not exported |
Date: |
Mon, 24 Mar 2014 16:15:16 +0100 |
Hello,
Eric Schulte <address@hidden> writes:
> Nicolas Goaziou <address@hidden> writes:
>>
>> As a side note, I think `org-babel-under-commented-heading-p' is useful
>> enough (with an optional parameter to prevent inheritance, maybe) to be
>> moved into "org.el".
>>
>
> I agree.
Here is the patch.
Regards,
--
Nicolas Goaziou
>From 690543c40d766802df3e30e44ef7d6f04d6c18ba Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <address@hidden>
Date: Mon, 24 Mar 2014 16:12:12 +0100
Subject: [PATCH] Rename `org-babel-under-commented-heading-p'
* lisp/org.el (org-in-commented-heading-p): New function.
* lisp/ob-tangle.el (org-babel-under-commented-heading-p): Remove
function.
(org-babel-tangle-collect-blocks): Use new function.
* lisp/ob-exp.el (org-babel-exp-process-buffer): Use new function.
* testing/lisp/test-org.el (test-org/in-commented-heading-p): New
test.
---
lisp/ob-exp.el | 2 +-
lisp/ob-tangle.el | 18 +-----------------
lisp/org.el | 16 ++++++++++++++++
testing/lisp/test-org.el | 32 ++++++++++++++++++++++++++++++++
4 files changed, 50 insertions(+), 18 deletions(-)
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 0ddb4dc..3b63422 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -158,7 +158,7 @@ may make them unreachable."
"^[ \t]*#\\+BEGIN_SRC")))
(goto-char (point-min))
(while (re-search-forward regexp nil t)
- (unless (save-match-data (org-babel-under-commented-heading-p))
+ (unless (save-match-data (org-in-commented-heading-p))
(let* ((element (save-excursion
;; If match is inline, point is at its
;; end. Move backward so
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index bf67410..294a6ff 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -357,22 +357,6 @@ that the appropriate major-mode is set. SPEC has the form:
insert-comment
(org-fill-template org-babel-tangle-comment-format-end link-data)))))
-(defvar org-comment-string) ;; Defined in org.el
-(defun org-babel-under-commented-heading-p ()
- "Non-nil if point is under a commented heading.
-This function also checks ancestors of the current headline, if
-any."
- (cond
- ((org-before-first-heading-p) nil)
- ((let ((headline (nth 4 (org-heading-components))))
- (and headline
- (let ((case-fold-search nil))
- (org-string-match-p (concat "^" org-comment-string "\\(?: \\|$\\)")
- headline)))))
- (t (save-excursion
- (and (org-up-heading-safe)
- (org-babel-under-commented-heading-p))))))
-
(defun org-babel-tangle-collect-blocks (&optional language tangle-file)
"Collect source blocks in the current Org-mode file.
Return an association list of source-code block specifications of
@@ -396,7 +380,7 @@ can be used to limit the collected code blocks by target
file."
(let* ((info (org-babel-get-src-block-info 'light))
(src-lang (nth 0 info))
(src-tfile (cdr (assoc :tangle (nth 2 info)))))
- (unless (or (org-babel-under-commented-heading-p)
+ (unless (or (org-in-commented-heading-p)
(string= (cdr (assoc :tangle (nth 2 info))) "no")
(and tangle-file (not (equal tangle-file src-tfile))))
(unless (and language (not (string= language src-lang)))
diff --git a/lisp/org.el b/lisp/org.el
index 727f646..ef0bc3f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -23303,6 +23303,22 @@ This version does not only check the character
property, but also
;; Compatibility alias with Org versions < 7.8.03
(defalias 'org-on-heading-p 'org-at-heading-p)
+(defun org-in-commented-heading-p (&optional no-inheritance)
+ "Non-nil if point is under a commented heading.
+This function also checks ancestors of the current headline,
+unless optional argument NO-INHERITANCE is non-nil."
+ (cond
+ ((org-before-first-heading-p) nil)
+ ((let ((headline (nth 4 (org-heading-components))))
+ (and headline
+ (let ((case-fold-search nil))
+ (org-string-match-p (concat "^" org-comment-string "\\(?: \\|$\\)")
+ headline)))))
+ (no-inheritance nil)
+ (t (save-excursion
+ (and (org-up-heading-safe)
+ (org-in-commented-heading-p t))))))
+
(defun org-at-comment-p nil
"Is cursor in a line starting with a # character?"
(save-excursion
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 949392e..0144841 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -544,6 +544,38 @@
+;;; Headline
+
+(ert-deftest test-org/in-commented-heading-p ()
+ "Test `org-in-commented-heading-p' specifications."
+ ;; Commented headline.
+ (should
+ (org-test-with-temp-text "* COMMENT Headline\nBody"
+ (goto-char (point-max))
+ (org-in-commented-heading-p)))
+ ;; Commented ancestor.
+ (should
+ (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
+ (goto-char (point-max))
+ (org-in-commented-heading-p)))
+ ;; Comment keyword is case-sensitive.
+ (should-not
+ (org-test-with-temp-text "* Comment Headline\nBody"
+ (goto-char (point-max))
+ (org-in-commented-heading-p)))
+ ;; Keyword is standalone.
+ (should-not
+ (org-test-with-temp-text "* COMMENTHeadline\nBody"
+ (goto-char (point-max))
+ (org-in-commented-heading-p)))
+ ;; Optional argument.
+ (should-not
+ (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
+ (goto-char (point-max))
+ (org-in-commented-heading-p t))))
+
+
+
;;; Links
;;;; Coderefs
--
1.9.1
- Re: [O] Babel should not work in the subtree marked as not exported, (continued)
- Re: [O] Babel should not work in the subtree marked as not exported, Andreas Leha, 2014/03/14
- Re: [O] Babel should not work in the subtree marked as not exported, Eric Schulte, 2014/03/14
- Re: [O] Babel should not work in the subtree marked as not exported, zwz, 2014/03/15
- Re: [O] Babel should not work in the subtree marked as not exported, Nicolas Goaziou, 2014/03/15
- Re: [O] Babel should not work in the subtree marked as not exported, Eric Schulte, 2014/03/15
- Re: [O] Babel should not work in the subtree marked as not exported, Andreas Leha, 2014/03/17
- Re: [O] Babel should not work in the subtree marked as not exported,
Nicolas Goaziou <=
- Re: [O] Babel should not work in the subtree marked as not exported, Eric Schulte, 2014/03/24
- Re: [O] Babel should not work in the subtree marked as not exported, Bastien, 2014/03/24
- Re: [O] Babel should not work in the subtree marked as not exported, Eric Schulte, 2014/03/24
- Re: [O] Babel should not work in the subtree marked as not exported, Samuel Wales, 2014/03/24
- Re: [O] Babel should not work in the subtree marked as not exported, Samuel Wales, 2014/03/24
- Re: [O] Babel should not work in the subtree marked as not exported, Sebastien Vauban, 2014/03/14
Re: [O] Babel should not work in the subtree marked as not exported, Rainer M Krug, 2014/03/11
Re: [O] Babel should not work in the subtree marked as not exported, zwz, 2014/03/12