In wakatime-mode
, there are a bunch of process calls that is done by the wakatime-call
function. It calls a predefined shell command, so no real magic inside.
Now I’d like to make it a bit more error prone by adding a retry count. However, as this is done by a process sentinel, I have to create a lambda for this. A process sentinel takes two parameters, process
and signal
.
Question is, is it possible to somehow pass the value of a local (ie. function parameter) variable to a lambda for use, thus converting the lambda into a clojure? I’d prefer to go without moving to lexical binding.
Backquote is not an option (or is it?), as the variable I want to reference is not in the function’s argument list.
Here is the function:
(defun wakatime-call (savep &optional retrying)
"Call WakaTime command."
(let*
((command (wakatime-client-command savep t))
(process-environment (if wakatime-python-path
(cons (format "PYTHONPATH=%s"
wakatime-python-path)
process-environment)
process-environment))
(process (start-process
"Shell"
(generate-new-buffer " *WakaTime messages*")
shell-file-name
shell-command-switch
command)))
(set-process-sentinel process
`(lambda (process signal)
(when (memq (process-status process) '(exit signal))
(kill-buffer (process-buffer process))
(let ((exit-status (process-exit-status process)))
(when (and (not (= 0 exit-status)) (not (= 102 exit-status)))
(error "WakaTime Error (%s)" exit-status))
(when (= 102 exit-status)
; If we are retrying already, error out
(if retrying
(error "WakaTime Error (%s)" exit-status)
; otherwise, ask for an API key and call ourselves
; recursively
(wakatime-prompt-api-key)
(wakatime-call savep t)))))))
(set-process-query-on-exit-flag process nil)))
The goal is to access savep
and retrying
in the process sentinel’s lambda/closure.