From a7277bbdaa51a1e992b85ac54225e1dcbfa512b5 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Thu, 18 Jul 2024 15:14:31 +0200 Subject: [PATCH] update ob-restclient Signed-off-by: Andreas Gerler --- .../ob-restclient-autoloads.el | 32 ++++---- .../ob-restclient-pkg.el | 4 +- .../ob-restclient.el | 76 ++++++++++++++----- 3 files changed, 73 insertions(+), 39 deletions(-) rename elpa/{ob-restclient-20230301.1951 => ob-restclient-20231228.1403}/ob-restclient-autoloads.el (54%) rename elpa/{ob-restclient-20230301.1951 => ob-restclient-20231228.1403}/ob-restclient-pkg.el (70%) rename elpa/{ob-restclient-20230301.1951 => ob-restclient-20231228.1403}/ob-restclient.el (66%) diff --git a/elpa/ob-restclient-20230301.1951/ob-restclient-autoloads.el b/elpa/ob-restclient-20231228.1403/ob-restclient-autoloads.el similarity index 54% rename from elpa/ob-restclient-20230301.1951/ob-restclient-autoloads.el rename to elpa/ob-restclient-20231228.1403/ob-restclient-autoloads.el index 4c1aadc7..a503d930 100644 --- a/elpa/ob-restclient-20230301.1951/ob-restclient-autoloads.el +++ b/elpa/ob-restclient-20231228.1403/ob-restclient-autoloads.el @@ -1,37 +1,37 @@ -;;; ob-restclient-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- -;; +;;; ob-restclient-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)))) +(add-to-list 'load-path (or (and load-file-name (directory-file-name (file-name-directory load-file-name))) (car load-path))) + -;;;### (autoloads nil "ob-restclient" "ob-restclient.el" (0 0 0 0)) ;;; Generated autoloads from ob-restclient.el (autoload 'org-babel-execute:restclient "ob-restclient" "\ Execute a block of Restclient code with org-babel. This function is called by `org-babel-execute-src-block' -\(fn BODY PARAMS)" nil nil) - +(fn BODY PARAMS)") (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) +Return a list of statements assigning variables specified in PARAMS. +(fn PARAMS)") (register-definition-prefixes "ob-restclient" '("org-babel-")) - -;;;*** -;;;### (autoloads nil nil ("ob-restclient-pkg.el") (0 0 0 0)) +;;; End of scraped data + +(provide 'ob-restclient-autoloads) -;;;*** - ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t -;; coding: utf-8 +;; no-native-compile: t +;; coding: utf-8-emacs-unix ;; End: + ;;; ob-restclient-autoloads.el ends here diff --git a/elpa/ob-restclient-20230301.1951/ob-restclient-pkg.el b/elpa/ob-restclient-20231228.1403/ob-restclient-pkg.el similarity index 70% rename from elpa/ob-restclient-20230301.1951/ob-restclient-pkg.el rename to elpa/ob-restclient-20231228.1403/ob-restclient-pkg.el index 3cd45970..1c08d32c 100644 --- a/elpa/ob-restclient-20230301.1951/ob-restclient-pkg.el +++ b/elpa/ob-restclient-20231228.1403/ob-restclient-pkg.el @@ -1,6 +1,6 @@ -(define-package "ob-restclient" "20230301.1951" "org-babel functions for restclient-mode" +(define-package "ob-restclient" "20231228.1403" "org-babel functions for restclient-mode" '((restclient "0")) - :commit "ded3b7eb7b0592328a7a08ecce6f25278cba4a1d" :authors + :commit "8183f8af08838854cf145ca4855b373f3e7c44b0" :authors '(("Alf Lervåg")) :maintainers '(("Alf Lervåg")) diff --git a/elpa/ob-restclient-20230301.1951/ob-restclient.el b/elpa/ob-restclient-20231228.1403/ob-restclient.el similarity index 66% rename from elpa/ob-restclient-20230301.1951/ob-restclient.el rename to elpa/ob-restclient-20231228.1403/ob-restclient.el index ff5cf6b9..39f60c24 100644 --- a/elpa/ob-restclient-20230301.1951/ob-restclient.el +++ b/elpa/ob-restclient-20231228.1403/ob-restclient.el @@ -1,11 +1,11 @@ -;;; ob-restclient.el --- org-babel functions for restclient-mode +;;; ob-restclient.el --- org-babel functions for restclient-mode -*- lexical-binding: t -*- ;; Copyright (C) Alf Lervåg ;; Author: Alf Lervåg ;; Keywords: literate programming, reproducible research ;; Homepage: https://github.com/alf/ob-restclient.el -;; Version: 0.02 +;; Version: 0.03 ;; Package-Requires: ((restclient "0")) ;;; License: @@ -37,6 +37,7 @@ (require 'ob-ref) (require 'ob-comint) (require 'ob-eval) +(require 'org-table) (require 'restclient) (defvar org-babel-default-header-args:restclient @@ -44,7 +45,9 @@ "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") + "The path to `jq', for post-processing. Uses the PATH by default" + :type '(string) + :group 'org-babel) ;;;###autoload (defun org-babel-execute:restclient (body params) @@ -56,6 +59,8 @@ This function is called by `org-babel-execute-src-block'" (restclient-same-buffer-response t) (restclient-response-body-only (org-babel-restclient--should-hide-headers-p params)) (restclient-same-buffer-response-name (buffer-name)) + (raw-only (org-babel-restclient--raw-payload-p params)) + (suppress-response-buffer (fboundp #'restclient-http-send-current-suppress-response-buffer)) (display-buffer-alist (cons '("\\*temp\\*" display-buffer-no-window (allow-no-window . t)) @@ -63,17 +68,14 @@ This function is called by `org-babel-execute-src-block'" (insert (buffer-name)) (with-temp-buffer - (dolist (p params) - (let ((key (car p)) - (value (cdr p))) - (when (eql key :var) - (insert (format ":%s = <<\n%s\n#\n" (car value) (cdr value)))))) - (insert body) + (insert + (org-babel-expand-body:generic + body params + (org-babel-variable-assignments:restclient params))) (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)) + (restclient-http-parse-current-and-do 'restclient-http-do raw-only t suppress-response-buffer)) (while restclient-within-call (sleep-for 0.05)) @@ -91,28 +93,54 @@ This function is called by `org-babel-execute-src-block'" (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) + results-buffer t)) - ;; widen if jq but not pure payload + ;; 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)))) + (if (member "table" (cdr (assoc :result-params params))) + (let* ((separator '(4)) + (result + (condition-case err + (let ((pmax (point-max))) + ;; If the buffer is empty, don't bother trying to + ;; convert the table. + (when (> pmax 1) + (org-table-convert-region (point-min) pmax separator) + (delq nil + (mapcar (lambda (row) + (and (not (eq row 'hline)) + (mapcar #'org-babel-string-read row))) + (org-table-to-lisp))))) + (error + (display-warning 'org-babel + (format "Error reading results: %S" err) + :error) + nil)))) + (pcase result + (`((,scalar)) scalar) + (`((,_ ,_ . ,_)) result) + (`(,scalar) scalar) + (_ result))) + (when (not (org-babel-restclient--return-pure-payload-result-p params)) + (org-babel-restclient--wrap-result)) + (buffer-string))))) ;;;###autoload (defun org-babel-variable-assignments:restclient (params) - "Return a list of restclient statements assigning the block's variables specified in PARAMS." + "Return a list of statements assigning variables specified in PARAMS." (mapcar (lambda (pair) (let ((name (car pair)) - (value (cdr pair))) - (format ":%s = %s" name value))) + (value (cdr pair)) + (format-string ":%s = %s\n")) + (when (string-match-p "\n" value) + (setq format-string ":%s = <<\n%s\n#\n")) + (format format-string name value))) (org-babel--get-vars params))) (defun org-babel-restclient--wrap-result () @@ -120,6 +148,8 @@ This function is called by `org-babel-execute-src-block'" (let ((mode-name (substring (symbol-name major-mode) 0 -5))) (insert (format "#+BEGIN_SRC %s\n" mode-name)) (goto-char (point-max)) + (unless (and (bolp) (eolp)) + (insert "\n")) (insert "#+END_SRC\n"))) (defun org-babel-restclient--should-hide-headers-p (params) @@ -134,12 +164,16 @@ This function is called by `org-babel-execute-src-block'" (when result-type (string-match "value\\|table" result-type)))) +(defun org-babel-prep-session:restclient (_session _params) + "Return an error because restclient does not support sessions." + (error "Restclient does not support sessions")) (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 - (string-match "file" result-type)))) + (and (not (org-babel-restclient--should-hide-headers-p params)) + (string-match "file" result-type))))) (provide 'ob-restclient) ;;; ob-restclient.el ends here -- 2.47.3