(defgroup syncthing nil
"Syncthing client customize group."
:prefix "syncthing-"
:group 'syncthing)
(defcustom syncthing-server "http://localhost"
"The server of Syncthing."
:type 'string
:safe #'stringp
:group 'syncthing)
(defcustom syncthing-port 8080
"The port of Syncthing."
:type 'number
:safe #'numberp
:group 'syncthing)
(defcustom syncthing-api-key "n9mrv83iyememn3sgbc7z291k6o07r"
"The API key for Syncthing."
:type 'string
:safe #'stringp
:group 'syncthing)
(defmacro syncthing--rest-api (method endpoint &rest arglist)
"The Syncthing REST API macro to construct HTTP METHOD, ENDPOINT with ARGLIST."
`(defun ,(intern (format "syncthing-api-%s-%s" method endpoint)) ,arglist
(let ((url-request-method ,method)
(url-request-extra-headers '(("X-API-Key" . ,syncthing-api-key))))
(with-current-buffer
(url-retrieve-synchronously
(format "%s:%s%s" syncthing-server syncthing-port ,endpoint))
(goto-char (point-min))
(re-search-forward "^$")
(let ((result (json-read)))
result)))))
(defvar syncthing--http-rest-endpoints-alist
'(("GET" . "/rest/system/browse")
("GET" . "/rest/system/config")
("GET" . "/rest/system/config/isync")))
(syncthing--rest-api "GET" "/rest/system/config")
(mapcar
(lambda (pair)
(syncthing--rest-api (car pair) (cdr pair))) ; <-- problem here.
syncthing--http-rest-endpoints-alist)
请问,这里创建macro后,为上面单独一行能够正常生产函数。但是在 mapcar
里面却无法解开 (car pair)
和 (cdr pair)
. 输出的结果是:
(syncthing-api-\(car\ pair\)-\(cdr\ pair\) syncthing-api-\(car\ pair\)-\(cdr\ pair\) syncthing-api-\(car\ pair\)-\(cdr\ pair\))
这是为什么?应该怎样正确使用?