From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Babel should not work in the subtree marked as not exported Date: Mon, 24 Mar 2014 16:15:16 +0100 Message-ID: <87y4zzk4qj.fsf@gmail.com> References: <87wqg0gawq.fsf@gmail.com> <87lhwgettp.fsf@med.uni-goettingen.de> <87bnxbg02x.fsf@gmail.com> <87ha73dnxe.fsf@med.uni-goettingen.de> <87zjku41nq.fsf@gmail.com> <878usdemuv.fsf@med.uni-goettingen.de> <87eh25d22d.fsf@gmail.com> <874n31dvf8.fsf@med.uni-goettingen.de> <8738ik8rod.fsf@gmail.com> <871ty3tt8r.fsf@gmail.com> <8761ne270h.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WS6aZ-0000yY-1i for emacs-orgmode@gnu.org; Mon, 24 Mar 2014 11:15:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WS6aQ-00040l-Gu for emacs-orgmode@gnu.org; Mon, 24 Mar 2014 11:14:58 -0400 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]:53881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WS6aQ-00040d-6I for emacs-orgmode@gnu.org; Mon, 24 Mar 2014 11:14:50 -0400 Received: by mail-wg0-f52.google.com with SMTP id k14so3473065wgh.23 for ; Mon, 24 Mar 2014 08:14:49 -0700 (PDT) In-Reply-To: <8761ne270h.fsf@gmail.com> (Eric Schulte's message of "Sat, 15 Mar 2014 20:48:30 -0600") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: Andreas Leha , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Eric Schulte writes: > Nicolas Goaziou 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Rename-org-babel-under-commented-heading-p.patch >From 690543c40d766802df3e30e44ef7d6f04d6c18ba Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 --=-=-=--