jq-mode icon indicating copy to clipboard operation
jq-mode copied to clipboard

Option to push the values entered in the jq-interactive minibuffer into the kill-ring?

Open blak3mill3r opened this issue 7 years ago • 5 comments

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.

blak3mill3r avatar Oct 12 '18 13:10 blak3mill3r

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.

Fuco1 avatar Oct 12 '18 14:10 Fuco1

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.

blak3mill3r avatar Oct 12 '18 14:10 blak3mill3r

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.

ljos avatar Oct 14 '18 13:10 ljos

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.

ljos avatar Oct 14 '18 13:10 ljos

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.

gvol avatar Aug 18 '23 04:08 gvol