From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: Andreas Leha <andreas.leha@med.uni-goettingen.de>, emacs-orgmode@gnu.org
Subject: Re: Babel should not work in the subtree marked as not exported
Date: Mon, 24 Mar 2014 16:15:16 +0100 [thread overview]
Message-ID: <87y4zzk4qj.fsf@gmail.com> (raw)
In-Reply-To: <8761ne270h.fsf@gmail.com> (Eric Schulte's message of "Sat, 15 Mar 2014 20:48:30 -0600")
[-- Attachment #1: Type: text/plain, Size: 348 bytes --]
Hello,
Eric Schulte <schulte.eric@gmail.com> writes:
> Nicolas Goaziou <n.goaziou@gmail.com> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Rename-org-babel-under-commented-heading-p.patch --]
[-- Type: text/x-diff, Size: 5141 bytes --]
From 690543c40d766802df3e30e44ef7d6f04d6c18ba Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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 @@
\f
+;;; 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))))
+
+
+\f
;;; Links
;;;; Coderefs
--
1.9.1
next prev parent reply other threads:[~2014-03-24 15:15 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-11 12:47 Babel should not work in the subtree marked as not exported zwz
2014-03-11 13:27 ` Ken Mankoff
2014-03-11 13:41 ` Andreas Leha
2014-03-11 13:57 ` Ken Mankoff
2014-03-12 10:53 ` zwz
2014-03-12 22:58 ` Andreas Leha
2014-03-13 14:24 ` Eric Schulte
2014-03-13 22:48 ` Andreas Leha
2014-03-14 1:03 ` Eric Schulte
2014-03-14 5:44 ` Samuel Wales
2014-03-14 13:02 ` zwz
2014-03-14 19:10 ` Samuel Wales
2014-03-14 5:48 ` Samuel Wales
2014-03-14 8:40 ` Sebastien Vauban
2014-03-14 8:41 ` Andreas Leha
2014-03-14 19:59 ` Eric Schulte
2014-03-15 13:54 ` zwz
2014-03-15 14:46 ` Nicolas Goaziou
2014-03-16 2:48 ` Eric Schulte
2014-03-17 21:13 ` Andreas Leha
2014-03-24 15:15 ` Nicolas Goaziou [this message]
2014-03-24 16:05 ` Eric Schulte
2014-03-24 16:21 ` Bastien
2014-03-24 17:28 ` Eric Schulte
2014-03-24 18:06 ` Samuel Wales
2014-03-24 18:49 ` Samuel Wales
2014-03-14 1:10 ` John Hendy
2014-03-14 8:34 ` Sebastien Vauban
2014-03-11 14:03 ` Rainer M Krug
2014-03-12 9:23 ` Sebastien Vauban
2014-03-12 10:46 ` zwz
2014-03-12 11:02 ` zwz
2014-03-12 15:00 ` John Hendy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y4zzk4qj.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=andreas.leha@med.uni-goettingen.de \
--cc=emacs-orgmode@gnu.org \
--cc=schulte.eric@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).