Why isn't elisp nil the empty string?

Table of Contents

Sometimes in emacs nil is not punned well enough. I found this when using Telephone Line, when the crucial problem is that nil can’t be construed as a string (why isn’t it the empty string when strings are wanted?).

Error during redisplay: (eval (telephone-line-add-subseparators ‘((lambda (face) (telephone-line-raw (if (telephone-line-selected-window-active) (progn (propertize battery-mode-line-string ‘mouse-face ‘(:box 1))))))) telephone-line-cubed-hollow-left ‘evil)) signaled (wrong-type-argument stringp nil) [36 times]

I fixed this manually with some extra code, when writing such cruft feels like a slight against lisps:

(telephone-line-defsegment telephone-line-battery-segment ()
  (if (and (telephone-line-selected-window-active)
           battery-mode-line-string)
    (propertize battery-mode-line-string
                'mouse-face '(:box 1))
    ""))

Notice the value of battery-mode-line-string may be nil, like when I have a limit to the percentages at which it should display, and this was causing lots of errors about (stringp nil) that cluttered my error messages on every buffer change.

Resources

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist