The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Fix Duplicate Windows With ob-restclient

TODO: Pull subtitle into page object

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_start_default_section code_end_default_section

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Fix Duplicate Windows With ob-restclient

-- p

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

-- p

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.

-- p

I put together this hack to close it.

-- p

Specifically, I add these two lines into
my own copy of the `org-babel-restclient--wrap-result`
funciton

-- code/

(other-window 2)
  (delete-window)

-- /code

-- p

The full things looks like this:

-- p

That's an update to the code in this file

-- p

https://github.com/alf/ob-restclient.el/blob/master/ob-restclient.el

-- p

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)

  )

-- /code


-- categories
-- Miscellaneous

-- metadata
-- date: 2022-06-02 02:23:17
-- id: 2a0eb4o7
-- status: scratch
-- type: post
-- SCRUBBED_NEO: false
-- site: aws