[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/plz d2a7368699 37/40: Tidy: (plz) Don't switch to proce
From: |
ELPA Syncer |
Subject: |
[elpa] externals/plz d2a7368699 37/40: Tidy: (plz) Don't switch to process-buffer |
Date: |
Mon, 26 Jun 2023 06:59:34 -0400 (EDT) |
branch: externals/plz
commit d2a736869918a85bd962dc220205d2ffbdb29e21
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Tidy: (plz) Don't switch to process-buffer
This is even simpler and avoids a buffer switching.
---
plz.el | 215 +++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 108 insertions(+), 107 deletions(-)
diff --git a/plz.el b/plz.el
index ed198044c8..a8e2732ab8 100644
--- a/plz.el
+++ b/plz.el
@@ -412,114 +412,115 @@ NOQUERY is passed to `make-process', which see.
then (lambda (result)
(process-put process :plz-result result))
else nil))
- (with-current-buffer process-buffer
- (let ((then (pcase-exhaustive as
- ((or 'binary 'string)
- (lambda ()
- (let ((coding-system (or (plz--coding-system) 'utf-8)))
- (pcase as
- ('binary (set-buffer-multibyte nil)))
- (plz--narrow-to-body)
- (when decode
- (decode-coding-region (point) (point-max)
coding-system))
- (funcall then (or (buffer-string)
- (make-plz-error :message (format
"buffer-string is nil in buffer:%S" process-buffer)))))))
- ('buffer (lambda ()
- (funcall then (current-buffer))))
- ('response (lambda ()
- (funcall then (or (plz--response :decode-p
decode)
- (make-plz-error :message
(format "response is nil for buffer:%S buffer-string:%S"
-
process-buffer (buffer-string)))))))
- ('file (lambda ()
- (set-buffer-multibyte nil)
+ (setf
+ ;; Set the callbacks, etc. as process properties.
+ (process-get process :plz-then)
+ (pcase-exhaustive as
+ ((or 'binary 'string)
+ (lambda ()
+ (let ((coding-system (or (plz--coding-system) 'utf-8)))
+ (pcase as
+ ('binary (set-buffer-multibyte nil)))
+ (plz--narrow-to-body)
+ (when decode
+ (decode-coding-region (point) (point-max) coding-system))
+ (funcall then (or (buffer-string)
+ (make-plz-error :message (format "buffer-string
is nil in buffer:%S" process-buffer)))))))
+ ('buffer (lambda ()
+ (funcall then (current-buffer))))
+ ('response (lambda ()
+ (funcall then (or (plz--response :decode-p decode)
+ (make-plz-error :message (format
"response is nil for buffer:%S buffer-string:%S"
+
process-buffer (buffer-string)))))))
+ ('file (lambda ()
+ (set-buffer-multibyte nil)
+ (plz--narrow-to-body)
+ (let ((filename (make-temp-file "plz-")))
+ (condition-case err
+ (progn
+ (write-region (point-min) (point-max) filename)
+ (funcall then filename))
+ ;; In case of an error writing to the file, delete the
temp file
+ ;; and signal the error. Ignore any errors encountered
while
+ ;; deleting the file, which would obscure the original
error.
+ (error (ignore-errors
+ (delete-file filename))
+ (funcall then (make-plz-error :message (format
"error while writing to file %S: %S" filename err))))))))
+ (`(file ,(and (pred stringp) filename))
+ (lambda ()
+ (set-buffer-multibyte nil)
+ (plz--narrow-to-body)
+ (condition-case err
+ (progn
+ (write-region (point-min) (point-max) filename nil nil nil
'excl)
+ (funcall then filename))
+ ;; Since we are creating the file, it seems sensible to delete it
in case of an
+ ;; error while writing to it (e.g. a disk-full error). And we
ignore any errors
+ ;; encountered while deleting the file, which would obscure the
original error.
+ (error (ignore-errors
+ (when (file-exists-p filename)
+ (delete-file filename)))
+ (funcall then (make-plz-error :message (format "error while
writing to file %S: %S" filename err)))))))
+ ((pred functionp) (lambda ()
+ (let ((coding-system (or (plz--coding-system)
'utf-8)))
(plz--narrow-to-body)
- (let ((filename (make-temp-file "plz-")))
- (condition-case err
- (progn
- (write-region (point-min) (point-max)
filename)
- (funcall then filename))
- ;; In case of an error writing to the file,
delete the temp file
- ;; and signal the error. Ignore any errors
encountered while
- ;; deleting the file, which would obscure the
original error.
- (error (ignore-errors
- (delete-file filename))
- (funcall then (make-plz-error :message
(format "error while writing to file %S: %S" filename err))))))))
- (`(file ,(and (pred stringp) filename))
- (lambda ()
- (set-buffer-multibyte nil)
- (plz--narrow-to-body)
- (condition-case err
- (progn
- (write-region (point-min) (point-max) filename
nil nil nil 'excl)
- (funcall then filename))
- ;; Since we are creating the file, it seems sensible
to delete it in case of an
- ;; error while writing to it (e.g. a disk-full
error). And we ignore any errors
- ;; encountered while deleting the file, which would
obscure the original error.
- (error (ignore-errors
- (when (file-exists-p filename)
- (delete-file filename)))
- (funcall then (make-plz-error :message (format
"error while writing to file %S: %S" filename err)))))))
- ((pred functionp) (lambda ()
- (let ((coding-system (or
(plz--coding-system) 'utf-8)))
- (plz--narrow-to-body)
- (when decode
- (decode-coding-region (point)
(point-max) coding-system))
- (funcall then (funcall as))))))))
- (setf (process-get process :plz-then) then
- (process-get process :plz-else) else
- (process-get process :plz-finally) finally
- (process-get process :plz-sync) sync-p
- ;; Record list of arguments for debugging purposes (e.g. when
- ;; using Edebug in a process buffer, this allows determining
- ;; which request the buffer is for).
- (process-get process :plz-args) (apply #'list method url rest))
- ;; Send --config arguments.
- (process-send-string process curl-config)
- (when body
- (cl-typecase body
- (string (process-send-string process body))
- (buffer (with-current-buffer body
- (process-send-region process (point-min) (point-max))))))
- (process-send-eof process)
- ;; HACK: We set the result to a sentinel value so that any other
- ;; value, even nil, means that the response was processed, and
- ;; the sentinel does not need to be called again (see below).
- (process-put process :plz-result :plz-result)
- (if sync-p
- (unwind-protect
- (progn
- ;; See Info node `(elisp)Accepting Output'.
- (unless (and process stderr-process)
- (error "Process unexpectedly nil"))
- (while (accept-process-output process))
- (while (accept-process-output stderr-process))
- (when (eq :plz-result (process-get process :plz-result))
- ;; HACK: Sentinel seems to not have been called: call it
again. (Although
- ;; this is a hack, it seems to be a necessary one due to
Emacs's process
- ;; handling.) See
<https://github.com/alphapapa/plz.el/issues/3> and
- ;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50166>.
- (plz--sentinel process "finished\n")
- (when (eq :plz-result (process-get process :plz-result))
- (error "Plz: NO RESULT FROM PROCESS:%S ARGS:%S"
- process rest)))
- ;; Sentinel seems to have been called: check the result.
- (pcase (process-get process :plz-result)
- ((and (pred plz-error-p) data)
- ;; The AS function signaled an error, which was collected
- ;; into a `plz-error' struct: re-signal the error here,
- ;; outside of the sentinel.
- (if (plz-error-response data)
- ;; FIXME: Signal only plz-error in v0.8.
- (signal 'plz-http-error (list "HTTP error" data))
- (signal 'plz-curl-error (list "Curl error" data))))
- (else
- ;; The AS function returned a value: return it.
- else)))
- (unless (eq as 'buffer)
- (kill-buffer process-buffer))
- (kill-buffer (process-buffer stderr-process)))
- ;; Async request: return the process object.
- process)))))
+ (when decode
+ (decode-coding-region (point) (point-max)
coding-system))
+ (funcall then (funcall as))))))
+ (process-get process :plz-else) else
+ (process-get process :plz-finally) finally
+ (process-get process :plz-sync) sync-p
+ ;; Record list of arguments for debugging purposes (e.g. when
+ ;; using Edebug in a process buffer, this allows determining
+ ;; which request the buffer is for).
+ (process-get process :plz-args) (apply #'list method url rest)
+ ;; HACK: We set the result to a sentinel value so that any other
+ ;; value, even nil, means that the response was processed, and
+ ;; the sentinel does not need to be called again (see below).
+ (process-get process :plz-result) :plz-result)
+ ;; Send --config arguments.
+ (process-send-string process curl-config)
+ (when body
+ (cl-typecase body
+ (string (process-send-string process body))
+ (buffer (with-current-buffer body
+ (process-send-region process (point-min) (point-max))))))
+ (process-send-eof process)
+ (if sync-p
+ (unwind-protect
+ (progn
+ ;; See Info node `(elisp)Accepting Output'.
+ (unless (and process stderr-process)
+ (error "Process unexpectedly nil"))
+ (while (accept-process-output process))
+ (while (accept-process-output stderr-process))
+ (when (eq :plz-result (process-get process :plz-result))
+ ;; HACK: Sentinel seems to not have been called: call it
again. (Although
+ ;; this is a hack, it seems to be a necessary one due to
Emacs's process
+ ;; handling.) See
<https://github.com/alphapapa/plz.el/issues/3> and
+ ;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50166>.
+ (plz--sentinel process "finished\n")
+ (when (eq :plz-result (process-get process :plz-result))
+ (error "Plz: NO RESULT FROM PROCESS:%S ARGS:%S"
+ process rest)))
+ ;; Sentinel seems to have been called: check the result.
+ (pcase (process-get process :plz-result)
+ ((and (pred plz-error-p) data)
+ ;; The AS function signaled an error, which was collected
+ ;; into a `plz-error' struct: re-signal the error here,
+ ;; outside of the sentinel.
+ (if (plz-error-response data)
+ ;; FIXME: Signal only plz-error in v0.8.
+ (signal 'plz-http-error (list "HTTP error" data))
+ (signal 'plz-curl-error (list "Curl error" data))))
+ (else
+ ;; The AS function returned a value: return it.
+ else)))
+ (unless (eq as 'buffer)
+ (kill-buffer process-buffer))
+ (kill-buffer (process-buffer stderr-process)))
+ ;; Async request: return the process object.
+ process)))
;;;;; Queue
- [elpa] externals/plz f551c1bd49 25/40: Tidy: (plz--respond), (continued)
- [elpa] externals/plz f551c1bd49 25/40: Tidy: (plz--respond), ELPA Syncer, 2023/06/26
- [elpa] externals/plz de8e21f81d 29/40: Tidy: Docstrings, ELPA Syncer, 2023/06/26
- [elpa] externals/plz f9f95a8544 34/40: Comment: Add TODO, ELPA Syncer, 2023/06/26
- [elpa] externals/plz c786bbf7d2 35/40: Tidy/Comment, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 438162db4e 13/40: WIP: Add request args to sentinel error, ELPA Syncer, 2023/06/26
- [elpa] externals/plz a1f8a10b0b 16/40: Comment: Add FIXME, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 880223e7c0 22/40: Tidy: (plz--sentinel), ELPA Syncer, 2023/06/26
- [elpa] externals/plz 53ef6a16ce 26/40: Comment: Tidy, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 582f0c5bb8 31/40: Tests: Enable continue-on-error for linting, ELPA Syncer, 2023/06/26
- [elpa] externals/plz b896c41d71 32/40: Change: Generate buffer for STDERR, ELPA Syncer, 2023/06/26
- [elpa] externals/plz d2a7368699 37/40: Tidy: (plz) Don't switch to process-buffer,
ELPA Syncer <=
- [elpa] externals/plz 9319470060 38/40: Merge branch 'wip/no-signal-from-sentinel-as-timer', ELPA Syncer, 2023/06/26
- [elpa] externals/plz 5e63662e21 40/40: Docs: Update changelog, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 0cb20bc74d 03/40: Tidy, ELPA Syncer, 2023/06/26
- [elpa] externals/plz e28b4e8b6a 06/40: Tidy, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 8f263bfd0f 09/40: Comment: Remove old TODO, ELPA Syncer, 2023/06/26
- [elpa] externals/plz c181fd1565 10/40: Tidy: Error handling in THEN function, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 4735c8333d 17/40: Fix: (plz) Signal error with data as list, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 260840d3e7 18/40: Change: (plz--respond) Rename from plz--timer, ELPA Syncer, 2023/06/26
- [elpa] externals/plz b04b466d79 19/40: Change: Signal plz-curl/http-error again, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 5a60113110 21/40: Comment: Add links to bug reports, ELPA Syncer, 2023/06/26