This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Is there a command to "paste as quote JS/CLJS string" (or Java/Clojure string)? I find myself needing this all the time
It would paste one "two three" four
as "one \"two three\" four"
I don't know how to do that in emacs but I usually cheat by opening a ruby repl and wrapping it in %{}
so %{one "two three" four}
which then is inspected and I get:
>> %{one "two three" four}
=> "one \"two three\" four"
Not sure if there's one already, but I've got this in my config:
(defun dc/yank-as-quoted-string
"Insert the clipboard contents as a string with escaped double quotes."
(interactive)
(let ((string (current-kill 0 t)))
(insert (concat "\"" (replace-regexp-in-string "\"" "\\\\\"" string) "\""))))
Thanks @U02CV2P4J6S - taking inspiration from your snippet, I came up with this, based on simpleclip:
(defun quote-js (s)
(with-temp-buffer
(insert s)
(shell-command-on-region (point-min) (point-max) "python -c \"import sys,json; sys.stdout.write(json.dumps(sys.stdin.read()))\"" nil 'replace)
(buffer-string)))
(defun paste-quoted ()
(interactive "*")
(let ((str-val (quote-js (simpleclip-get-contents))))
(unless str-val
(error "No content to paste"))
(when (use-region-p)
(delete-region (region-beginning) (region-end)))
(push-mark (point) t)
(insert-for-yank str-val)
(when (and (not (minibufferp))
(not simpleclip-less-feedback)
(simpleclip-called-interactively-p 'interactive))
(message "pasted quoted from clipboard"))))
You meant @U013TCGL92T 😛
Thanks to both (but wow - that Slack UX is confusing)
You'd think they'd sort user tags by closest context :P.
If you’re using separedit (which I heartily recommend):
(defun yank-quoted ()
(interactive)
(separedit-dwim)
(yank)
(separedit-commit))
I wrote a hackable clipboard transformer that can do that. Can you write clojure that does the transformation you want? like, is it just string replace "
with \"
?
here’s what a config entry for it looks like:
{:re #"replace! (.+) with (.+) in (.+)"
:export (fn [[_ search replace text]]
(str/replace text (re-pattern search) replace))}
https://github.com/magnars/string-edit.el this package changed my life