I am essentially trying to build a list of strings, where each of those strings in turn are built by their own functions.

However, I get the following error when the code is evaluated:

Wrong type argument: stringp, nil

Here is the code:

(defun mode-line-segment-git-status ()
  "Build the git status mode-line segment."
  (let (branch-name '(substring-no-properties vc-mode 5)))
  (list "Branch: " 'branch-name))

(defvar mode-line-segments nil)
(defun add-mode-line-segment (segment)
  "Add a modeline segment to the modeline."
  (setq mode-line-segments (append mode-line-segments (funcall segment))))

(add-mode-line-segment 'mode-line-segment-git-status)

(setq-default mode-line-format mode-line-segments)

What am I doing wrong?

  • Your let in your first function a) should enclosed your let-bound variable in its own set of parentheses, and b) should not quote the function whose value you want to bind to the variable.
    – Dan
    Commented May 3, 2018 at 15:21

1 Answer 1


@Dan's comment is quite correct: you don't need to be quoting inside your let form, and also, you can't access let-bound variables outside the scope of the let form. (You might notice that Emacs lisp has a single global namespace for variables. let is how we encapsulate variables inside functions, keep them from leaking.)

More generally: the Wrong type argument is elisp's way of telling you, "I expected an x but got a y. stringp, nil means, "I expected something that satisfies the stringp predicate, but I received nil." You can get more information about where the error is happening by calling M-x toggle-debug-on-error, but "I'm handing a nil to something that needs a string` might be enough of a hint.

  • +1 for M-x toggle-debug-on-error. It's really handy when you have a way of reliably reproducing the error.
    – mindthief
    Commented Nov 22, 2020 at 3:36

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.