emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Darlan Cavalcante Moreira <darcamo@gmail.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: How to add content from a file to a table automatically
Date: Thu, 10 Jan 2013 11:27:34 -0700	[thread overview]
Message-ID: <87zk0grizt.fsf@gmail.com> (raw)
In-Reply-To: <50ef04af.0839650a.7f7b.ffff9872@mx.google.com> (Darlan Cavalcante Moreira's message of "Thu, 10 Jan 2013 15:12:57 -0300")

Darlan Cavalcante Moreira <darcamo@gmail.com> writes:

> Thank you Eric and Jambunathan for your answers.
>
> If I process the whole table with babel to manually add the lines from the
> external file than I would have to take care of updating the formula for
> the "Total" value as well as making sure the new content was added before
> the "Total" line, right?. The later is simple, but updating the formula
> could be complicated.
>

Alternately, since the table is simply an array you could pass it to
another code block in your preferred language, and then perform the
total calculation on the array.  Then run `continually-run' on this
second code block.

>
> Meanwhile, I'm investigating using org-capture for this.
>

I'm not familiar with Org-capture myself, but the below sounds like a
good plan, I hope it works out.

If you do find a natural way to combine org-capture and Babel code
blocks I'm sure such a system would be of use to others on the list, so
please do share.

Best,

>
> For instance, if I use a template such as
> #+begin_src emacs-lisp
>   ("f" "test" table-line
>    (file+headline "test.org" "Test table")
>    (file "path/food.org")
>    :table-line-pos "II-1"
>    :immediate-finish t)
> #+end_src
> where the food.org file has a single line then I can capture with
> #+begin_src emacs-lisp
>   (org-capture nil "f")'
> #+end_src
> and org-capture will place the content from the "food.org" file in a table
> in the "Test Table" headline of the test.org file.
>
> The advantage of using org-capture instead of pure babel is that it will
> already put the content in the correct place and update the
> formulas. However, the formulas are updated correctly only if I capture a
> single line each time.
>
> I think a combination of babel with org-capture is my best option.
> Once that is working I will use your timer approach for automating this
> (while I investigate inotify suggested by Jambunathan).
>
> --
> Darlan
>
>
> At Wed, 09 Jan 2013 22:10:37 -0700,
> Eric Schulte wrote:
>> 
>> #+Title: Periodically Rerun a Code Block
>> 
>> Here's the lisp code to define a function to continually re-run a code
>> block.  Evaluate the following code block, then =M-x continually-run=,
>> press ENTER and then type in the name of the code block to continually
>> run (in this case "date").
>> #+begin_src emacs-lisp :results silent
>>   (defvar continual-runners nil
>>     "Holds running block timers (so they may be canceled).")
>>   
>>   (defun run-block-in-buffer (name buffer)
>>     (save-match-data
>>       (with-current-buffer buffer
>>         (save-excursion
>>           (org-babel-goto-named-src-block name)
>>           (with-local-quit
>>             (undo-boundary)
>>             (with-temp-message (format "re-running %s" name)
>>               (org-babel-execute-src-block))
>>             (undo-boundary))))))
>>   
>>   (defun continually-run (name)
>>     "Continually run the supplied code block name.
>>   The code block is assumed to be in the current buffer."
>>     (interactive "scode block to continually run: ")
>>     (let ((run-buffer (current-buffer)))
>>       (add-to-list 'continual-runners
>>                    (run-at-time nil 5 'run-block-in-buffer name run-buffer))))
>> #+end_src
>> 
>> Here's the code block to be continually re-run.
>> #+Name: date
>> #+begin_src sh
>>   date
>> #+end_src
>> 
>> And here are the results which will be continually updated.
>> #+RESULTS: date
>> : Wed Jan  9 22:04:08 MST 2013
>> 
>> Execute the following to stop all continually updating code blocks.
>> #+begin_src emacs-lisp :results silent
>>   (mapc #'cancel-timer continual-runners)
>> #+end_src

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

      reply	other threads:[~2013-01-10 18:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-10  3:25 How to add content from a file to a table automatically Darlan Cavalcante Moreira
2013-01-10  5:07 ` Usecase for inotify? " Jambunathan K
2013-01-10 18:58   ` Eli Zaretskii
2013-01-10  5:10 ` Eric Schulte
2013-01-10 18:12   ` Darlan Cavalcante Moreira
2013-01-10 18:27     ` Eric Schulte [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zk0grizt.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=darcamo@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).