Skip to content

Commit a6965c8

Browse files
FIX louietan#76: handle both old and new function signatures of `request--curl-callback'
'request.el' commit '8ccbae1b5e5e2ae68112dd46a6bee67d318b0deb' changed the function signature ("arity") from 2 to 3 arguments. The current stable version of that package still uses the old number of args. The rolling-release master branch of 'request.el' uses the new number of args. This function handles both cases for the time being. (It is generally frowned upon to use provate functions from other packages since they are not considered a stable interface. However, for now, it is unavoidable since there is no "stable" interface to forec 'request.el' to run the callback.)
1 parent 835ce8d commit a6965c8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

anki-editor.el

+13-4
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ See https://apps.ankiweb.net/docs/manual.html#latex-conflicts.")
147147
(json-array-type 'list)
148148
reply err)
149149

150-
(let ((response (request (format "http://%s:%s"
151-
anki-editor-anki-connect-listening-address
152-
anki-editor-anki-connect-listening-port)
150+
(let* ((url (format "http://%s:%s"
151+
anki-editor-anki-connect-listening-address
152+
anki-editor-anki-connect-listening-port))
153+
(response (request url
153154
:type "POST"
154155
:parser 'json-read
155156
:data request-body
@@ -164,7 +165,15 @@ See https://apps.ankiweb.net/docs/manual.html#latex-conflicts.")
164165
;; might not be called right away but at a later time, that's
165166
;; why here we manually invoke callbacks to receive the result.
166167
(unless (request-response-done-p response)
167-
(request--curl-callback (get-buffer-process (request-response--buffer response)) "finished\n")))
168+
;; (request--curl-callback "localhost" (get-buffer-process (request-response--buffer response)) "finished\n")))
169+
(if (= 2 (func-arity (function 'request--curl-callback)))
170+
;; Handle the older, stable version of 'request.el' in which
171+
;; `request--curl-callback' has two args.
172+
(request--curl-callback (get-buffer-process (request-response--buffer response)) "finished\n")
173+
;; Handle new 3-argument function signature as of 'request.el' commit
174+
;; '8ccbae1b5e5e2ae68112dd46a6bee67d318b0deb'. Should fix anki-editor
175+
;; errors for those using newer versions of 'request.el'.
176+
(request--curl-callback url (get-buffer-process (request-response--buffer response)) "finished\n"))))
168177

169178
(when err (error "Error communicating with AnkiConnect using cURL: %s" err))
170179
(or reply (error "Got empty reply from AnkiConnect"))))

0 commit comments

Comments
 (0)