Fork me on GitHub

how to eval an elisp expression in the context of a specific buffer? pseudo code (eval-in-buffer (nth 0 (buffer-list)) '(do-this-and-that))


Usually “with-current-buffer”


thanks. It turns out that I need frame, not buffer and found select-frame

Jakub Šťastný13:06:39

Hey guys. Question about reusability of SQL code when doing literate programming in Orgmode (please see the screenshot below this message) # Requirements In my code I want to separate SQL queries from my app code, I don't want them to be just bunch of strings inside my CJ code. I want them to live in separate blocks, where I can: 1. Run them using C-c C-c, #+CALL:, or "=inline=". When running via call or inline, I want to be able to override the default email argument. (All of this works already, I'm mentioning it, because I don't want it to be lost "on the way".) 1. I want to see SQL syntax highlighted, which I get for free with the code block, but it wouldn't be the case would I be using strings in CJ. 2. Now the issue is how do I include it into my CJ app code? # The issue Babel has two was of referring code blocks: either by <<my-named-block>>, or by <<my-named-block(args)>>. The former simply copies and pastes contents of the block (which we need for tangling) and the latter actually calls the block. Calling the block is not what we want. We need to copy and paste the contents, BUT we need to replace the $email babel variable. And here is what I struggle with – how would I do that? The preferred solution would be with babel itself: this is no concern of the application. I tried to write a named helper function in babel and calling it like <<replace-variables(x: <<get-user-query>>), but babel doesn't seem to be supporting nested calls. The fn replace-variables was meant to simply take the SQL with $email in it and convert it to a valid CJ string with evaluation, something like (str "SELECT ..." email), which would then correctly take email from the request (CJ variable as opposed to babel variable). Does anyone know whether/how could this be done in babel itself? If not, I'd probably have to go for plan B, which would be replacing "$email" (string) by email (variable) in CJ.


Hm, I managed the get the following working, as in "ugly but works... sort of?".

#+name: email
#+begin_src text
  "[email protected]"

#+name: my-sql-query
#+begin_src sqlite :db test.db :noweb yes
  SELECT * FROM users WHERE (email = <<email>>)

#+begin_src shell :noweb yes
  print_query() {
      local query="<<my-sql-query>>"
      echo "$query"


: SELECT * FROM users WHERE (email = [email protected])

Jakub Šťastný15:07:51

Thanks @U051MHSEK, I'll take a look at it later in the day.