From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: [BABEL] tangling with leaving non-source code lines as empty lines? Date: Thu, 15 Jul 2010 10:00:55 +0200 Message-ID: <4C3EC037.1070702@mail.com> References: <871vb8lgoq.fsf@gmail.com> <874og4qkdy.fsf@gmail.com> <4C3C1F66.1070604@googlemail.com> <871vb7wb3c.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=36398 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OZJNR-00052z-Po for emacs-orgmode@gnu.org; Thu, 15 Jul 2010 04:01:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OZJNO-00058h-DA for emacs-orgmode@gnu.org; Thu, 15 Jul 2010 04:01:03 -0400 Received: from mail-ww0-f49.google.com ([74.125.82.49]:47261) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OZJNO-00058O-4M for emacs-orgmode@gnu.org; Thu, 15 Jul 2010 04:01:02 -0400 Received: by wwb22 with SMTP id 22so131714wwb.30 for ; Thu, 15 Jul 2010 01:00:59 -0700 (PDT) In-Reply-To: <871vb7wb3c.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: emacs-orgmode , Dr Rainer M Krug -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 13/07/2010 19:22, Eric Schulte wrote: > Hi Rainer, > > Dr Rainer M Krug writes: > >> On 13/07/2010 02:46, Eric Schulte wrote: >>> Hi Rainer, >>> >>> With the tangling comments generated by the latest Org-mode, the >>> following function should be able to jump from any code in a tangled >>> code file back to the relevant block in the original Org-mode file. >> >> Wow - that was quick. >> >> Thanks. >> >>> >>> --8<---------------cut here---------------start------------->8--- >>> (defun org-babel-tangle-jump-to-org () >>> "Jump from a tangled code file to the related Org-mode file." >>> (interactive) >>> (let ((mid (point)) >>> target-buffer target-char >>> start end link path block-name) >>> (save-window-excursion >>> (save-excursion >>> (unless (and (re-search-backward org-bracket-link-analytic-regexp nil t) >>> (setq start (point)) >>> (setq link (match-string 0)) >>> (setq path (match-string 3)) >>> (setq block-name (match-string 5)) >>> (re-search-forward (concat " " (regexp-quote block-name) >>> " ends here[\n\r]") nil t) >>> (setq end (point)) >>> (< start mid) (< mid end)) >>> (error "not in tangled code"))) >>> (when (string-match "::" path) >>> (setq path (substring path 0 (match-beginning 0)))) >>> (find-file path) (setq target-buffer (current-buffer)) >>> (goto-char start) (org-open-link-from-string link) >>> (if (string-match "[^ \t\n\r]:\\([[:digit:]]+\\)" block-name) >>> (org-babel-next-src-block >>> (string-to-int (match-string 1 block-name))) >>> (org-babel-goto-named-src-block block-name)) >>> (setq target-char (point))) >>> (pop-to-buffer target-buffer) >>> (goto-char target-char))) >>> --8<---------------cut here---------------end--------------->8--- >>> >> >> I tried it out, and realised that one needs to name the blocks >> (#+srcname:) to be able to use it. Then it jumps to the code block in >> the org file. >> > > Have you tried this on un-named code blocks (with the latest Org-mode > from git)? It should work for those as well -- it parses the name, and > uses org-babel-next-src-block to jump down the appropriate number of > blocks. OK - I tried it this morning (after updating org-mode), and it is working even with unnamed blocks - perfect. > >> >> Two more things (As pointed out in the other email) would be nice: >> >> 1) it would be nice to jump to the line of code in the Org-mode file >> which corresponds to the line in the code file >> > > Agreed, I was planning on implementing this, it shouldn't be difficult. Great - thanks > >> >> 2) It would be brilliant, if one could call the function from the >> Org-file buffer and enter the line number and then jump to the block / >> line in the block. >> > > That's a great suggestions, I will certainly look at folding it in. Perfect - I am looking forward to that. > >> >> In addition: >> 3) it would be very useful, if this function could be used with >> non-named source blocks. >> > > As I said above, I /believe/ that it is usable as such now, however if > you could come up with an example where this fails, please do let me > know. Working - thanks. > >> >> But that function is already quite usefull. >> > > Great, I'll post any future improvements I make to this thread, and > please do let me know if you run across errant behavior or new > potentially useful behavior. I am looking forward to any additions, Cheers, Rainer > > Cheers -- Eric > >> >> Thanks, >> >> Rainer >> >> >>> This is too large of a block of untested code to push into Org-mode now, >>> however please give it a try, and let me know if you think this could be >>> generally useful. Hopefully after the feature-freeze we can fold >>> something like this into Babel to ease navigation between Org files and >>> their tangled offspring. >>> >>> Cheers -- Eric >>> >>> "Eric Schulte" writes: >>> >>>> Hi Rainer, >>>> >>>> If I'm understand you correctly you want the absolute position (by LOC) >>>> of the lines of R code to be the same in both the original org file and >>>> the tangled file or R code. I don't think this is possible. It is >>>> possible to tangle code blocks in any order (not just the order in which >>>> they appear in the original org file), so there are many valid tangling >>>> scenarios in which this feature could not work. >>>> >>>> Rather, I think that it may make sense to have a function for jumping >>>> back and forth between tangled code blocks and the related Org file. In >>>> that case the R errors could be followed to the tangled R code file, >>>> from which you could easily jump to the relevant line in the relevant >>>> code block in the Org file. If you are tangling with comments, then it >>>> should be possible to have a function called from a line in a tangled >>>> code file which when called >>>> >>>> 1) finds it's enclosing comments >>>> 2) remembers it's offset from the comments (which would then be it's >>>> offset in the code block in the Org file) >>>> 3) read the comment to learn which code block in which Org file it's >>>> tangled from >>>> 4) jump to the relevant line, in the relevant block, in the relevant >>>> file >>>> >>>> Similarly when called form within a code block in an Org file the >>>> function could >>>> >>>> 1) read it's header argument to find the relevant tangled code file >>>> 2) jump to that file >>>> 3) use the comments in that file to move to the appropriate section of >>>> code and related line >>>> >>>> I'll think about such a function, and if it makes sense to implement it >>>> apart from a more general "activate org-mode links in comments" minor >>>> mode. Any ideas or suggestions would be welcome! >>>> >>>> Thanks -- Eric >>>> >>>> Rainer M Krug writes: >>>> >>>>> Hi Eric, >>>>> >>>>> would it be possible, when tangling, to leave lines without source code in >>>>> the resulting code file as empty lines? The reasoning would be that error >>>>> messages (at least in R) give the line in which the error occurred. If the >>>>> line numbers in which the code sits would be preserved (by leaving empty >>>>> lines where no code is in the .org file), debugging would be much easier. >>>>> >>>>> By the way: I am using the after tangle hook and it works absolutely >>>>> perfectly. >>>>> >>>>> Thanks and cheers, >>>>> >>>>> Rainer -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkw+wDYACgkQoYgNqgF2egoNmgCeL1ypgjwjT82r60x6yEyT5FF6 VwgAnA1GkoyEX4GoQmYjtctI+Q2t6S2s =AVWc -----END PGP SIGNATURE-----