0

I want a function designed to accept two completing-read calls, one to set nstruc that holds either "Glyph" or "Command", and actm that holds either "alpha α" or "beta β".

The two variables are then intended to be used inside the body of the function, within the pcase construct shown.

(defun greek (actm)
  "TODO"

  (interactive
   (list
    (let ( nstruc 
           (csel '("Glyph" "Command") )   
           (cseq '("alpha α" "beta β")) )
      (setq nstruc (completing-read "Instruc: " csel nil t nil))
      (completing-read "Letter: " cseq nil t nil) )))

  (pcase actm
    ("alpha α" (insert "\\alpha"))
    ("beta β"  (insert "\\beta")) )

Perhaps I do not need to put the completing-read calls in the interactive clause, but in the body of the function.

(defun my-custom-function ()
  (interactive)
  (let ((first-choice (completing-read "Enter your first choice: "))
        (second-choice (completing-read "Enter your second choice: ")))
    (message "First choice: %s, Second choice: %s" first-choice second-choice)))

When you use this function, Emacs will prompt you to enter two choices, and it will display the entered choices in the message area.

6
  • Is your question how to design a function that fits your description? Or is your question something specific about the code you show? The latter would bit this Q&A site, but the specific question is missing. The former would be too abstract. Either way, missing detail.
    – Drew
    Aug 15 at 1:28
  • Why is it important to enter either \alpha or α ? What problem will this code solve for you? There may be packages out there that already solve your problem. For instance, see this answer: tex.stackexchange.com/a/688137/1299
    – Trevoke
    Aug 15 at 2:54
  • @Trevoke Because that is what I want the function to do. Do you have an elisp solution to my function that works, or do you not ?
    – user41249
    Aug 15 at 3:10
  • I guess OP wants to ask what is the difference between (interactive ... completing-read ...) and (interactive) ... (completing-read ...).
    – shynur
    Aug 15 at 4:51
  • @Mahavir "because that is what I want the function to do" is a non-answer. We're here to solve people's problems, not to do people's homework. Real-world problems have context, homework problems do not.
    – Trevoke
    Aug 15 at 11:37

1 Answer 1

0

The question is on how to make the variable nstruc available for use in the pcase part.

You can't. nstruc only exists within the scope of your interactive form.

If your function needs a value from interactive it should be a part of the list of function arguments being returned by interactive, so that you can get it from there.

Change your function to accept two arguments and you could make this trivial adjustment:

(interactive
 (let (nstruc
       (csel '("Glyph" "Command"))
       (cseq '("alpha α" "beta β")))
   (list
    (setq nstruc (completing-read "Instruc: " csel nil t nil))
    (completing-read "Letter: " cseq nil t nil))))

Or without the nstruc redundancy:

(interactive
 (let ((csel '("Glyph" "Command"))
       (cseq '("alpha α" "beta β")))
   (list
    (completing-read "Instruc: " csel nil t nil)
    (completing-read "Letter: " cseq nil t nil))))
0