jq-mode
jq-mode copied to clipboard
Option to push the values entered in the jq-interactive minibuffer into the kill-ring?
Great package, thanks!
I was searching for a way to get at the value of the jq expression I last typed in...
I ended up binding a key in json-mode to do this
(kill-new (car minibuffer-history))
and that more or less does what I want, but I have to press that key after finishing jq-interactively. Perhaps it would be useful to add an option to jq-mode that would cause the last interactive jq expression to be pushed to the kill-ring automatically.
That's very unusual in Emacs, I cannot think of any other minibuffer-reading routine doing that. Would you be OK with the content always being pushed to the kill ring? I can imagine it being quite annoying.
Yes, if the content were always pushed to the kill ring, that would help. I'm generally using jq-interactive in order to come up with a jq expression that I will use in a script, for example, not just to get the output of jq in a buffer.
I have used C-x h C-w, i.e., mark-whole-buffer -> kill-region, but we could push it to a separate history variable that you can cycle through with a keybinding in a jq-mode buffer.
If you execute the command it will go into the jq-interactive-history variable. We could use that, we could even do something if you C-g and cheat something into the variable.
What about something like
(defun jq-insert-last-interactive-query ()
"Insert the last interactive query.
Useful when using `jq-interactively' to test out a query and then
insert it into a script."
(interactive)
(let ((query (car-safe jq-interactive-history)))
(when query
(insert query))))
This requires my fix at #35.
I feel like a prefix argument should insert an entire shell statement (with jq '...'), or maybe choose a different query from the history. I could probably put a PR together with either one if people know what they want. Otherwise, I might just leave the simple version like this.