dakrone / es-mode

An Emacs major mode for interacting with Elasticsearch
GNU General Public License v3.0
196 stars 34 forks source link

Delay evaluation of defaults for org-babel #71

Closed bgutter closed 5 years ago

bgutter commented 5 years ago

Hey @dakrone

This package has been awesome for tinkering with Elasticsearch in emacs. Many thanks!

I ran into something that I think might be a bug in the org-babel block handling. It looks like changing the values of the variables for default URL and default method does not take effect as one might expect.

Unlike (I assume) in proper es-mode buffers, org-babel blocks will continue to use the value of "es-default-url" and "...-method" which were set at package load time. This is because they are cached into the org-babel-default-header-args:es variable in defvar.

For example:

 #+NAME: a
 #+BEGIN_SRC es
 GET /_search?pretty
 { ... }
 #+END_SRC

 #+NAME: b
 #+BEGIN_SRC emacs-lisp
 (setq es-default-url "not-localhost:1234")
 #+BEGIN_SRC

 #+NAME: c
 #+BEGIN_SRC es
 GET /_search?pretty
 { ... }
 #+END_SRC

Assume these blocks are eval'd in order.

Without this change, blocks "a" and "c" will always request from "localhost:9000", or whatever was the custom value of "es-default-url" via customize-variable when the package was loaded.

With this change, block "c" will instead begin to use the new default url.

What do you think?

dakrone commented 5 years ago

This change makes sense to me, thanks @bgutter!