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))))
|
||||
(info (org-babel-get-src-block-info))
|
||||
(src-lang (first info))
|
||||
(body (second info))
|
||||
(body (org-babel-expand-noweb-references info))
|
||||
(params (third info))
|
||||
(spec (list link source-name params body))
|
||||
by-lang)
|
||||
|
@ -176,35 +176,34 @@ comment) .
|
|||
|
||||
This function must be called from inside of the buffer containing
|
||||
the source-code block which holds BODY."
|
||||
(interactive)
|
||||
(let* ((parent-buffer (or parent-buffer (current-buffer)))
|
||||
(info (or info (org-babel-get-src-block-info)))
|
||||
(lang (first info))
|
||||
(body (second info))
|
||||
(new-body "") index source-name)
|
||||
(with-temp-buffer
|
||||
(insert body) (goto-char (point-min))
|
||||
(funcall (intern (concat lang "-mode")))
|
||||
(setq index (point))
|
||||
(while (and (re-search-forward "<<\\(.+\\)>>" nil t)
|
||||
(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))))
|
||||
(flet ((nb-add (text)
|
||||
(setq new-body (concat new-body text))))
|
||||
(with-temp-buffer
|
||||
(insert body) (goto-char (point-min))
|
||||
(funcall (intern (concat lang "-mode")))
|
||||
(setq index (point))
|
||||
;; if found, add body of referenced source-block
|
||||
(setq new-body
|
||||
(concat new-body
|
||||
(save-excursion
|
||||
(set-buffer parent-buffer)
|
||||
(let ((point (org-babel-find-named-block source-name)))
|
||||
(if point
|
||||
(save-excursion
|
||||
(goto-char point)
|
||||
(concat "\n" (second (org-babel-get-src-block-info))))
|
||||
""))))))
|
||||
(setq new-body (concat new-body (buffer-substring index (point-max)))))
|
||||
(while (and (re-search-forward "<<\\(.+\\)>>" nil t)
|
||||
(save-match-data (comment-beginning)))
|
||||
(save-match-data (setf source-name (match-string 1)))
|
||||
;; add interval to new-body
|
||||
(goto-char (match-end 0))
|
||||
(nb-add (buffer-substring index (point)))
|
||||
(setq index (point))
|
||||
;; if found, add body of referenced source-block
|
||||
(nb-add (save-excursion
|
||||
(set-buffer parent-buffer)
|
||||
(let ((point (org-babel-find-named-block source-name)))
|
||||
(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))
|
||||
|
||||
(provide 'org-babel-tangle)
|
||||
|
|
|
@ -207,39 +207,7 @@ would then be [[#sandbox][the sandbox]].
|
|||
#+end_src
|
||||
|
||||
|
||||
* Tasks [39/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---------------------------"
|
||||
|
||||
* Tasks [40/61]
|
||||
** PROPOSED raise elisp error when source-blocks return errors
|
||||
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
|
||||
writing the results to a table
|
||||
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
|
||||
Sometimes when tangling a file (e.g. when extracting elisp from a
|
||||
|
|
|
@ -13,7 +13,7 @@ echo "line 2"
|
|||
more text
|
||||
|
||||
#+srcname: ruby-no-session
|
||||
#+begin_src ruby :tangle yes
|
||||
#+begin_src ruby
|
||||
def hello
|
||||
puts "hello world"
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ more text
|
|||
#+end_src
|
||||
|
||||
#+srcname: ruby-with-noweb-references
|
||||
#+begin_src ruby
|
||||
#+begin_src ruby :tangle yes
|
||||
# <<ruby-no-session>>
|
||||
hello()
|
||||
#+end_src
|
||||
|
|
Loading…
Reference in New Issue