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,12 +176,13 @@ 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)
|
||||||
|
(flet ((nb-add (text)
|
||||||
|
(setq new-body (concat new-body text))))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert body) (goto-char (point-min))
|
(insert body) (goto-char (point-min))
|
||||||
(funcall (intern (concat lang "-mode")))
|
(funcall (intern (concat lang "-mode")))
|
||||||
|
@ -191,20 +192,18 @@ the source-code block which holds BODY."
|
||||||
(save-match-data (setf source-name (match-string 1)))
|
(save-match-data (setf source-name (match-string 1)))
|
||||||
;; add interval to new-body
|
;; add interval to new-body
|
||||||
(goto-char (match-end 0))
|
(goto-char (match-end 0))
|
||||||
(setq new-body (concat new-body (buffer-substring index (point))))
|
(nb-add (buffer-substring index (point)))
|
||||||
(setq index (point))
|
(setq index (point))
|
||||||
;; if found, add body of referenced source-block
|
;; if found, add body of referenced source-block
|
||||||
(setq new-body
|
(nb-add (save-excursion
|
||||||
(concat new-body
|
|
||||||
(save-excursion
|
|
||||||
(set-buffer parent-buffer)
|
(set-buffer parent-buffer)
|
||||||
(let ((point (org-babel-find-named-block source-name)))
|
(let ((point (org-babel-find-named-block source-name)))
|
||||||
(if point
|
(if point
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char point)
|
(goto-char point)
|
||||||
(concat "\n" (second (org-babel-get-src-block-info))))
|
(concat "\n" (second (org-babel-get-src-block-info))))
|
||||||
""))))))
|
"")))))
|
||||||
(setq new-body (concat new-body (buffer-substring index (point-max)))))
|
(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