Why doesn't this work?

(defun load-browser (app)
    (interactive "sChoose Browser? ")
    (cond ((string= app '"c")
        (setq browse-url-generic-program "chromium")
        (setq browse-url-browser-function 'browse-url-generic))
    (message "Else case Typed %s" app)

It fails to work in the Else case where the input string/char is not "c".

  1. No need to quote a string: use "c" instead of '"c". Strings evaluate to themselves.

  2. You second cond clause is invalid. It is this: (message "Else case Typed %s" app). That tests the symbol message as a variable, and it is no doubt an undefined variable, which raises an error.

What you are probably trying to get is this as your second cond clause:

 (t (message "Else case Typed %s" app)) ; If not first clause, show message.

Read the doc about cond. And always use correct indentation. See C-h k C-M-q in Emacs-Lisp mode.

  • That should be C-h k C-M-q. I tried to edit it, but apparently edits have to be at least six characters. – jbm Feb 8 '14 at 3:04
  • @jbm: Right; thanks. Corrected C-h f to C-h k. – Drew Feb 8 '14 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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