0

I am trying to understand the use of the interactive and the intern commands so I can use a function both within an interactive context and an elisp context.

Require some explanation of how intern is setting up the variable style for use with the (setq show-paren-style style) command.

How would one call the function in elisp code?

(defun richerenkov-view-parens (style)
  "Visualise parentheses and expressions using STYLE.
STYLE must be a symbol."
  (interactive
   (list
    (intern (completing-read "Visualise: "
       '("bracemk" "expression" "mixed") nil t "mixed"))))
  (setq show-paren-style style))

1 Answer 1

1

(intern "bracemk") returns the canonical symbol bracemk the same as you would get from using 'bracemk.

Hence: (richerenkov-view-parens 'bracemk)

Note also the docstring: "STYLE must be a symbol" -- so you know in advance that you need to pass a symbol as the argument.

Refer to M-x elisp-index-search RET intern RET

3
  • Right. In brief, intern is only used when using the function interactively, to change the word into a symbol. When the function in used in elisp code (where the function is not called interactively) one uses the symbol immediately that is passed directly to show-paren-style.
    – Dilna
    Commented Jun 21, 2022 at 7:11
  • Yes, exactly so.
    – phils
    Commented Jun 21, 2022 at 7:24
  • Great. Looks like completing-read inside the interactive expression should match the arguments to the function.
    – Dilna
    Commented Jun 21, 2022 at 7:30

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.