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 May 3 '18 at 15:21

@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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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