Re: [Orgmode] Re: [babel] Painless integration of source blocks with language

2011-01-24 Thread Seth Burleigh
> You are correct, while the tangling works, the detangling still needs to
> be updated to take into account the fact that there may now be nested
> sections of tangled code -- which it doesn't currently.  Hopefully this
> wont be too large of a code change...
>

It probably wouldnt involve much code change, since there is very few
functions which operate on tangled files - detangle and jump to source
block?
It would be a good time to implement some functions, maybe like this,
which did operate on tangled files -

org-babel-detangle-src-block-info
which, given a point on the line of a link, would produced something like
((end . '(0 100)) (middle . (10 90)) (children . (((end . (20 30))
...) ... more children))
where end is the position in the buffer from the beginning of the link
to the end of the matching end link, and middle is the body portion.

. Then define a function which maps over
all of the detangled toplevel src blocks of a file(like what is done
for tangled src blocks).

And then one could call org-babel-detangle-src-block which would do
some recursive detangling


if has children, detangle children
get body string
replace the children in body string (using end) with appropriate noweb syntax
replace appropriate org block with code

and then you could call org-babel-detangle which would detangle all of
a file, using the map function mentioned previously to collect all
source blocks.

(with-error
  detangle all toplevel blocks of file
)

where with-error will catch any errors, replace org file with original
content if an error is thrown, and then reraise the error.

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: [babel] Painless integration of source blocks with language

2011-01-18 Thread Seth Burleigh
ok, so im not sure how you got it working, but heres the problem in
the code (i think).

We start with the tangled output
--
;; [[file:~/Desktop/test.org][/home/seth/Desktop/test\.org:2]]

(let ((x 1))
  (message "x=%s" x)
  ;; [[file:~/Desktop/test.org][wrappable]]
  (setq x (+ 4 x))
  ;; wrappable ends here
  (message "x=%s" x))
;;>> before org-babel-detangle calls org-babel-tangle-jump-to-org, it
is at this point
;; /home/seth/Desktop/test\.org:2 ends here
--

The code jumps to the point marked above (notice any comment with ;;>>
is just my markup)
So, lets go to the relevant portion of org-babel-tangle-jump-to-org.

--
(defun org-babel-tangle-jump-to-org ()
  "Jump from a tangled code file to the related Org-mode file."
  (interactive)
  (let ((mid (point))
start end done
target-buffer target-char link path block-name body)
(save-window-excursion
  (save-excursion
(while (and (re-search-backward org-bracket-link-analytic-regexp nil t)
(not ; ever wider searches until matching block comments
 (and (setq start (point-at-eol))
  (setq link (match-string 0))
  (setq path (match-string 3))
  (setq block-name (match-string 5))
  (save-excursion
(save-match-data
  (re-search-forward
   (concat " " (regexp-quote block-name)
   " ends here") nil t)
  (setq end (point-at-bol
;;(message "start %s mid %s end %s" start mid end)
(unless (and start (< start mid) (< mid end))
  (error (format "not in tangled code %s %s %s " start mid end)))
---


notice that mid is set to the point commented previously. Then it
searches backward for org-bracket-link-analytic-regexp , and it finds
;; [[file:~/Desktop/test.org][wrappable]]. Then it searches forward
and matches ;; wrappable ends here. So, start and end encompass the
inner block, but the mid point is in the outside block. Therefore, it
fails with the error message

(unless (and start (< start mid) (< mid end))
  (error (format "not in tangled code %s %s %s " start mid end)))

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: [babel] Painless integration of source blocks with language

2011-01-18 Thread Seth Burleigh
>
>
> Please try using a decent sender, or at least no HTML. I know this cannot
> be
> obvious, though, but look at the results:
>
>
>
Not to get off on a tanget, but im using gmail. Looks perfect in my gmail
account - i guess your email doesnt support html markup? I just reply to
all, and it automatically does the markup. I guess ill have to learn how to
disable it:)
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: [babel] Painless integration of source blocks with language

2011-01-18 Thread Seth Burleigh
> Your cursor must be on a code line, not on a special "comments" line. I've
> had

the same behavior once. Just move down your cursor one or two lines away...
>
>
 Are you saying you have succesfully detangled noweb embedded code? If so,
ill have to take a look at the code to see where the bug is. It doesn't work
no matter where i place my cursor. My tangled output is also different -

;; [[file:~/Desktop/test.org][/home/seth/Desktop/test\.org:2]]

(let ((x 1))
  (message "x=%s" x)
  ;; [[file:~/Desktop/test.org][wrappable]]
  (setq x (+ 4 x))
  ;; wrappable ends here
  (message "x=%s" x))

;; /home/seth/Desktop/test\.org:2 ends here


Notice that detangling works if there is no noweb being used.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] [babel] Painless integration of source blocks with language

2011-01-17 Thread Seth Burleigh
On Sun, Jan 16, 2011 at 9:31 AM, Eric Schulte wrote:

>
> #+source: wrappable
> #+begin_src emacs-lisp
>  (setq x (+ 4 x))
> #+end_src
>
> #+begin_src emacs-lisp :comments noweb :noweb yes :tangle yes
>  (let ((x 1))
>(message "x=%s" x)
><>
>(message "x=%s" x))
> #+end_src
>
> which tangles out the following emacs-lisp
> #+begin_src emacs-lisp
>  ;; [[file:~/src/babel-dev/scraps.org:
> :*wrap%20noweb%20references%20in%20comments][wrap-noweb-references-in-comments:2]]
>  (let ((x 1))
>(message "x=%s" x)
>;; [[file:~/src/babel-dev/scraps.org:
> :*wrap%20noweb%20references%20in%20comments][wrappable]]
>(setq x (+ 4 x))
>;; wrappable ends here
>(message "x=%s" x))
>  ;; wrap-noweb-references-in-comments:2 ends here
> #+end_src
>
> Cheers -- Eric
>


Cool! Does it yet support detangling? I tried it out and it said i wasnt in
a tangle code.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] [babel] Painless integration of source blocks with language

2011-01-13 Thread Seth Burleigh
>As for how to trace back through noweb links, the best option seem to be
>using the existing jump function to navigate from raw source to the
>embedded block, keeping track of the point's offset form the beginning
>of the block, then using `org-babel-expand-src-block' to expand the body
>of the embedded code block marking noweb references with text properties
>as they are inserted into the expanding body, and then using the point
>offset to place the point into the appropriate noweb reference.  This
>process could then recurse on the embedded noweb code block until it
>ends up in a non-noweb portion of an expanded code block body.

If you dont have any comment anchors in the text, how would you know which
 noweb block you are in? If your org file and raw files are synched, then
you could, but if they become unsynched, which is the way it should be
(change raw code until done, then detangle to org), i dont exactly see how
you can do it.

The only option which allows someone to change the raw text file is to use
comment anchors - or you could save marks in a separate file, but this
wouldn't  allow for offline editing unless you open it with a program that
understands this format. With the comment method, you get the raw file
advantage, plus emacs can hide these comments if one makes a minor mode to
do so - a win win situation, i think, except for the aforementioned
shortcomings.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] [babel][bug] \ in detangling

2011-01-13 Thread Seth Burleigh
Ive attached the file it fails on. Notice that it fails below the constants
macro, but if you're above it, it will succeed since it wont find the [[name
val]]


general.clj
Description: Binary data
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] [babel][bug] \ in detangling

2011-01-13 Thread Seth Burleigh
thanks. also, when trying to detangle my code, i found another bug.

In the functions org-babel-tangle-jump-to--org and org-babel-detangle, it
uses  org-bracket-link-analytic-regexp to search for the [[file:]] links.
However, it does not include the comment in the regex (";;" in clojure), so
somehow [[name val]] in my code is matched as a link, and then it fails to
detangle.
Also, related, it doesnt include the comment in the regex to find the end of
the block, it just does (concat " " (regexp-quote block-name) " ends here").

Since i only want to detangle clojure code, i simply put this in my .emacs
file to fix it
 (setq org-bracket-link-analytic-regexp
(concat ";;[ ]*"
 "\\[\\["
 "\\(\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):\\)?"
 "\\([^]]+\\)"
 "\\]"
 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
 "\\]"
 ))

I suppose one would have to customize the first two comments per language.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] [babel][bug] \ in detangling

2011-01-13 Thread Seth Burleigh
(defun org-babel-update-block-body (new-body)
  "Update the body of the current code block to NEW-BODY."
  (if (not (org-babel-where-is-src-block-head))
  (error "not in source block")
(save-match-data
  (replace-match (concat (org-babel-trim new-body) "\n") nil t nil 5))
(indent-rigidly (match-beginning 5) (match-end 5) 2)))

replace-match argument should be t instead of nil (as shown), otherwise \ is
treated as a special character and you cant detangle code with that
character in it.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] [babel] Painless integration of source blocks with language

2011-01-13 Thread Seth Burleigh
I would just like to throw in a quick idea.
The easiest way to support noweb tangling is to get org-babel-tangle to
create nested tags and change detangle to take these into account.

for example, i have the forex_user source block that is tangled.

;; [[file:~/Dropbox/.rep/clj-forex/clj-forex.org::*User][forex_user]]
my code...
;; [[file:~/Dropbox/.rep/clj-forex/clj-forex.org::*User][embedded_block]]
my embedded code ...
;; embedded_block ends here
;; forex_user ends here

corresponding to a forex_user block of
#+begin_src
  my code ...
  <>
#+end_src

This would only work for noweb on separate lines and preferably only when
one block is noweb embedded into one other source block, but i believe that
this is the most common case anyways. This could be enforced in the
detangle/tangle code.

Then, a separate minor mode could make these file: markers invisible and
create a colored overlay pattern per source block code. Saving the file
would still save the markers, you just wouldnt see them if the minor mode
was on.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] [babel] Painless integration of source blocks with language

2011-01-11 Thread Seth Burleigh
woops, what i actually meant is that noweb doesnt work. I was thinking about
it, and it might be possible to
(a) automatically create overlays around begin_src blocks using
auto-overlays
(b) have a custom syntax parser that parses noweb syntax in those blocks.
 Sort of like what is done for syntax highlighting.

Im gradually converting my code to literate programming and am just on the
verge of splitting up my one clojure ns to  one-block org file into multiple
blocks per ns, so i will soon need the noweb functionality. When i get it
ill make sure to post and update!
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: [babel] Painless integration of source blocks with language

2011-01-09 Thread Seth Burleigh
and i misspoke also, the previous .org file wouldnt work since that uses
noweb. Heres a simple new example.


test.org
Description: Binary data
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: [babel] Painless integration of source blocks with language

2011-01-09 Thread Seth Burleigh
My bad. I believe i did look up the functions, but they didn't do what i
needed (or so i thought).
The code doesn't matter too much, let me explain the idea.

A file may contain many blocks of code. Lets look at a arbitrary block A. In
the end, block A will somehow become noweb embedded into a source block
which is actually tangled to a file. Lets call this source block C.
find-chunk finds this source block, given the position of block A, checking
also that the source has a type of "clojure". So, basically it searches for
the string <>, if it finds it, checks if the source block (with an
arbitrary name, lets say my-block) is tangled, if not, it searches for
<> until it actually finds a tangled source block.

tangle-chunk is used to tangle block A by finding block C (using find-chunk)
and tangling that. It is basically copied from org-babel except that it uses
mkdir to create any parent directories that do not exist (i think this
should be included as an option in tangle file, btw, if it isn't)

So, conceptually we have many blocks which are noweb embedded into various
source files, however indirectly. We want to find the source files that
these blocks are embedded in so that we can (in the future) navigate from
the block to the file number.
 '
Thats all that does, from line 110 up. I copied it from my previous posting.
>From below that, i implement an emacs overlay, created by new-chunk.
Basically all it does is associate a chunk of code in the buffer to a chunk
of code in another chunk. We can 'add a link', i.e. append a chunk to its
'lp-link property.

Next, we add the ability to replace the code of one chunk with another. This
is what push-chunk does. Now, all that we have left is the code to create
chunks from source blocks.

Pushing code from one chunk to another code work with noweb embedding, but
it was just a proof of concept anyways.

What i was imagining when i did this is that i would have a source code file
which has various 'chunks' highlighted in different colors (various
background colors), each having a 'link' to the appropriate source code
chunk in the babel file. Thus, we could push changes from the source code
files to the org-mode file and navigate between. This would eliminate the
code markers. I was imagining that the tangled source code files could be
viewed simply as an indirect buffer created from the org file, so we
wouldn't need code markers to save the chunk info for future sessions - we
would just generate it all from the org-file.

 What is needed now is to be able to push from one chunk to another, except
leaving any <> blocks as they are.  With that, i believe the ideas
mentioned in the first post could be fully implemented.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: [babel] Painless integration of source blocks with language

2011-01-09 Thread Seth Burleigh
As an update, ive been working on something i call chunks.
Basically, they are blocks of code (i.e. emacs overlays) that are linked
together.
So far, i have each ns of my clojure code in one source block which is
then tangled to one file.
So, i would like to open the tangled file and then make changes, and finally
'push' those changes to the org file.

Theres some bugs (pushing when mark is next to a parantheses), but i think
it is going in the correct way to also include noweb tangling. In the
attached code, you hit f8 in a source block to link the block to its file
and then f8 if you want to unlink it, and you hit ctrl-alt-p to push changes
from source file to org file.

just execute lp.el in an ielm buffer. and try it out with the previous test
org file that was attached.


lp.el
Description: Binary data
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] [babel] Painless integration of source blocks with language

2011-01-08 Thread Seth Burleigh
Preface: I hope attachments show up, i dont know if they are allowed 

Im currently interested in using babel for a medium size clojure project. I
think the below propositions would greatly benefit babel in accomplishing
literate programming.

First part of the proposal to make this painless:

In a literate document, you might very well have small chunks of code for
one ns scattered around and then finally combined using noweb into one file
and tangle the output. Currently, keys like
compile-file (C-c C-k), goto function definition (M-.), do not work at all
in the source blocks. This is unfortunate, and makes life very painful. So,
first we need to get these keys to work.
Heres how it can possibly be done.

Lets say we want to compile the code in block A. Block B uses noweb syntax
to import block A, and then tangles to file src/B.clj. So we need to search
for  the presence of <> in a tangled code chunk , tangle the chunk to a
file, go to the file buffer and position the cursor at the correct relative
position, and then invoke the appropriate function (in this case,
slime-compile-and-load-file).

Ive attached two files which do this, the first one is an example org file
in which you can use the compile keystrokes on (after opening a slime server
for clojure). However, it doesnt position the cursor in the tangled file
correctly, but this is not needed for compile/load file. Its not a very good
implementation, but it works for this case. Also, it doesn't work when the
indirect buffer created by C-c '  is open. The advantage of this method is
that it can easily be generalized to any language, since the compiler gets
what it expects - a file of code to operate on.

Second part of proposal:

Literate documents are good for documentation, but if you're the author, you
dont need the documentation and it will certainly get in the way of you
writing code to keep having to type C-c ' to open various chunks of code.
Ideally, we would like to have our file of code (that is, the tangled file
output for one ns in clojure) as the top buffer, and our documentation at
the bottom. Changes to the code will automatically reflect itself in the
documentation (after a save). In order to accomplish this, there has to be a
method to map from tangled file line number, to the correct chunk name and
line number in the .org file. This might be accomplished by tangling code
like this:
;;#chunk-name
..code
;;#

I think this would be much more natural than editing each chunk separately.
Of course, the ;;# might become an annoyance, but im sure there might  be a
better way.
With this mapping , we can develop the code until we get it right. Then we
can hit a keystroke and have our documentation jump to the correct line
number in the .org file, and then do all the documentation for that.

With the line mapping ability also comes the ability to map errors in the
line number to numbers in the org file. Although, this probably wouldn't be
necessary, since we would be looking at the combined chunk file.


Any thoughts/ideas how to implement this?


test.org
Description: Binary data


seth-obj-clj.el
Description: Binary data
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] [babel] How to fontify blocks other than begin_src?

2011-01-07 Thread Seth Burleigh
Thanks, it does. Yep, i looked at the code, and everything was  based on
begin_src - so i think i will keep it at that!
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] [babel] How to fontify blocks other than begin_src?

2011-01-07 Thread Seth Burleigh
I would like blocks like begin_html/end_html to be fontified just like
begin_src blocks are.
I would also like to define my own source blocks for clojure (basically a
shorthand) and also have them highlighted. Heres what i have to turn on
fontifying and define a block.

(setq org-src-fontify-natively t)
;; define #+clj as start of clojure code block and #+end as end of block
(add-to-list 'org-edit-src-region-extra
   '("^[ \t]*#\\+clj.*\n" "\n[ \t]*#\\+end" "clojure"))

Ive also noticed that the code block (#+clj ... #+end) doesnt fold -
however, if i define the block as begin_clj and end_clj it will fold, so im
guessing org assumes a certain block format for folding code.

Any way to do the above two things?
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] [Babel][BUG] Executing python code fails due to indentation error

2010-09-08 Thread Seth Burleigh
Youre right, without a session it works, but with a session it doesn't. Any
pointers for why this wouldn't work in the shell? I really need python for

On Tue, Sep 7, 2010 at 5:44 PM, Eric Schulte  wrote:

> Hi Seth,
>
> This works fine for me with external evaluation, e.g.
> --8<---cut here---start->8---
> #+begin_src python
> def add(a,b):
>   return a+b
> def sub(a,b):
>   return a-b
> return add(sub(10,1),sub(10,2))
> #+end_src
>
> #+results:
> : 17
> --8<---cut here---end--->8---
>
> I did notice that when I added a ":session test" header argument the
> interactive shell output the error you mentioned.  This issue would have
> to be resolved by the Python inferior process either python-mode or
> python-shell.
>
> Best -- Eric
>
> Seth Burleigh  writes:
>
> > #+begin_src python
> > def add(a,b):
> >return a+b
> > def sub(a,b):
> >return a-b
> > #+end_src
> >
> > Fails to execute due to 'unexpected indentation' in general, this is a
> > problem for copy/pasting into any emacs python shell, it wont work.
> > ___
> > Emacs-orgmode mailing list
> > Please use `Reply All' to send replies to the list.
> > Emacs-orgmode@gnu.org
> > http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] [Babel][BUG] Executing python code fails due to indentation error

2010-09-07 Thread Seth Burleigh
#+begin_src python
def add(a,b):
   return a+b
def sub(a,b):
   return a-b
#+end_src

Fails to execute due to 'unexpected indentation' in general, this is a
problem for copy/pasting into any emacs python shell, it wont work.
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] [babel] python session speed vs non session

2010-09-06 Thread Seth Burleigh
I have recently been trying out the src executing capabilities of orgmode. I
have been confused why a python session takes significantly longer to
execute than a non python session. For example

#+begin_src python
return 2+2
#+end_src

executes pretty quickly, but
#+begin_src python :session test
2+2
#+end_src

executes twice as long. Looking at the command shell for python, it seems
that the time is being taken to actually send the source to the command
shell buffer. Once its sent (or once i can see it displayed in the command
shell buffer) it immediately returns. Any ideas?
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode