emacs

Consider also joining #cider, #lsp and #inf-clojure, where most of the tool-specific discussions are happening.
2021-06-26T04:16:25.069900Z

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

dpsutton 2021-06-26T04:47:16.070500Z

Usually “with-current-buffer”

2021-06-26T05:13:16.071100Z

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

2021-06-26T13:53:39.080700Z

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.

adityaathalye 2021-06-29T17:31:02.104300Z

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

#+name: email
#+begin_src text
  "foo@bar.baz"
#+end_src

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

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

  print_query
#+end_src

#+RESULTS:
: SELECT * FROM users WHERE (email = foo@bar.baz)

2021-07-02T15:27:51.116900Z

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