The code constantly prints server-process: nil instead of the server process name:

-*- lexical-binding: t; -*-
(let* ((port 1234)
       (server-process 'something))
  (setq server-process
         :server t
         :name "libbasecampel-oauth-http-server"
         :service port
         :buffer (generate-new-buffer "*libbasecampel-oauth-http-server*")
         :filter (lambda (_process _data)
                   (message "server-process: %s" server-process)))))

Can someone please explain why I can't access the server process from the filter lambda? Also, I would like to know how to do it, my goal being to kill the server when data arrives.

In case you wonder, the _process argument to the filter function is the client process, not the server one.

  • I don't know why lexical-binding at the top of your file does not have your desired effect, but you might want to try placing a backtick in front of (lambda and a comma before the server-process in the message statement. In terms of the let*, you are only binding port and server-process and you are not using either of them in subsequent let-bound statements -- as such, it would appear that just let is sufficient and do not need let*. In addition, you may be interested in trying lexical-let instead of let -- in that case, you may not need the backtick/comma.
    – lawlist
    Sep 9, 2019 at 20:37
  • 1
    FYI if I add (message "%S" (process-filter server-process)) to the end of that outermost let* form, I see the expected (closure ((server-process . #<process libbasecampel-oauth-http-server>) (port . 1234) t) (_process _data) (message "server-process: %s" server-process)). Do you see the same?
    – phils
    Sep 9, 2019 at 23:49
  • 1
    Have you perhaps written and evaluated this code in a buffer which does not have lexical-binding enabled? (Just adding the comment doesn't do anything if the comment doesn't get processed. Does the behaviour change if you re-load the file?)
    – phils
    Sep 9, 2019 at 23:58
  • 1
    FYI I've now tested it with process input, and with lexical-binding enabled your code works for me.
    – phils
    Sep 9, 2019 at 23:59
  • @phils: yes I do. The problem only appears in the filter function. Sep 10, 2019 at 7:21

1 Answer 1


In a private email, Christopher Wellons answered my question. The problem is that server-process is a special variable defined in server.el. Special variables are always dynamically bound. As a result, the filter closure doesn't close over the server-process variable. When the filter closure is evaluated, the server-process variable's value is the one from server.el, i.e., nil for me.

The fix is to use a different variable name.

  • 2
    I try to avoid local binding names with a dash for this reason.
    – clemera
    Sep 10, 2019 at 8:44
  • I was curious and there are three symbols without dashes you shouldn't use for local var names as well: obarray, debugger and noninteractive
    – clemera
    Sep 11, 2019 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.