[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/plz 3dfcbff613 36/40: Change: Use process properties in
From: |
ELPA Syncer |
Subject: |
[elpa] externals/plz 3dfcbff613 36/40: Change: Use process properties instead of buffer-local variables |
Date: |
Mon, 26 Jun 2023 06:59:34 -0400 (EDT) |
branch: externals/plz
commit 3dfcbff613d62d5fc520bf94ff5c7e0f2e5bbfa0
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Change: Use process properties instead of buffer-local variables
It's always good to not define any more symbols than necessary. And
IIRC the more buffer-local variables are defined in an Emacs instance,
the slower it is to iterate over buffers.
---
README.org | 1 +
plz.el | 47 ++++++++++++++---------------------------------
plz.info | 32 +++++++++++++++++---------------
3 files changed, 32 insertions(+), 48 deletions(-)
diff --git a/README.org b/README.org
index c336be5814..0e0e07ba51 100644
--- a/README.org
+++ b/README.org
@@ -186,6 +186,7 @@ You may also clear a queue with ~plz-clear~, which cancels
any active or queued
*Internal*
+ Tests now run against a local instance of
[[https://github.com/postmanlabs/httpbin][httpbin]] (since the ~httpbin.org~
server is often overloaded).
++ No buffer-local variables are defined anymore; process properties are used
instead.
** 0.6
diff --git a/plz.el b/plz.el
index dfbc8d1d6b..ed198044c8 100644
--- a/plz.el
+++ b/plz.el
@@ -217,24 +217,6 @@ only LF).")
(90 . "SSL public key does not matched pinned public key"))
"Alist mapping curl error code integers to helpful error messages.")
-;;;; Variables
-
-(defvar-local plz-else nil
- "Callback function for unsuccessful completion of request.
-Called in current curl process buffer.")
-
-(defvar-local plz-then nil
- "Callback function for successful completion of request.
-Called in current curl process buffer.")
-
-(defvar-local plz-finally nil
- "Function called unconditionally after completion of request.
-Called after the then/else function, without arguments, outside
-the curl process buffer.")
-
-(defvar-local plz-sync nil
- "Used when `plz' is called synchronously.")
-
;;;; Customization
(defgroup plz nil
@@ -483,11 +465,10 @@ NOQUERY is passed to `make-process', which see.
(when decode
(decode-coding-region (point)
(point-max) coding-system))
(funcall then (funcall as))))))))
- ;; TODO: Consider using process properties for these instead of
buffer-local vars.
- (setf plz-then then
- plz-else else
- plz-finally finally
- plz-sync sync-p
+ (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).
@@ -735,7 +716,7 @@ for asynchronous ones)."
(pred numberp)
(rx "exited abnormally with code " (group (1+ digit))))
(let ((buffer (process-buffer process)))
- (if (buffer-local-value 'plz-sync buffer)
+ (if (process-get process :plz-sync)
(plz--respond process buffer status)
(run-at-time 0 nil #'plz--respond process buffer status))))))
@@ -762,7 +743,7 @@ argument passed to `plz--sentinel', which see."
((and status (guard (<= 200 status 299)))
;; Any 2xx response is considered successful.
(ignore status) ; Byte-compiling in Emacs <28 complains without
this.
- (funcall plz-then))
+ (funcall (process-get process :plz-then)))
(_
;; TODO: If using ":as 'response", the HTTP response
;; should be passed to the THEN function, regardless
@@ -772,9 +753,9 @@ argument passed to `plz--sentinel', which see."
;; Any other status code is considered unsuccessful
;; (for now, anyway).
(let ((err (make-plz-error :response (plz--response))))
- (pcase-exhaustive plz-else
+ (pcase-exhaustive (process-get process :plz-else)
(`nil (process-put process :plz-result err))
- ((pred functionp) (funcall plz-else err)))))))
+ ((and (pred functionp) fn) (funcall fn err)))))))
((or (and (pred numberp) code)
(rx "exited abnormally with code " (let code (group (1+
digit)))))
@@ -784,9 +765,9 @@ argument passed to `plz--sentinel', which see."
(number code)))
(curl-error-message (alist-get curl-exit-code
plz-curl-errors))
(err (make-plz-error :curl-error (cons curl-exit-code
curl-error-message))))
- (pcase-exhaustive plz-else
+ (pcase-exhaustive (process-get process :plz-else)
(`nil (process-put process :plz-result err))
- ((pred functionp) (funcall plz-else err)))))
+ ((and (pred functionp) fn) (funcall fn err)))))
((and (or "killed\n" "interrupt\n") status)
;; Curl process killed or interrupted.
@@ -794,12 +775,12 @@ argument passed to `plz--sentinel', which see."
("killed\n" "curl process killed")
("interrupt\n" "curl process interrupted")))
(err (make-plz-error :message message)))
- (pcase-exhaustive plz-else
+ (pcase-exhaustive (process-get process :plz-else)
(`nil (process-put process :plz-result err))
- ((pred functionp) (funcall plz-else err)))))))
- (when-let ((finally (buffer-local-value 'plz-finally buffer)))
+ ((and (pred functionp) fn) (funcall fn err)))))))
+ (when-let ((finally (process-get process :plz-finally)))
(funcall finally))
- (unless (buffer-local-value 'plz-sync buffer)
+ (unless (process-get process :plz-sync)
(kill-buffer buffer))))
(defun plz--stderr-sentinel (process status)
diff --git a/plz.info b/plz.info
index fd7475cabb..5e6001a7b5 100644
--- a/plz.info
+++ b/plz.info
@@ -315,6 +315,8 @@ File: README.info, Node: 07-pre, Next: 06, Up: Changelog
• Tests now run against a local instance of httpbin
(https://github.com/postmanlabs/httpbin) (since the ‘httpbin.org’
server is often overloaded).
+ • No buffer-local variables are defined anymore; process properties
+ are used instead.
File: README.info, Node: 06, Next: 054, Prev: 07-pre, Up: Changelog
@@ -519,21 +521,21 @@ Node: Queueing6859
Node: Tips8242
Node: Changelog8543
Node: 07-pre8812
-Node: 069523
-Node: 05410138
-Node: 05310381
-Node: 05210697
-Node: 05110904
-Node: 0511156
-Node: 0411362
-Node: 0312268
-Node: 02112716
-Node: 0212867
-Node: 0112998
-Node: Credits13094
-Node: Development13460
-Node: Copyright assignment13974
-Node: License14562
+Node: 069619
+Node: 05410234
+Node: 05310477
+Node: 05210793
+Node: 05111000
+Node: 0511252
+Node: 0411458
+Node: 0312364
+Node: 02112812
+Node: 0212963
+Node: 0113094
+Node: Credits13190
+Node: Development13556
+Node: Copyright assignment14070
+Node: License14658
End Tag Table
- [elpa] externals/plz c181fd1565 10/40: Tidy: Error handling in THEN function, (continued)
- [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
- [elpa] externals/plz 96710ad323 23/40: Tidy, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 7edcd67472 27/40: Change: Set STDERR process and sentinel, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 3576b9820c 28/40: Tidy: Unused arguments, ELPA Syncer, 2023/06/26
- [elpa] externals/plz f94f8af98a 30/40: Tidy: Error message, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 1aad476df9 33/40: Fix: Replace string in error data, ELPA Syncer, 2023/06/26
- [elpa] externals/plz 3dfcbff613 36/40: Change: Use process properties instead of buffer-local variables,
ELPA Syncer <=
- [elpa] externals/plz 919d2b8500 39/40: Docs: Update changelog, ELPA Syncer, 2023/06/26