forked from mirrors/org-mode
Fix `org-babel-detangle' handling of false positives
* lisp/ob-tangle.el (org-babel-detangle): Handle false positive matches of `org-link-bracket-re'. * testing/examples/babel.el: New file for Babel detangle false positive test. * testing/examples/babel.org (detangle): Add detangle/false positive example. * testing/lisp/test-ob-tangle.el (ob-tangle/detangle-false-positive): Add test for detangle false positive.
This commit is contained in:
parent
6f113a5392
commit
010d1e3b6e
|
@ -516,14 +516,16 @@ which enable the original code blocks to be found."
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(let ((counter 0) new-body end)
|
(let ((counter 0) new-body end)
|
||||||
(while (re-search-forward org-link-bracket-re nil t)
|
(while (re-search-forward org-link-bracket-re nil t)
|
||||||
(when (re-search-forward
|
(if (and (match-string 2)
|
||||||
(concat " " (regexp-quote (match-string 2)) " ends here"))
|
(re-search-forward
|
||||||
(setq end (match-end 0))
|
(concat " " (regexp-quote (match-string 2)) " ends here") nil t))
|
||||||
(forward-line -1)
|
(progn (setq end (match-end 0))
|
||||||
(save-excursion
|
(forward-line -1)
|
||||||
(when (setq new-body (org-babel-tangle-jump-to-org))
|
(save-excursion
|
||||||
(org-babel-update-block-body new-body)))
|
(when (setq new-body (org-babel-tangle-jump-to-org))
|
||||||
(setq counter (+ 1 counter)))
|
(org-babel-update-block-body new-body)))
|
||||||
|
(setq counter (+ 1 counter)))
|
||||||
|
(setq end (point)))
|
||||||
(goto-char end))
|
(goto-char end))
|
||||||
(prog1 counter (message "Detangled %d code blocks" counter)))))
|
(prog1 counter (message "Detangled %d code blocks" counter)))))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
(string-match-p "^#[[:digit:]]+$" "#123")
|
||||||
|
|
||||||
|
;; [[id:73115FB0-6565-442B-BB95-50195A499EF4][detangle:1]]
|
||||||
|
;; detangle changes
|
||||||
|
;; linked content to detangle:1 ends here
|
|
@ -488,3 +488,16 @@ nil
|
||||||
#+BEGIN_SRC emacs-lisp :output-dir xxx :file foo.bar
|
#+BEGIN_SRC emacs-lisp :output-dir xxx :file foo.bar
|
||||||
nil
|
nil
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
* detangle
|
||||||
|
** false positive
|
||||||
|
The =[[= causes a false positive which ~org-babel-detangle~ should handle properly
|
||||||
|
#+begin_src emacs-lisp :tangle yes
|
||||||
|
(string-match-p "^#[[:digit:]]+$" "#123")
|
||||||
|
#+end_src
|
||||||
|
** linked content to detangle
|
||||||
|
:PROPERTIES:
|
||||||
|
:ID: 73115FB0-6565-442B-BB95-50195A499EF4
|
||||||
|
:END:
|
||||||
|
#+begin_src emacs-lisp :tangle yes :comments link
|
||||||
|
;; detangle
|
||||||
|
#+end_src
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'subr-x)
|
||||||
|
|
||||||
;; TODO
|
;; TODO
|
||||||
;; (ert-deftest ob-tangle/noweb-on-tangle ()
|
;; (ert-deftest ob-tangle/noweb-on-tangle ()
|
||||||
;; "Noweb header arguments tangle correctly.
|
;; "Noweb header arguments tangle correctly.
|
||||||
|
@ -380,6 +382,15 @@ another block
|
||||||
(org-split-string (buffer-string))))
|
(org-split-string (buffer-string))))
|
||||||
(delete-file file))))))
|
(delete-file file))))))
|
||||||
|
|
||||||
|
(ert-deftest ob-tangle/detangle-false-positive ()
|
||||||
|
"Test handling of false positive link during detangle."
|
||||||
|
(org-test-in-example-file (expand-file-name "babel.el" org-test-example-dir)
|
||||||
|
(org-babel-detangle)
|
||||||
|
(org-test-at-id "73115FB0-6565-442B-BB95-50195A499EF4"
|
||||||
|
(org-babel-next-src-block)
|
||||||
|
(should (equal (string-trim (org-element-property :value (org-element-at-point)))
|
||||||
|
";; detangle changes")))))
|
||||||
|
|
||||||
(provide 'test-ob-tangle)
|
(provide 'test-ob-tangle)
|
||||||
|
|
||||||
;;; test-ob-tangle.el ends here
|
;;; test-ob-tangle.el ends here
|
||||||
|
|
Loading…
Reference in New Issue