about summary refs log tree commit diff stats
path: root/.emacs.d/lisp/init-misc.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/init-misc.el')
-rw-r--r--.emacs.d/lisp/init-misc.el26
1 files changed, 23 insertions, 3 deletions
diff --git a/.emacs.d/lisp/init-misc.el b/.emacs.d/lisp/init-misc.el
index d71c646..82c4264 100644
--- a/.emacs.d/lisp/init-misc.el
+++ b/.emacs.d/lisp/init-misc.el
@@ -44,8 +44,27 @@
                       (cdar restclient-saved-requests)
                     (alist-get (completing-read "Call: " (map-keys restclient-saved-requests)) restclient-saved-requests nil nil 'string-equal))))
         (apply 'restclient-http-do args))))
+
+  ;; https://github.com/pashky/restclient.el/issues/288#issuecomment-1775770753
+  (defun my/restclient-copy-curl-command ()
+    "Formats the request as a curl command and copies the command to the clipboard."
+    (interactive)
+    (restclient-http-parse-current-and-do
+     '(lambda (method url headers entity)
+        (let* ((header-args
+                (apply 'append
+                       (mapcar (lambda (header)
+                                 (list "-H" (format "\"%s: %s\"" (car header) (cdr header))))
+                               headers)))
+               (header-parsed (mapconcat 'identity header-args " "))
+               (method-arg (concat "-X" " " method))
+               (entity-arg (if (> 0 (string-width entity)) ""
+                             (format "-d \x27%s\x27" entity)))
+               (curl-command (format "curl %s %s %s %s" header-parsed method-arg url entity-arg)))
+          (kill-new curl-command)
+          (message "curl command copied to clipboard.")))))
   :bind
-  ("C-c C-h" . restclient-call-saved-request)
+  ("C-c M-h" . restclient-call-saved-request)
   (:map restclient-mode-map ("C-c h" . restclient-save-current))
   :mode (("\\.http\\'" . restclient-mode)))
 
@@ -61,8 +80,9 @@
 
 (use-package csv-mode
   :bind (:map csv-mode-map
-              ("M-]" . csv-forward-field)
-              ("M-[" . csv-backward-field)))
+              ;; TODO find something less awkward
+              ("C-M-)" . csv-forward-field)
+              ("C-M-(" . csv-backward-field)))
 
 (use-package yaml-mode
   :diminish