diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2014-03-24 16:12:12 +0100 |
---|---|---|
committer | Eric Schulte <schulte.eric@gmail.com> | 2014-03-24 13:29:42 -0400 |
commit | 6d1d61f66775818c27505953afbb36fe3f6427b3 (patch) | |
tree | 42da1cddc8f9c5d2f0b63c26038ed152e4ea73cc | |
parent | 230d09aeb0a9914ed1c5e377b0b84b7064370c6d (diff) | |
download | org-mode-6d1d61f66775818c27505953afbb36fe3f6427b3.tar.gz |
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.
-rw-r--r-- | lisp/ob-exp.el | 2 | ||||
-rw-r--r-- | lisp/ob-tangle.el | 18 | ||||
-rw-r--r-- | lisp/org.el | 16 | ||||
-rw-r--r-- | 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 |