From ba616cbb234dd5782c870d82d689c31f3fdef665 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sat, 25 Nov 2023 11:43:15 +0100 Subject: [PATCH] update ob-restclient Signed-off-by: Andreas Gerler --- .../ob-restclient-pkg.el | 2 - .../ob-restclient-autoloads.el | 13 ++- .../ob-restclient-pkg.el | 14 ++++ .../ob-restclient.el | 84 ++++++++++++------- 4 files changed, 79 insertions(+), 34 deletions(-) delete mode 100644 elpa/ob-restclient-20200316.759/ob-restclient-pkg.el rename elpa/{ob-restclient-20200316.759 => ob-restclient-20230301.1951}/ob-restclient-autoloads.el (65%) create mode 100644 elpa/ob-restclient-20230301.1951/ob-restclient-pkg.el rename elpa/{ob-restclient-20200316.759 => ob-restclient-20230301.1951}/ob-restclient.el (59%) diff --git a/elpa/ob-restclient-20200316.759/ob-restclient-pkg.el b/elpa/ob-restclient-20200316.759/ob-restclient-pkg.el deleted file mode 100644 index 2270e2f8..00000000 --- a/elpa/ob-restclient-20200316.759/ob-restclient-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; Generated package description from /Users/andreas/.emacs.d/elpa/ob-restclient-20200316.759/ob-restclient.el -*- no-byte-compile: t -*- -(define-package "ob-restclient" "20200316.759" "org-babel functions for restclient-mode" '((restclient "0")) :commit "0ebfc7c5ebf96d2fe1a476439831363a5a43b9b6" :authors '(("Alf Lervåg")) :maintainer '("Alf Lervåg") :keywords '("literate programming" "reproducible research") :url "https://github.com/alf/ob-restclient.el") diff --git a/elpa/ob-restclient-20200316.759/ob-restclient-autoloads.el b/elpa/ob-restclient-20230301.1951/ob-restclient-autoloads.el similarity index 65% rename from elpa/ob-restclient-20200316.759/ob-restclient-autoloads.el rename to elpa/ob-restclient-20230301.1951/ob-restclient-autoloads.el index 747e57d9..4c1aadc7 100644 --- a/elpa/ob-restclient-20200316.759/ob-restclient-autoloads.el +++ b/elpa/ob-restclient-20230301.1951/ob-restclient-autoloads.el @@ -1,4 +1,4 @@ -;;; ob-restclient-autoloads.el --- automatically extracted autoloads +;;; ob-restclient-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- ;; ;;; Code: @@ -15,7 +15,16 @@ This function is called by `org-babel-execute-src-block' \(fn BODY PARAMS)" nil nil) -(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "ob-restclient" '("org-babel-"))) +(autoload 'org-babel-variable-assignments:restclient "ob-restclient" "\ +Return a list of restclient statements assigning the block's variables specified in PARAMS. + +\(fn PARAMS)" nil nil) + +(register-definition-prefixes "ob-restclient" '("org-babel-")) + +;;;*** + +;;;### (autoloads nil nil ("ob-restclient-pkg.el") (0 0 0 0)) ;;;*** diff --git a/elpa/ob-restclient-20230301.1951/ob-restclient-pkg.el b/elpa/ob-restclient-20230301.1951/ob-restclient-pkg.el new file mode 100644 index 00000000..3cd45970 --- /dev/null +++ b/elpa/ob-restclient-20230301.1951/ob-restclient-pkg.el @@ -0,0 +1,14 @@ +(define-package "ob-restclient" "20230301.1951" "org-babel functions for restclient-mode" + '((restclient "0")) + :commit "ded3b7eb7b0592328a7a08ecce6f25278cba4a1d" :authors + '(("Alf Lervåg")) + :maintainers + '(("Alf Lervåg")) + :maintainer + '("Alf Lervåg") + :keywords + '("literate programming" "reproducible research") + :url "https://github.com/alf/ob-restclient.el") +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/elpa/ob-restclient-20200316.759/ob-restclient.el b/elpa/ob-restclient-20230301.1951/ob-restclient.el similarity index 59% rename from elpa/ob-restclient-20200316.759/ob-restclient.el rename to elpa/ob-restclient-20230301.1951/ob-restclient.el index 9e3af3cf..ff5cf6b9 100644 --- a/elpa/ob-restclient-20200316.759/ob-restclient.el +++ b/elpa/ob-restclient-20230301.1951/ob-restclient.el @@ -4,8 +4,6 @@ ;; Author: Alf Lervåg ;; Keywords: literate programming, reproducible research -;; Package-Version: 20200316.759 -;; Package-Commit: 0ebfc7c5ebf96d2fe1a476439831363a5a43b9b6 ;; Homepage: https://github.com/alf/ob-restclient.el ;; Version: 0.02 ;; Package-Requires: ((restclient "0")) @@ -45,6 +43,9 @@ `((:results . "raw")) "Default arguments for evaluating a restclient block.") +(defcustom org-babel-restclient--jq-path "jq" + "The path to `jq', for post-processing. Uses the PATH by default") + ;;;###autoload (defun org-babel-execute:restclient (body params) "Execute a block of Restclient code with org-babel. @@ -53,6 +54,7 @@ This function is called by `org-babel-execute-src-block'" (with-temp-buffer (let ((results-buffer (current-buffer)) (restclient-same-buffer-response t) + (restclient-response-body-only (org-babel-restclient--should-hide-headers-p params)) (restclient-same-buffer-response-name (buffer-name)) (display-buffer-alist (cons @@ -67,51 +69,73 @@ This function is called by `org-babel-execute-src-block'" (when (eql key :var) (insert (format ":%s = <<\n%s\n#\n" (car value) (cdr value)))))) (insert body) - (goto-char (point-min)) - (delete-trailing-whitespace) - (goto-char (point-min)) - (restclient-http-parse-current-and-do - 'restclient-http-do (org-babel-restclient-raw-payload-p params) t)) + (goto-char (point-min)) + (delete-trailing-whitespace) + (goto-char (point-min)) + (restclient-http-parse-current-and-do + 'restclient-http-do (org-babel-restclient--raw-payload-p params) t)) (while restclient-within-call (sleep-for 0.05)) (goto-char (point-min)) - (when (search-forward (buffer-name) nil t) + (when (equal (buffer-name) (buffer-string)) (error "Restclient encountered an error")) - (if (org-babel-restclient-return-pure-payload-result-p params) - (org-babel-restclient-pure-payload-result) - (org-babel-restclient-wrap-result))))) + (when-let* ((jq-header (assoc :jq params)) + (jq-path "jq") + (jq-args (or (cdr (assoc :jq-args params)) ""))) + (shell-command-on-region + (point-min) + (point-max) + (format "%s %s--args %s" org-babel-restclient--jq-path + (if (assq :jq-args params) (format "%s " jq-args) "") + (shell-quote-argument (cdr jq-header))) + (current-buffer) + t)) + + ;; widen if jq but not pure payload + (when (and (assq :jq params) + (not (assq :noheaders params)) + (not (org-babel-restclient--return-pure-payload-result-p params))) + (widen)) + + (when (not (org-babel-restclient--return-pure-payload-result-p params)) + (org-babel-restclient--wrap-result)) + + (buffer-string)))) -(defun org-babel-restclient-wrap-result () +;;;###autoload +(defun org-babel-variable-assignments:restclient (params) + "Return a list of restclient statements assigning the block's variables specified in PARAMS." + (mapcar + (lambda (pair) + (let ((name (car pair)) + (value (cdr pair))) + (format ":%s = %s" name value))) + (org-babel--get-vars params))) + +(defun org-babel-restclient--wrap-result () "Wrap the contents of the buffer in an `org-mode' src block." (let ((mode-name (substring (symbol-name major-mode) 0 -5))) (insert (format "#+BEGIN_SRC %s\n" mode-name)) (goto-char (point-max)) - (insert "#+END_SRC\n") - (buffer-string))) - -(defun org-babel-restclient-pure-payload-result () - "Just return the payload." - (let ((comments-start - (save-excursion - (goto-char (point-max)) - (while (comment-only-p (line-beginning-position) (line-end-position)) - (forward-line -1)) - ;; Include the last line as well - (forward-line) - (point)))) - (buffer-substring (point-min) comments-start))) - - -(defun org-babel-restclient-return-pure-payload-result-p (params) + (insert "#+END_SRC\n"))) + +(defun org-babel-restclient--should-hide-headers-p (params) + "Return `t' if headers should be hidden." + (or (org-babel-restclient--return-pure-payload-result-p params) + (assq :noheaders params) + (assq :jq params))) + +(defun org-babel-restclient--return-pure-payload-result-p (params) "Return `t' if the `:results' key in PARAMS contains `value' or `table'." (let ((result-type (cdr (assoc :results params)))) (when result-type (string-match "value\\|table" result-type)))) -(defun org-babel-restclient-raw-payload-p (params) + +(defun org-babel-restclient--raw-payload-p (params) "Return t if the `:results' key in PARAMS contain `file'." (let ((result-type (cdr (assoc :results params)))) (when result-type -- 2.47.3