emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using babel to generate a commit log
@ 2011-03-30  5:38 Luke Crook
  2011-03-30  6:26 ` Jambunathan K
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Luke Crook @ 2011-03-30  5:38 UTC (permalink / raw)
  To: emacs-orgmode


I have written the following code that uses the Emacs vc-* commands to generate 
a commit log. I would like the output of this code to be included when my file 
is exported.

#+begin_src emacs-lisp :var limit=""
;; Most of this code is copied from vc.el vc-print-log
(when (vc-find-backend-function (vc-backend (buffer-file-name (current-buffer)))
  				                'print-log)
      (let* ((limit (if (numberp limit) limit vc-log-show-limit))
	         (vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
	         (backend (car vc-fileset))
	         (files (cadr vc-fileset)))
	  (with-temp-buffer 
          (vc-call-backend backend
	      		       'print-log
	      		       files
	      		       (current-buffer))
          (sit-for 5 t)          
          (buffer-string))))
#+end_src

What is happening is; 

  1) The code between #+begin_src and #+end_src is exported and not the result 
of evaluating the code (the commit log).
  2) I have to add at delay of at least 5 seconds (set-for 5 t) as vc-git calls 
"git log" as an asynchronous process. If not for the delay then babel 
immediately returns an empty buffer and the "vc-call-backend" process never 
completes.

How can I fix (1).

Is there a better way that I can accomplish (2) ?

Thanks,
-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30  5:38 Using babel to generate a commit log Luke Crook
@ 2011-03-30  6:26 ` Jambunathan K
  2011-03-30  7:57   ` Luke Crook
  2011-03-30  6:28 ` Suvayu Ali
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 23+ messages in thread
From: Jambunathan K @ 2011-03-30  6:26 UTC (permalink / raw)
  To: Luke Crook; +Cc: emacs-orgmode

Luke Crook <luke@balooga.com> writes:

> I have written the following code that uses the Emacs vc-* commands to generate 
> a commit log. I would like the output of this code to be included when my file 
> is exported.
>
> #+begin_src emacs-lisp :var limit=""
> ;; Most of this code is copied from vc.el vc-print-log
> (when (vc-find-backend-function (vc-backend (buffer-file-name (current-buffer)))
>   				                'print-log)
>       (let* ((limit (if (numberp limit) limit vc-log-show-limit))
> 	         (vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
> 	         (backend (car vc-fileset))
> 	         (files (cadr vc-fileset)))
> 	  (with-temp-buffer 
>           (vc-call-backend backend
> 	      		       'print-log
> 	      		       files
> 	      		       (current-buffer))
>           (sit-for 5 t)          
>           (buffer-string))))
> #+end_src
>
> What is happening is; 
>
>   1) The code between #+begin_src and #+end_src is exported and not the result 
> of evaluating the code (the commit log).
>   2) I have to add at delay of at least 5 seconds (set-for 5 t) as vc-git calls 
> "git log" as an asynchronous process. If not for the delay then babel 
> immediately returns an empty buffer and the "vc-call-backend" process never 
> completes.
>
> How can I fix (1).
>
> Is there a better way that I can accomplish (2) ?

Quick hints if you are willing to settle for some hacks.

In vc-do-command, you may have to set OKSTATUS to 0. Track
`vc-disable-async-diff' in vc.el and vc-svn.el for possible hints.

,----[ C-h f vc-do-command RET ]
| vc-do-command is an autoloaded Lisp function in `vc-dispatcher.el'.
| 
| (vc-do-command BUFFER OKSTATUS COMMAND FILE-OR-LIST &rest FLAGS)
| 
| Execute a slave command, notifying user and checking for errors.
| Output from COMMAND goes to BUFFER, or the current buffer if
| BUFFER is t.  If the destination buffer is not already current,
| set it up properly and erase it.  The command is considered
| successful if its exit status does not exceed OKSTATUS (if
| OKSTATUS is nil, that means to ignore error status, if it is
| `async', that means not to wait for termination of the
| subprocess; if it is t it means to ignore all execution errors).
| FILE-OR-LIST is the name of a working file; it may be a list of
| files or be nil (to execute commands that don't expect a file
| name or set of files).  If an optional list of FLAGS is present,
| that is inserted into the command line before the filename.
| Return the return value of the slave command in the synchronous
| case, and the process object in the asynchronous case.
| 
| [back]
`----


,----[ C-h v vc-disable-async-diff RET ]
| vc-disable-async-diff is a variable defined in `vc.el'.
| Its value is nil
| 
| Documentation:
| VC sets this to t locally to disable some async diff operations.
| Backends that offer asynchronous diffs should respect this variable
| in their implementation of vc-BACKEND-diff.
| 
| [back]
`----


>
> Thanks,
> -Luke
>
>
>
>

-- 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30  5:38 Using babel to generate a commit log Luke Crook
  2011-03-30  6:26 ` Jambunathan K
@ 2011-03-30  6:28 ` Suvayu Ali
  2011-03-30  7:52   ` Luke Crook
  2011-03-30  6:29 ` Nick Dokos
  2011-03-30 20:12 ` Eric Schulte
  3 siblings, 1 reply; 23+ messages in thread
From: Suvayu Ali @ 2011-03-30  6:28 UTC (permalink / raw)
  To: emacs-orgmode

On Wed, 30 Mar 2011 05:38:41 +0000 (UTC)
Luke Crook <luke@balooga.com> wrote:

>   1) The code between #+begin_src and #+end_src is exported and not
> the result of evaluating the code (the commit log).

[...]

> 
> How can I fix (1).
> 

Have you tried ':exports results' as a header argument?

> 
> Thanks,
> -Luke

-- 
Suvayu

Open source is the future. It sets us free.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30  5:38 Using babel to generate a commit log Luke Crook
  2011-03-30  6:26 ` Jambunathan K
  2011-03-30  6:28 ` Suvayu Ali
@ 2011-03-30  6:29 ` Nick Dokos
  2011-03-30 20:12 ` Eric Schulte
  3 siblings, 0 replies; 23+ messages in thread
From: Nick Dokos @ 2011-03-30  6:29 UTC (permalink / raw)
  To: Luke Crook; +Cc: nicholas.dokos, emacs-orgmode

Luke Crook <luke@balooga.com> wrote:

> 
> I have written the following code that uses the Emacs vc-* commands to generate 
> a commit log. I would like the output of this code to be included when my file 
> is exported.
> 
> 
> ;; Most of this code is copied from vc.el vc-print-log
> (when (vc-find-backend-function (vc-backend (buffer-file-name (current-buffer)))
>   				                'print-log)
>       (let* ((limit (if (numberp limit) limit vc-log-show-limit))
> 	         (vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
> 	         (backend (car vc-fileset))
> 	         (files (cadr vc-fileset)))
> 	  (with-temp-buffer 
>           (vc-call-backend backend
> 	      		       'print-log
> 	      		       files
> 	      		       (current-buffer))
>           (sit-for 5 t)          
>           (buffer-string))))
> #+end_src
> 
> What is happening is; 
> 
>   1) The code between #+begin_src and #+end_src is exported and not the result 
> of evaluating the code (the commit log).

Try using

--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp :var limit="" :exports results
--8<---------------cut here---------------end--------------->8---

>   2) I have to add at delay of at least 5 seconds (set-for 5 t) as vc-git calls 
> "git log" as an asynchronous process. If not for the delay then babel 
> immediately returns an empty buffer and the "vc-call-backend" process never 
> completes.
> 

A quick look didn't produce much enlightenment: the standard way is to set
a process sentinel, but this is commented out in vc-do-command. There is also
a hook that is run at the end of the function:

,----
| 	(vc-exec-after
| 	 `(run-hook-with-args 'vc-post-command-functions
| 			      ',command ',file-or-list ',flags))
`----

but I think you need the process in order to set a sentinel (see sec. 37.10 of
the Elisp manual for info on sentinels).

Nick

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30  6:28 ` Suvayu Ali
@ 2011-03-30  7:52   ` Luke Crook
  2011-03-30 13:07     ` Nick Dokos
  0 siblings, 1 reply; 23+ messages in thread
From: Luke Crook @ 2011-03-30  7:52 UTC (permalink / raw)
  To: emacs-orgmode

Suvayu Ali <fatkasuvayu+linux <at> gmail.com> writes:

> 
> On Wed, 30 Mar 2011 05:38:41 +0000 (UTC)
> Luke Crook <luke <at> balooga.com> wrote:
> 
> >   1) The code between #+begin_src and #+end_src is exported and not
> > the result of evaluating the code (the commit log).
> 
> [...]
> 
> > 
> > How can I fix (1).
> > 
> 
> Have you tried ':exports results' as a header argument?
> 

I just tried ':exports results'. But now I get the following error when 
exporting the file, "Cannot open load file: vc-nil"

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30  6:26 ` Jambunathan K
@ 2011-03-30  7:57   ` Luke Crook
  2011-03-30 13:43     ` Nick Dokos
  0 siblings, 1 reply; 23+ messages in thread
From: Luke Crook @ 2011-03-30  7:57 UTC (permalink / raw)
  To: emacs-orgmode

Jambunathan K <kjambunathan <at> gmail.com> writes:

> 
> Luke Crook <luke <at> balooga.com> writes:
> 
> >   2) I have to add at delay of at least 5 seconds (set-for 5 t) as vc-git 
calls 
> > "git log" as an asynchronous process. If not for the delay then babel 
> > immediately returns an empty buffer and the "vc-call-backend" process never 
> > completes.
> >
> > Is there a better way that I can accomplish (2) ?
> 
> Quick hints if you are willing to settle for some hacks.
> 
> In vc-do-command, you may have to set OKSTATUS to 0. Track
> `vc-disable-async-diff' in vc.el and vc-svn.el for possible hints.
> 

I changed my code to wait until the 'Git' process completes. Luckily "vc-call-
backend" returns the async process.

#+begin_src emacs-lisp :var limit="" :file test.log :exports results
;; Most of this code is copied from vc.el vc-print-log
(when (vc-find-backend-function (vc-backend (buffer-file-name (current-buffer)))
  				                'print-log)
      (let* ((limit (if (numberp limit) limit vc-log-show-limit))
	         (vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
	         (backend (car vc-fileset))
	         (files (cadr vc-fileset)))
	  (with-temp-buffer 
          (let ((status (vc-call-backend backend
	      		                     'print-log
	      		                     files
	      		                     (current-buffer))))
          (while (not (eq 'exit (process-status status)))
              (sit-for 1 t))
          (buffer-string)))))
#+end_src


-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-30  7:52   ` Luke Crook
@ 2011-03-30 13:07     ` Nick Dokos
  2011-03-30 15:34       ` Luke Crook
  0 siblings, 1 reply; 23+ messages in thread
From: Nick Dokos @ 2011-03-30 13:07 UTC (permalink / raw)
  To: Luke Crook; +Cc: nicholas.dokos, emacs-orgmode

Luke Crook <luke@balooga.com> wrote:

> Suvayu Ali <fatkasuvayu+linux <at> gmail.com> writes:
> 
> > 
> > On Wed, 30 Mar 2011 05:38:41 +0000 (UTC)
> > Luke Crook <luke <at> balooga.com> wrote:
> > 
> > >   1) The code between #+begin_src and #+end_src is exported and not
> > > the result of evaluating the code (the commit log).
> > 
> > [...]
> > 
> > > 
> > > How can I fix (1).
> > > 
> > 
> > Have you tried ':exports results' as a header argument?
> > 
> 
> I just tried ':exports results'. But now I get the following error when 
> exporting the file, "Cannot open load file: vc-nil"
> 

That sounds like vc does not know what backend to use: maybe you are not
in a git-controlled directory?

Nick

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-30  7:57   ` Luke Crook
@ 2011-03-30 13:43     ` Nick Dokos
  2011-03-30 18:08       ` Luke Crook
  0 siblings, 1 reply; 23+ messages in thread
From: Nick Dokos @ 2011-03-30 13:43 UTC (permalink / raw)
  To: Luke Crook; +Cc: nicholas.dokos, emacs-orgmode

Luke Crook <luke@balooga.com> wrote:

> Jambunathan K <kjambunathan <at> gmail.com> writes:
> 
> > 
> > Luke Crook <luke <at> balooga.com> writes:
> > 
> > >   2) I have to add at delay of at least 5 seconds (set-for 5 t) as vc-git 
> calls 
> > > "git log" as an asynchronous process. If not for the delay then babel 
> > > immediately returns an empty buffer and the "vc-call-backend" process never 
> > > completes.
> > >
> > > Is there a better way that I can accomplish (2) ?
> > 
> > Quick hints if you are willing to settle for some hacks.
> > 
> > In vc-do-command, you may have to set OKSTATUS to 0. Track
> > `vc-disable-async-diff' in vc.el and vc-svn.el for possible hints.
> > 
> 
> I changed my code to wait until the 'Git' process completes. Luckily "vc-call-
> backend" returns the async process.
> 
Oh, I missed that - thanks for pointing it out.

> #+begin_src emacs-lisp :var limit="" :file test.log :exports results
> ;; Most of this code is copied from vc.el vc-print-log
> (when (vc-find-backend-function (vc-backend (buffer-file-name (current-buffer)))
>   				                'print-log)
>       (let* ((limit (if (numberp limit) limit vc-log-show-limit))
> 	         (vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
> 	         (backend (car vc-fileset))
> 	         (files (cadr vc-fileset)))
> 	  (with-temp-buffer 
>           (let ((status (vc-call-backend backend
> 	      		                     'print-log
> 	      		                     files
> 	      		                     (current-buffer))))
>           (while (not (eq 'exit (process-status status)))
>               (sit-for 1 t))
>           (buffer-string)))))
> #+end_src
> 

... or you could use a sentinel :-)

One bit of defensive programming might be to check that status *is* a
process before you do the wait: vc-do-command returns a real status in
the synchronous case, so if you cut-n-paste this code with some other
command that does not use async, it'll blow up.

Nick

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 13:07     ` Nick Dokos
@ 2011-03-30 15:34       ` Luke Crook
  2011-03-30 16:51         ` Nick Dokos
  0 siblings, 1 reply; 23+ messages in thread
From: Luke Crook @ 2011-03-30 15:34 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos <at> hp.com> writes:

> 
> Luke Crook <luke <at> balooga.com> wrote:
> 
> > Suvayu Ali <fatkasuvayu+linux <at> gmail.com> writes:
> > 
> > > Have you tried ':exports results' as a header argument?
> > > 
> > 
> > I just tried ':exports results'. But now I get the following error when 
> > exporting the file, "Cannot open load file: vc-nil"
> > 
> 
> That sounds like vc does not know what backend to use: maybe you are not
> in a git-controlled directory?
> 

'C-c C-c' at the top of the source block does generate the correct output 
though. It is just 'C-c C-e <export backend>' that returns this error.

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-30 15:34       ` Luke Crook
@ 2011-03-30 16:51         ` Nick Dokos
  2011-03-30 17:47           ` Luke Crook
  0 siblings, 1 reply; 23+ messages in thread
From: Nick Dokos @ 2011-03-30 16:51 UTC (permalink / raw)
  To: Luke Crook; +Cc: nicholas.dokos, emacs-orgmode

Luke Crook <luke@balooga.com> wrote:

> Nick Dokos <nicholas.dokos <at> hp.com> writes:
> 
> > 
> > Luke Crook <luke <at> balooga.com> wrote:
> > 
> > > Suvayu Ali <fatkasuvayu+linux <at> gmail.com> writes:
> > > 
> > > > Have you tried ':exports results' as a header argument?
> > > > 
> > > 
> > > I just tried ':exports results'. But now I get the following error when 
> > > exporting the file, "Cannot open load file: vc-nil"
> > > 
> > 
> > That sounds like vc does not know what backend to use: maybe you are not
> > in a git-controlled directory?
> > 
> 
> 'C-c C-c' at the top of the source block does generate the correct output 
> though. It is just 'C-c C-e <export backend>' that returns this error.
> 

Right: (current-buffer) is not what you think it is when exporting - it is
the temp buffer that the export mechanism sets up.

There is a way to get the original buffer during capture, but I don't
know of a similar mechanism during export. I hardwired the file name
instead, but I got no further than the vc-fileset call: there seem to be
all sorts of contextual assumptions that vc makes that are violated in
the export context.

Nick

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 16:51         ` Nick Dokos
@ 2011-03-30 17:47           ` Luke Crook
  2011-03-30 18:41             ` Luke Crook
  2011-03-30 20:10             ` Eric Schulte
  0 siblings, 2 replies; 23+ messages in thread
From: Luke Crook @ 2011-03-30 17:47 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos <at> hp.com> writes:

> 
> Luke Crook <luke <at> balooga.com> wrote:
> 
> > 'C-c C-c' at the top of the source block does generate the correct output 
> > though. It is just 'C-c C-e <export backend>' that returns this error.
> > 
> 
> Right: (current-buffer) is not what you think it is when exporting - it is
> the temp buffer that the export mechanism sets up.
> 
> There is a way to get the original buffer during capture, but I don't
> know of a similar mechanism during export. I hardwired the file name
> instead, but I got no further than the vc-fileset call: there seem to be
> all sorts of contextual assumptions that vc makes that are violated in
> the export context.

Yes, this makes sense thanks. I'll create another thread asking how to retrieve 
the original buffer during the export process.

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 13:43     ` Nick Dokos
@ 2011-03-30 18:08       ` Luke Crook
  2011-03-30 18:42         ` Nick Dokos
  0 siblings, 1 reply; 23+ messages in thread
From: Luke Crook @ 2011-03-30 18:08 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos <at> hp.com> writes:

> 
> Luke Crook <luke <at> balooga.com> wrote:
> 
> > Jambunathan K <kjambunathan <at> gmail.com> writes:
> > 
> > > 
> > 
> > I changed my code to wait until the 'Git' process completes. Luckily "vc-
call-
> > backend" returns the async process.
> > 
> 
> ... or you could use a sentinel 
> 
> One bit of defensive programming might be to check that status *is* a
> process before you do the wait: vc-do-command returns a real status in
> the synchronous case, so if you cut-n-paste this code with some other
> command that does not use async, it'll blow up.
> 

I have modified the code to only check the status if the process is actually 
running;

	  (with-temp-buffer 
          (let ((status (vc-call-backend backend
	      		                     'print-log
	      		                     files
	      		                     (current-buffer))))
          (when (= 0 (process-exit-status status))
              (while (not (eq 'exit (process-status status)))
                 (sit-for 1 t)))

I'm not sure about using a sentinel though as this is just a callback that is 
executed when the process completes. Wouldn't the sentinel fire after the source 
block has returned?

Or do you mean to wait until a variable set by the sentinel returns t?

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 17:47           ` Luke Crook
@ 2011-03-30 18:41             ` Luke Crook
  2011-03-30 20:10             ` Eric Schulte
  1 sibling, 0 replies; 23+ messages in thread
From: Luke Crook @ 2011-03-30 18:41 UTC (permalink / raw)
  To: emacs-orgmode

Luke Crook <luke <at> balooga.com> writes:

> 
> Nick Dokos <nicholas.dokos <at> hp.com> writes:
> 
> > There is a way to get the original buffer during capture, but I don't
> > know of a similar mechanism during export. I hardwired the file name
> > instead, but I got no further than the vc-fileset call: there seem to be
> > all sorts of contextual assumptions that vc makes that are violated in
> > the export context.
> 
 
org-publish-initial-buffer provides this when publishing, but I can't find an 
equivalent for a standard export.

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-30 18:08       ` Luke Crook
@ 2011-03-30 18:42         ` Nick Dokos
  0 siblings, 0 replies; 23+ messages in thread
From: Nick Dokos @ 2011-03-30 18:42 UTC (permalink / raw)
  To: Luke Crook; +Cc: nicholas.dokos, emacs-orgmode

Luke Crook <luke@balooga.com> wrote:

> Nick Dokos <nicholas.dokos <at> hp.com> writes:
> 
> > 
> > Luke Crook <luke <at> balooga.com> wrote:
> > 
> > > Jambunathan K <kjambunathan <at> gmail.com> writes:
> > > 
> > > > 
> > > 
> > > I changed my code to wait until the 'Git' process completes. Luckily "vc-
> call-
> > > backend" returns the async process.
> > > 
> > 
> > ... or you could use a sentinel 
> > 
> > One bit of defensive programming might be to check that status *is* a
> > process before you do the wait: vc-do-command returns a real status in
> > the synchronous case, so if you cut-n-paste this code with some other
> > command that does not use async, it'll blow up.
> > 
> 
> I have modified the code to only check the status if the process is actually 
> running;
> 
> 	  (with-temp-buffer 
>           (let ((status (vc-call-backend backend
> 	      		                     'print-log
> 	      		                     files
> 	      		                     (current-buffer))))
>           (when (= 0 (process-exit-status status))
>               (while (not (eq 'exit (process-status status)))
>                  (sit-for 1 t)))
> 

I meant something like this:

  (if (processp status)
     ...do the process stuff)
  
It's not a problem here since vc-call-backend will always call print-log
asynchronously, so status will always be a process, but if you use this
code somewhere else with a different command that is *not* done
asynchronously, then you'll have a problem. Not a biggie.

> I'm not sure about using a sentinel though as this is just a callback that is 
> executed when the process completes. Wouldn't the sentinel fire after the source 
> block has returned?
> 
> Or do you mean to wait until a variable set by the sentinel returns t?
> 

Something like the latter: just something to avoid the busy-wait loop,
but again it's a minor nit - the loop works just fine.

Nick

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-30 17:47           ` Luke Crook
  2011-03-30 18:41             ` Luke Crook
@ 2011-03-30 20:10             ` Eric Schulte
  2011-03-30 20:22               ` Nick Dokos
  2011-03-30 22:02               ` Luke Crook
  1 sibling, 2 replies; 23+ messages in thread
From: Eric Schulte @ 2011-03-30 20:10 UTC (permalink / raw)
  To: Luke Crook; +Cc: emacs-orgmode

Luke Crook <luke@balooga.com> writes:

> Nick Dokos <nicholas.dokos <at> hp.com> writes:
>
>> 
>> Luke Crook <luke <at> balooga.com> wrote:
>> 
>> > 'C-c C-c' at the top of the source block does generate the correct output 
>> > though. It is just 'C-c C-e <export backend>' that returns this error.
>> > 
>> 
>> Right: (current-buffer) is not what you think it is when exporting - it is
>> the temp buffer that the export mechanism sets up.
>> 
>> There is a way to get the original buffer during capture, but I don't
>> know of a similar mechanism during export. I hardwired the file name
>> instead, but I got no further than the vc-fileset call: there seem to be
>> all sorts of contextual assumptions that vc makes that are violated in
>> the export context.
>
> Yes, this makes sense thanks. I'll create another thread asking how to retrieve 
> the original buffer during the export process.
>

It is true that export takes place in a fresh Org-mode buffer, however
the header arguments of Org-mode code blocks are guaranteed to be
evaluated in the original buffer, so a trick like the following can be
used to grab the original buffer.

#+begin_src emacs-lisp :var buf=(buffer-file-name (current-buffer)) :exports both
  (message "buffer %S!" buf)
#+end_src

This issue should be given more prominence in the Org-mode manual, as it
is a common source of confusion.

Cheers -- Eric

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30  5:38 Using babel to generate a commit log Luke Crook
                   ` (2 preceding siblings ...)
  2011-03-30  6:29 ` Nick Dokos
@ 2011-03-30 20:12 ` Eric Schulte
  2011-03-30 21:58   ` Luke Crook
  3 siblings, 1 reply; 23+ messages in thread
From: Eric Schulte @ 2011-03-30 20:12 UTC (permalink / raw)
  To: Luke Crook; +Cc: emacs-orgmode

Luke Crook <luke@balooga.com> writes:

> I have written the following code that uses the Emacs vc-* commands to generate 
> a commit log. I would like the output of this code to be included when my file 
> is exported.
>

Is there a reason this processing takes place using Emacs Lisp rather
than a simple shell code block, the following alternative should be
simpler and more robust.

#+begin_src sh :exports results :results output
  git log -1
#+end_src

Best -- Eric

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-30 20:10             ` Eric Schulte
@ 2011-03-30 20:22               ` Nick Dokos
  2011-03-30 22:02               ` Luke Crook
  1 sibling, 0 replies; 23+ messages in thread
From: Nick Dokos @ 2011-03-30 20:22 UTC (permalink / raw)
  To: Eric Schulte; +Cc: nicholas.dokos, emacs-orgmode, Luke Crook

Eric Schulte <schulte.eric@gmail.com> wrote:

> > Yes, this makes sense thanks. I'll create another thread asking how to retrieve 
> > the original buffer during the export process.
> >
> 
> It is true that export takes place in a fresh Org-mode buffer, however
> the header arguments of Org-mode code blocks are guaranteed to be
> evaluated in the original buffer, so a trick like the following can be
> used to grab the original buffer.
> 
> #+begin_src emacs-lisp :var buf=(buffer-file-name (current-buffer)) :exports both
>   (message "buffer %S!" buf)
> #+end_src
> 

... and there was general rejoicing.

Thanks!
Nick

> This issue should be given more prominence in the Org-mode manual, as it
> is a common source of confusion.
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 20:12 ` Eric Schulte
@ 2011-03-30 21:58   ` Luke Crook
  0 siblings, 0 replies; 23+ messages in thread
From: Luke Crook @ 2011-03-30 21:58 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte <schulte.eric <at> gmail.com> writes:

> 
> Luke Crook <luke <at> balooga.com> writes:
> 
> > I have written the following code that uses the Emacs vc-* commands to 
generate 
> > a commit log. 

> Is there a reason this processing takes place using Emacs Lisp rather
> than a simple shell code block, the following alternative should be
> simpler and more robust.
> 
> #+begin_src sh :exports results :results output
>   git log -1
> #+end_src

I wanted to abstract away the actual vcs used so that this code could be used by 
others having a different vcs. 

In my case I only want the commits for the file being exported and not the 
previous 'n' commits. I have all my specs in the same git repo.

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 20:10             ` Eric Schulte
  2011-03-30 20:22               ` Nick Dokos
@ 2011-03-30 22:02               ` Luke Crook
  2011-03-30 23:20                 ` Luke Crook
  1 sibling, 1 reply; 23+ messages in thread
From: Luke Crook @ 2011-03-30 22:02 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte <schulte.eric <at> gmail.com> writes:

>  
> It is true that export takes place in a fresh Org-mode buffer, however
> the header arguments of Org-mode code blocks are guaranteed to be
> evaluated in the original buffer, so a trick like the following can be
> used to grab the original buffer.
> 
> #+begin_src emacs-lisp :var buf=(buffer-file-name (current-buffer)) :exports 
both
>   (message "buffer %S!" buf)
> #+end_src
> 

That is exactly what I need. Thank you very much.

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 22:02               ` Luke Crook
@ 2011-03-30 23:20                 ` Luke Crook
  2011-03-30 23:44                   ` Eric Schulte
  0 siblings, 1 reply; 23+ messages in thread
From: Luke Crook @ 2011-03-30 23:20 UTC (permalink / raw)
  To: emacs-orgmode

Luke Crook <luke <at> balooga.com> writes:

> 
> Eric Schulte <schulte.eric <at> gmail.com> writes:
> 
> > #+begin_src emacs-lisp :var buf=(buffer-file-name (current-buffer)) :exports 
> both
> >   (message "buffer %S!" buf)
> > #+end_src
> > 

The following code will now generate the commit log. 

#+begin_src emacs-lisp :var limit=-1 :var buf=(buffer-name (current-buffer)) 
:exports results
;; Most of this code is copied from vc.el vc-print-log
(when (vc-find-backend-function (vc-backend (buffer-file-name (get-buffer buf)))
				    'print-log)
  (let ((limit -1)
	    (vc-fileset nil)
	    (backend nil)
	    (files nil))
    (with-current-buffer (get-buffer buf)
	  (setq vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
      (setq backend (car vc-fileset))
      (setq files (cadr vc-fileset)))
    (with-temp-buffer 
      (let ((status (vc-call-backend backend
				         'print-log
				         files
				         (current-buffer))))
	(when (and (processp status) ;; Make sure status is a process
		   (= 0 (process-exit-status status))) ;; And that it has not 
terminated
	  (while (not (eq 'exit (process-status status))) ;; Loop and sleep 
until complete
	    (sit-for 1 t)))
	(buffer-string)))))
#+end_src

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-30 23:20                 ` Luke Crook
@ 2011-03-30 23:44                   ` Eric Schulte
  2011-03-31  6:49                     ` Luke Crook
  0 siblings, 1 reply; 23+ messages in thread
From: Eric Schulte @ 2011-03-30 23:44 UTC (permalink / raw)
  To: Luke Crook; +Cc: emacs-orgmode

Luke Crook <luke@balooga.com> writes:

> Luke Crook <luke <at> balooga.com> writes:
>
>> 
>> Eric Schulte <schulte.eric <at> gmail.com> writes:
>> 
>> > #+begin_src emacs-lisp :var buf=(buffer-file-name (current-buffer)) :exports 
>> both
>> >   (message "buffer %S!" buf)
>> > #+end_src
>> > 
>
> The following code will now generate the commit log. 
>
> #+begin_src emacs-lisp :var limit=-1 :var buf=(buffer-name (current-buffer)) 
> :exports results
> ;; Most of this code is copied from vc.el vc-print-log
> (when (vc-find-backend-function (vc-backend (buffer-file-name (get-buffer buf)))
> 				    'print-log)
>   (let ((limit -1)
> 	    (vc-fileset nil)
> 	    (backend nil)
> 	    (files nil))
>     (with-current-buffer (get-buffer buf)
> 	  (setq vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
>       (setq backend (car vc-fileset))
>       (setq files (cadr vc-fileset)))
>     (with-temp-buffer 
>       (let ((status (vc-call-backend backend
> 				         'print-log
> 				         files
> 				         (current-buffer))))
> 	(when (and (processp status) ;; Make sure status is a process
> 		   (= 0 (process-exit-status status))) ;; And that it has not 
> terminated
> 	  (while (not (eq 'exit (process-status status))) ;; Loop and sleep 
> until complete
> 	    (sit-for 1 t)))
> 	(buffer-string)))))
> #+end_src

Great,

Since this could be generally useful would you be willing to add it to
the library of babel (org/contrib/babel/library-of-babel.org)?  If so
then if you could supply a few explanatory sentences, I'll add those and
the code block to the library-of-babel.org distributed with Org-mode.

Thanks -- Eric

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Using babel to generate a commit log
  2011-03-30 23:44                   ` Eric Schulte
@ 2011-03-31  6:49                     ` Luke Crook
  2011-04-01  0:28                       ` Eric Schulte
  0 siblings, 1 reply; 23+ messages in thread
From: Luke Crook @ 2011-03-31  6:49 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte <schulte.eric <at> gmail.com> writes:
>
> Since this could be generally useful would you be willing to add it to
> the library of babel (org/contrib/babel/library-of-babel.org)?  

That would be great.

> If so then if you could supply a few explanatory sentences, I'll add those and
> the code block to the library-of-babel.org distributed with Org-mode.

"This function will attempt to retrieve the entire commit log for the file 
associated with the current buffer and insert this log into the export. The 
function uses the Emacs VC commands to interface to the local version control 
system, but has only been tested to work with Git. 'limit' is currently 
unsupported."

-Luke

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Re: Using babel to generate a commit log
  2011-03-31  6:49                     ` Luke Crook
@ 2011-04-01  0:28                       ` Eric Schulte
  0 siblings, 0 replies; 23+ messages in thread
From: Eric Schulte @ 2011-04-01  0:28 UTC (permalink / raw)
  To: Luke Crook; +Cc: emacs-orgmode

Luke Crook <luke@balooga.com> writes:

> Eric Schulte <schulte.eric <at> gmail.com> writes:
>>
>> Since this could be generally useful would you be willing to add it to
>> the library of babel (org/contrib/babel/library-of-babel.org)?  
>
> That would be great.
>
>> If so then if you could supply a few explanatory sentences, I'll add those and
>> the code block to the library-of-babel.org distributed with Org-mode.
>
> "This function will attempt to retrieve the entire commit log for the file 
> associated with the current buffer and insert this log into the export. The 
> function uses the Emacs VC commands to interface to the local version control 
> system, but has only been tested to work with Git. 'limit' is currently 
> unsupported."
>

Fantastic, I've now added this to the library-of-babel.org file, so
anyone who loads the library of babel can now call this functionality
through the "" code block, e.g.,

#+call: 

Thanks for the contribution! -- Eric

ps. since I can be a bit OCD about these things, I made some aesthetic
indentation and reformatting changes to your elisp.

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2011-04-01  0:34 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-30  5:38 Using babel to generate a commit log Luke Crook
2011-03-30  6:26 ` Jambunathan K
2011-03-30  7:57   ` Luke Crook
2011-03-30 13:43     ` Nick Dokos
2011-03-30 18:08       ` Luke Crook
2011-03-30 18:42         ` Nick Dokos
2011-03-30  6:28 ` Suvayu Ali
2011-03-30  7:52   ` Luke Crook
2011-03-30 13:07     ` Nick Dokos
2011-03-30 15:34       ` Luke Crook
2011-03-30 16:51         ` Nick Dokos
2011-03-30 17:47           ` Luke Crook
2011-03-30 18:41             ` Luke Crook
2011-03-30 20:10             ` Eric Schulte
2011-03-30 20:22               ` Nick Dokos
2011-03-30 22:02               ` Luke Crook
2011-03-30 23:20                 ` Luke Crook
2011-03-30 23:44                   ` Eric Schulte
2011-03-31  6:49                     ` Luke Crook
2011-04-01  0:28                       ` Eric Schulte
2011-03-30  6:29 ` Nick Dokos
2011-03-30 20:12 ` Eric Schulte
2011-03-30 21:58   ` Luke Crook

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).