I have the following condition to set mbcomplt according to the symbol stored in armg. Is there a more convenient way (e.g a shorter way of setting mbcomplt) to set the numeric value for mbcomplt associated with symbol.

  (defvar armgv 0)
  (defvar cia '(norm norm))

  (defun mbcomplt-authentis (cookie)

   (let ( (armg (car cookie))
          (seqr (car (cdr cookie))) )
      ((eq armg 'auto)
          (setq mbcomplt 0))
      ((eq armg 'icomplt-horz)
          (setq mbcomplt 1))
      ((eq armg 'icomplt-vert)
          (setq mbcomplt 2))
      ((eq armg 'ivy)
          (setq mbcomplt 3))
      ((eq armg 'vertico)
          (setq mbcomplt 4))
      ((eq armg 'helm)
          (setq mbcomplt 5)))))
  • When posting code, please make an effort to ensure that it is syntactically correct. Commented Oct 30, 2022 at 9:28

1 Answer 1


Your code sets mbcomplt to a number 1 to 5 depending on the value of the variable armg (which is supposed to be a symbol like 'ivy). A more efficient way to do the same thing is this:

    (setq mbcomplt
      (cl-case armg
        ('auto 0)
        ('icomplt-horz 1)
        ('icomplt-vert 2)
        ('ivy 3)
        ('vertico 4)
        ('helm 5)))

You can do something similar with cond: the point is that conditionals in lisp are expressions that return a value.

  • Would you be kind enough to explain on use of symbols and values? Here you set mbcomplt, but need assistance on the meaning of the rest and how to use them.
    – Dilna
    Commented Oct 30, 2022 at 9:32
  • I don't know what you are asking here. Are you asking how cl-case works? (If so, do C-h f cl-case). Or are you asking how evaluation works in emacs-lisp, in which case you should read an introduction to emacs-lisp ( C-h R eintr). Commented Oct 30, 2022 at 9:41
  • Am asking how I would be using your construct. If I want to set mbcomplt to symbol auto with value 0, what would I do. I would then have to check whether an argument passed to a function is auto and then use it value, according to value, then do something.
    – Dilna
    Commented Oct 30, 2022 at 10:02
  • How can I set a symbol and set a value to it?
    – Dilna
    Commented Oct 30, 2022 at 10:04
  • I am not sure you understand what your original code does. I have edited my answer to make things a bit clearer. However, I have no idea what you mean by "How can I set a symbol and set a value to it?" Commented Oct 30, 2022 at 10:31

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.