ob-tangle: only create links for blocks that will actually tangle

this commit includes a unit test

* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): only create
  links for blocks that will actually tangle
This commit is contained in:
Eric Schulte 2010-10-14 17:15:11 -06:00
parent 03cbc9fc28
commit d32c8d49e5
3 changed files with 30 additions and 3 deletions

View File

@ -276,11 +276,12 @@ code blocks by language."
(let* ((start-line (save-restriction (widen)
(+ 1 (line-number-at-pos (point)))))
(file (buffer-file-name))
(link (progn (call-interactively 'org-store-link)
(org-babel-clean-text-properties
(car (pop org-stored-links)))))
(info (org-babel-get-src-block-info))
(params (nth 2 info))
(link (unless (string= (cdr (assoc :tangle params)) "no")
(progn (call-interactively 'org-store-link)
(org-babel-clean-text-properties
(car (pop org-stored-links))))))
(source-name (intern (or (nth 4 info)
(format "%s:%d"
current-heading block-counter))))

View File

@ -41,3 +41,21 @@
#+results:
: 4
* excessive id links on tangling
:PROPERTIES:
:ID: ef06fd7f-012b-4fde-87a2-2ae91504ea7e
:END:
** no, don't give me an ID
#+begin_src emacs-lisp :tangle no
(message "not to be tangled")
#+end_src
** yes, I'd love an ID
:PROPERTIES:
:ID: ae7b55ca-9ef2-4d30-bd48-da30e35fd0f3
:END:
#+begin_src emacs-lisp :tangle no
(message "for tangling")
#+end_src

View File

@ -43,6 +43,14 @@
(should-not (exp-p "no"))
(should (exp-p "tangle"))))))
(ert-deftest ob-tangle/no-excessive-id-insertion-on-tangle ()
"Don't add IDs to headings without tangling code blocks."
(org-test-at-id "ae7b55ca-9ef2-4d30-bd48-da30e35fd0f3"
(org-babel-next-src-block)
(org-babel-tangle)
(org-babel-previous-src-block)
(should (null (org-id-get)))))
(provide 'test-ob-tangle)
;;; test-ob-tangle.el ends here