Fix Duplicate Windows With ob-restclient
NOTE: This first fix only works with some :jq calls from ob-restclient. Specifcally, it doesn't work with `value` - there's another attempt lower that is in progress
When running restcliet in org mode via ob-restclient on my spacemacs install it would make a second window showing whatever buffer I was running the process in.
I put together this hack to close it.
Specifically, I add these two lines into my own copy of the `org-babel-restclient--wrap-result` funciton
Code
(other-window 2)
(delete-window)
The full things looks like this:
That's an update to the code in this file
https://github.com/alf/ob-restclient.el/blob/master/ob-restclient.el
Doing this fix by throwing content into a variable, probably make idomatic to use a buffer.
Code
(defvar aws-restclient-content nil
"Holder for the contents so you can
close the temporary buffer windows as
a hack"
)
(defun org-babel-execute:restclient (body params)
"Execute a block of Restclient code with org-babel.
This function is called by `org-babel-execute-src-block'"
(message "AWS MODIFIED: org-babel-execute:restclient")
(message "executing Restclient source code block")
(with-temp-buffer
(let ((results-buffer (current-buffer))
(restclient-same-buffer-response t)
(restclient-same-buffer-response-name (buffer-name))
(display-buffer-alist
(cons
'("\\*temp\\*" display-buffer-no-window (allow-no-window . t))
display-buffer-alist)))
(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)
(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 (equal (buffer-name) (buffer-string))
(error "Restclient encountered an error"))
(when (or (org-babel-restclient--return-pure-payload-result-p params)
(assq :noheaders params)
(assq :jq params))
(org-babel-restclient--hide-headers))
(when-let* ((jq-header (assoc :jq params))
(jq-path "jq"))
(shell-command-on-region
(point-min)
(point-max)
(format "%s %s" org-babel-restclient--jq-path
(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))
(setq aws-restclient-content (buffer-string))
(buffer-string)
))
(other-window 1)
(delete-window)
(prin1-to-string aws-restclient-content t)
)