help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using show-paren-style function in elisp code


From: carlmarcos
Subject: Re: Using show-paren-style function in elisp code
Date: Tue, 21 Jun 2022 06:58:33 +0200 (CEST)


Jun 20, 2022, 17:51 by brubar.cs@gmail.com:

> carlmarcos--- via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
>> Have written the following function to set `show-paren-style`.  Would it be 
>> possible to modify
>> the code in a way that also allows a user to use the style as an argument so 
>> that the function 
>> can be used in elisp code.  
>>
>
> I would follow Rudolf's advice, to not have to set the style manually
> everytime.
>
> But, if you still want to learn how to use a function both
> interactively and in elisp code, you should read the Elisp
> documentation about 'interactive'. It explains how to write functions
> that you can use as commands.
>
>  (info "(elisp)Using Interactive")
>
>  
> In your case, here is a possible solution:
>
>  #+begin_src elisp
>  (defun 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)
>  )
>  #+end_src
>
>
Cheers Bruno,  I wonder how the symbol provided by intern is taken up by the 
variable `style`.


>  
> Note 1: The function 'intern' transforms a string into a symbol; you then 
> don't need a 'pcase' anymore.
>
> Note 2: Your line:
>
>  (setq 'show-paren-style 'parenthesis)
>  
> should have been:
>  
>  (setq show-paren-style 'parenthesis)
>  
> as 'setq' expects a non-quoted symbol.
>
> Bruno
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]