0

Would like to have an interactive function that enables or disables two features (either auto-complete or company). Is this how I can use the interactive clause to pass two function arguments? I get confused because customarily, let returns only one thing, the result of the last command.

(defun complt (featr actm)
  "Enable or disable text completion."

  (interactive
   (list
    (let* ( (cseq '("acomplt" "company"))
            (cftr (completing-read "Featr: " cseq nil t "company"))
            (csel (completing-read "Actm: " 
                     '("disable" "enable") nil t "enable")) )
    cftr 
    csel))) 

  (message "DO THIS") 
  (message "DO THAT"))

2 Answers 2

0

Indeed let returns a single value, while for passing two values via 'interactive' you would like to pass a list containing two elements/values,

therefore, just place the list inside the let as follows to get what you want:

(defun complt (featr actm)
  "Enable or disable text completion."

  (interactive
    (let* ( (cseq '("acomplt" "company"))
            (cftr (completing-read "Featr: " cseq nil t "company"))
            (csel (completing-read "Actm: "
                                   '("disable" "enable") nil t "enable")) )
      (list cftr csel)))

  (message "DO THIS")
  (message "DO THAT"))
0

Yes, you have confused these two things: (list (form a b)) and (form (list a b)).

I think a simpler way to write this avoids let entirely:

(defun complt (featr actm)
  "Enable or disable text completion."

  (interactive
   (list
    (completing-read "Featr: " '("acomplt" "company") nil t "company")
    (completing-read "Actm: " '("disable" "enable") nil t "enable")))

  (message "DO THIS")
  (message "DO THAT"))

Here is another version using let:

(defun complt (featr actm)
  "Enable or disable text completion."

  (interactive
   (list
    (let ((choices '("acomplt" "company"))
          (completing-read "Featr: " choices nil t "company")))
    (let ((choices '("disable" "enable"))
          (completing-read "Actm: " choices nil t "enable")))))

  (message "DO THIS")
  (message "DO THAT"))

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.