commit a2d5e68106c12826429e0166350ecf4307a261e9
parent 38d72eab7460fc8f913e12048397f3fd05c34b05
Author: Lukas Henkel <lh@entf.net>
Date: Mon, 4 Jul 2022 20:46:01 +0200
Add restclient-jq
Diffstat:
4 files changed, 116 insertions(+), 1 deletion(-)
diff --git a/elpa/restclient-jq-20220426.1734/restclient-jq-autoloads.el b/elpa/restclient-jq-20220426.1734/restclient-jq-autoloads.el
@@ -0,0 +1,28 @@
+;;; restclient-jq-autoloads.el --- automatically extracted autoloads (do not edit) -*- lexical-binding: t -*-
+;; Generated by the `loaddefs-generate' function.
+
+;; This file is part of GNU Emacs.
+
+;;; Code:
+
+(add-to-list 'load-path (directory-file-name
+ (or (file-name-directory #$) (car load-path))))
+
+
+
+;;; Generated autoloads from restclient-jq.el
+
+(register-definition-prefixes "restclient-jq" '("restclient-jq-"))
+
+;;; End of scraped data
+
+(provide 'restclient-jq-autoloads)
+
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; coding: utf-8-emacs-unix
+;; End:
+
+;;; restclient-jq-autoloads.el ends here
diff --git a/elpa/restclient-jq-20220426.1734/restclient-jq-pkg.el b/elpa/restclient-jq-20220426.1734/restclient-jq-pkg.el
@@ -0,0 +1,2 @@
+;;; Generated package description from restclient-jq.el -*- no-byte-compile: t -*-
+(define-package "restclient-jq" "20220426.1734" "Support for setting restclient vars from jq expressions" '((restclient "20200502.831") (jq-mode "0.4.1") (emacs "24.4")) :commit "ae79e7dd283890072da69b8f48aeec1afd0d9442" :authors '(("Cameron Dorrat" . "cdorrat@gmail.com")) :maintainer '("Cameron Dorrat" . "cdorrat@gmail.com") :keywords '("tools" "comm" "http" "jq") :url "https://github.com/pashky/restclient.el")
diff --git a/elpa/restclient-jq-20220426.1734/restclient-jq.el b/elpa/restclient-jq-20220426.1734/restclient-jq.el
@@ -0,0 +1,85 @@
+;;; restclient-jq.el --- Support for setting restclient vars from jq expressions -*- lexical-binding: t; -*-
+;;
+;; Public domain.
+
+;; URL: https://github.com/pashky/restclient.el
+;; Package-Version: 20220426.1734
+;; Package-Commit: ae79e7dd283890072da69b8f48aeec1afd0d9442
+;; Author: Cameron Dorrat <cdorrat@gmail.com>
+;; Maintainer: Cameron Dorrat <cdorrat@gmail.com>
+;; Created: 26 Apr 2020
+;; Keywords: tools comm http jq
+;; Version: 0.1
+;; Package-Requires: ((restclient "20200502.831") (jq-mode "0.4.1") (emacs "24.4"))
+
+;; This file is not part of GNU Emacs.
+;; This file is public domain software. Do what you want.
+
+;;; Commentary:
+;;
+;; This is a companion to restclient.el to add support for setting variables from results using jq expressions
+
+;;; Code:
+;;
+(require 'restclient)
+(require 'jq-mode)
+
+;; --- jq support
+(defun restclient-jq-result-end-point ()
+ "Find the end of a restclient JSON response body."
+ (save-excursion
+ (goto-char (point-max))
+ (or (and (re-search-backward "^[^/].*" nil t)
+ (line-end-position))
+ (point-max))))
+
+(defun restclient-jq-get-var (jq-pattern)
+ "Find value matching the JQ-PATTERN in a restclient JSON response."
+
+ (with-temp-buffer
+ (let ((output (current-buffer)))
+ (with-current-buffer restclient-same-buffer-response-name
+ (call-process-region
+ (point-min)
+ (restclient-jq-result-end-point)
+ shell-file-name
+ nil
+ output
+ nil
+ shell-command-switch
+ (format "%s %s %s"
+ jq-interactive-command
+ "-r"
+ (shell-quote-argument jq-pattern))))
+ (string-trim (buffer-string)))))
+
+(defun restclient-jq-json-var-function (args _args-offset)
+ "A restclient result func for setting variables from a JSON response.
+
+ARGS contains the variable name and a jq pattern to use."
+ (save-match-data
+ (and (string-match "\\(:[^: \n]+\\) \\(.*\\)$" args)
+ (let ((var-name (match-string 1 args))
+ (jq-patt (match-string 2 args)))
+ (lambda ()
+ (let ((resp-val (restclient-jq-get-var jq-patt)))
+ (restclient-remove-var var-name)
+ (restclient-set-var var-name resp-val)
+ (message "restclient var [%s = \"%s\"] " var-name resp-val)))))))
+
+(defun restclient-jq-interactive-result ()
+ "Run jq interactively on a restclient JSON response buffer."
+ (interactive)
+ (flush-lines "^//.*") ;; jq doesnt like comments
+ (jq-interactively (point-min) (restclient-jq-result-end-point)))
+
+(restclient-register-result-func
+ "jq-set-var" #'restclient-jq-json-var-function
+ "Set a restclient variable with the value jq expression,
+takes var & jq expression as args.
+eg. -> jq-set-var :my-token .token")
+(define-key restclient-response-mode-map (kbd "C-c C-j") #'restclient-jq-interactive-result)
+
+(provide 'restclient-jq)
+
+;;; restclient-jq.el ends here
diff --git a/init.el b/init.el
@@ -268,7 +268,7 @@
("melpa-stable" . "https://stable.melpa.org/packages/")
("melpa" . "https://melpa.org/packages/")))
'(package-selected-packages
- '(graphviz-dot-mode consult-eglot jq-mode multiple-cursors ob-restclient restclient vterm deadgrep helpful pdf-tools paredit-menu paredit corfu sly eglot aggressive-indent project nov nhexl-mode elfeed magit yaml-mode json-mode lua-mode go-mode geiser-guile geiser org-roam org-contrib org ace-window expand-region consult marginalia uuidgen request diminish which-key))
+ '(restclient-jq graphviz-dot-mode consult-eglot jq-mode multiple-cursors ob-restclient restclient vterm deadgrep helpful pdf-tools paredit-menu paredit corfu sly eglot aggressive-indent project nov nhexl-mode elfeed magit yaml-mode json-mode lua-mode go-mode geiser-guile geiser org-roam org-contrib org ace-window expand-region consult marginalia uuidgen request diminish which-key))
'(pcomplete-ignore-case t t)
'(pixel-scroll-precision-mode t)
'(read-buffer-completion-ignore-case t)