From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: How to add content from a file to a table automatically Date: Wed, 09 Jan 2013 22:10:37 -0700 Message-ID: <87txqpy65u.fsf@gmail.com> References: <50ee34c8.09fb640a.6b64.0e5a@mx.google.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:50651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtAPb-0002KM-Fw for emacs-orgmode@gnu.org; Thu, 10 Jan 2013 00:10:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TtAPZ-0005gd-UR for emacs-orgmode@gnu.org; Thu, 10 Jan 2013 00:10:43 -0500 Received: from mail-ia0-f172.google.com ([209.85.210.172]:39535) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtAPZ-0005gW-P6 for emacs-orgmode@gnu.org; Thu, 10 Jan 2013 00:10:41 -0500 Received: by mail-ia0-f172.google.com with SMTP id u8so148572iag.17 for ; Wed, 09 Jan 2013 21:10:41 -0800 (PST) In-Reply-To: <50ee34c8.09fb640a.6b64.0e5a@mx.google.com> (Darlan Cavalcante Moreira's message of "Thu, 10 Jan 2013 00:25:56 -0300") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Darlan Cavalcante Moreira Cc: emacs-orgmode --=-=-= Content-Type: text/plain Darlan Cavalcante Moreira writes: > Is there a way to detect when a file changes and then add the content from > it (if any, the file could be empty) to a specified org-mode table? Each > line in that file is already constructed in a way that it could be copied > and pasted to the table directly (but I can change that if it makes things > easier). > Interesting question. Here is a partial answer. If you can write a code block which reads the external file, and then outputs the desired table, then the attached Org-mode file should work for you. The following defines a function (`continually-run') which re-runs a named code block every couple of seconds. Code blocks already handle the updating of their results every time they are run. See the file itself for more information. After testing this I will warn that it caused some weirdness with my cursor in the mini-buffer. Hope this helps, --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=code-block-rerunner.org #+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 --=-=-= Content-Type: text/plain -- Eric Schulte http://cs.unm.edu/~eschulte --=-=-=--