forked from mirrors/org-mode
DONE new reference syntax *inside* source code blocks
noweb style references are now expanded on tangle
This commit is contained in:
parent
17b2008968
commit
227540bce1
|
@ -132,7 +132,7 @@ code blocks by language."
|
||||||
(format "block-%d" block-counter))))
|
(format "block-%d" block-counter))))
|
||||||
(info (org-babel-get-src-block-info))
|
(info (org-babel-get-src-block-info))
|
||||||
(src-lang (first info))
|
(src-lang (first info))
|
||||||
(body (second info))
|
(body (org-babel-expand-noweb-references info))
|
||||||
(params (third info))
|
(params (third info))
|
||||||
(spec (list link source-name params body))
|
(spec (list link source-name params body))
|
||||||
by-lang)
|
by-lang)
|
||||||
|
@ -176,35 +176,34 @@ comment) .
|
||||||
|
|
||||||
This function must be called from inside of the buffer containing
|
This function must be called from inside of the buffer containing
|
||||||
the source-code block which holds BODY."
|
the source-code block which holds BODY."
|
||||||
(interactive)
|
|
||||||
(let* ((parent-buffer (or parent-buffer (current-buffer)))
|
(let* ((parent-buffer (or parent-buffer (current-buffer)))
|
||||||
(info (or info (org-babel-get-src-block-info)))
|
(info (or info (org-babel-get-src-block-info)))
|
||||||
(lang (first info))
|
(lang (first info))
|
||||||
(body (second info))
|
(body (second info))
|
||||||
(new-body "") index source-name)
|
(new-body "") index source-name)
|
||||||
(with-temp-buffer
|
(flet ((nb-add (text)
|
||||||
(insert body) (goto-char (point-min))
|
(setq new-body (concat new-body text))))
|
||||||
(funcall (intern (concat lang "-mode")))
|
(with-temp-buffer
|
||||||
(setq index (point))
|
(insert body) (goto-char (point-min))
|
||||||
(while (and (re-search-forward "<<\\(.+\\)>>" nil t)
|
(funcall (intern (concat lang "-mode")))
|
||||||
(save-match-data (comment-beginning)))
|
|
||||||
(save-match-data (setf source-name (match-string 1)))
|
|
||||||
;; add interval to new-body
|
|
||||||
(goto-char (match-end 0))
|
|
||||||
(setq new-body (concat new-body (buffer-substring index (point))))
|
|
||||||
(setq index (point))
|
(setq index (point))
|
||||||
;; if found, add body of referenced source-block
|
(while (and (re-search-forward "<<\\(.+\\)>>" nil t)
|
||||||
(setq new-body
|
(save-match-data (comment-beginning)))
|
||||||
(concat new-body
|
(save-match-data (setf source-name (match-string 1)))
|
||||||
(save-excursion
|
;; add interval to new-body
|
||||||
(set-buffer parent-buffer)
|
(goto-char (match-end 0))
|
||||||
(let ((point (org-babel-find-named-block source-name)))
|
(nb-add (buffer-substring index (point)))
|
||||||
(if point
|
(setq index (point))
|
||||||
(save-excursion
|
;; if found, add body of referenced source-block
|
||||||
(goto-char point)
|
(nb-add (save-excursion
|
||||||
(concat "\n" (second (org-babel-get-src-block-info))))
|
(set-buffer parent-buffer)
|
||||||
""))))))
|
(let ((point (org-babel-find-named-block source-name)))
|
||||||
(setq new-body (concat new-body (buffer-substring index (point-max)))))
|
(if point
|
||||||
|
(save-excursion
|
||||||
|
(goto-char point)
|
||||||
|
(concat "\n" (second (org-babel-get-src-block-info))))
|
||||||
|
"")))))
|
||||||
|
(nb-add (buffer-substring index (point-max)))))
|
||||||
new-body))
|
new-body))
|
||||||
|
|
||||||
(provide 'org-babel-tangle)
|
(provide 'org-babel-tangle)
|
||||||
|
|
|
@ -207,39 +207,7 @@ would then be [[#sandbox][the sandbox]].
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
* Tasks [39/61]
|
* Tasks [40/61]
|
||||||
** STARTED new reference syntax *inside* source code blocks
|
|
||||||
This is from an email discussion on the org-mode mailing list with
|
|
||||||
Sébastien. The goal here is to mimic the source-block reference style
|
|
||||||
of Noweb. Upon export and/or tangle these references could be
|
|
||||||
replaced with the actual body of the referenced source-code block.
|
|
||||||
|
|
||||||
See the following for an example.
|
|
||||||
|
|
||||||
#+srcname: ems-ruby-print-header
|
|
||||||
#+begin_src ruby
|
|
||||||
puts "---------------------------header---------------------------"
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+srcname: emacs-ruby-print-footer
|
|
||||||
#+begin_src ruby
|
|
||||||
puts "---------------------------footer---------------------------"
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+srcname: ems-ruby-print-message
|
|
||||||
#+begin_src ruby :file ruby-noweb.rb
|
|
||||||
# <<ems-ruby-print-header>>
|
|
||||||
puts " Ruby "
|
|
||||||
# <<ems-ruby-print-footer>>
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Upon export the previous source-code block would result in a file
|
|
||||||
being generated at =ruby-noweb.rb= with the following contents
|
|
||||||
|
|
||||||
: puts "---------------------------header---------------------------"
|
|
||||||
: puts " Ruby "
|
|
||||||
: puts "---------------------------footer---------------------------"
|
|
||||||
|
|
||||||
** PROPOSED raise elisp error when source-blocks return errors
|
** PROPOSED raise elisp error when source-blocks return errors
|
||||||
Not sure how/if this would work, but it may be desirable.
|
Not sure how/if this would work, but it may be desirable.
|
||||||
|
|
||||||
|
@ -1172,6 +1140,42 @@ to the command if BUFF is not given.)
|
||||||
2) The function is called inside of a =write.table= function call
|
2) The function is called inside of a =write.table= function call
|
||||||
writing the results to a table
|
writing the results to a table
|
||||||
3) The table is read using =org-table-import=
|
3) The table is read using =org-table-import=
|
||||||
|
** DONE new reference syntax *inside* source code blocks
|
||||||
|
This is from an email discussion on the org-mode mailing list with
|
||||||
|
Sébastien. The goal here is to mimic the source-block reference style
|
||||||
|
of Noweb. Upon export and/or tangle these references could be
|
||||||
|
replaced with the actual body of the referenced source-code block.
|
||||||
|
|
||||||
|
See the following for an example.
|
||||||
|
|
||||||
|
#+srcname: ems-ruby-print-header
|
||||||
|
#+begin_src ruby
|
||||||
|
puts "---------------------------header---------------------------"
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: emacs-ruby-print-footer
|
||||||
|
#+begin_src ruby
|
||||||
|
puts "---------------------------footer---------------------------"
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: ems-ruby-print-message
|
||||||
|
#+begin_src ruby :file ruby-noweb.rb
|
||||||
|
# <<ems-ruby-print-header>>
|
||||||
|
puts " Ruby "
|
||||||
|
# <<ems-ruby-print-footer>>
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Upon export the previous source-code block would result in a file
|
||||||
|
being generated at =ruby-noweb.rb= with the following contents
|
||||||
|
|
||||||
|
: puts "---------------------------header---------------------------"
|
||||||
|
: puts " Ruby "
|
||||||
|
: puts "---------------------------footer---------------------------"
|
||||||
|
|
||||||
|
the body of a source-code block with all =<<src-name>>= references
|
||||||
|
expanded can now be returned by `org-babel-expand-noweb-references'.
|
||||||
|
This function is now called by default on all source-code blocks on
|
||||||
|
export.
|
||||||
|
|
||||||
** DONE re-work tangling system
|
** DONE re-work tangling system
|
||||||
Sometimes when tangling a file (e.g. when extracting elisp from a
|
Sometimes when tangling a file (e.g. when extracting elisp from a
|
||||||
|
|
|
@ -13,7 +13,7 @@ echo "line 2"
|
||||||
more text
|
more text
|
||||||
|
|
||||||
#+srcname: ruby-no-session
|
#+srcname: ruby-no-session
|
||||||
#+begin_src ruby :tangle yes
|
#+begin_src ruby
|
||||||
def hello
|
def hello
|
||||||
puts "hello world"
|
puts "hello world"
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ more text
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+srcname: ruby-with-noweb-references
|
#+srcname: ruby-with-noweb-references
|
||||||
#+begin_src ruby
|
#+begin_src ruby :tangle yes
|
||||||
# <<ruby-no-session>>
|
# <<ruby-no-session>>
|
||||||
hello()
|
hello()
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
Loading…
Reference in a new issue