From: carlmarcos--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: Bruno Barbier <brubar.cs@gmail.com>
Cc: Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Using show-paren-style function in elisp code
Date: Tue, 21 Jun 2022 06:58:33 +0200 (CEST) [thread overview]
Message-ID: <N53c58F--3-2@tutanota.com> (raw)
In-Reply-To: <N51E0wj--3-2@missing-mail-id>
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
>
prev parent reply other threads:[~2022-06-21 4:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-20 8:00 Using show-paren-style function in elisp code carlmarcos--- via Users list for the GNU Emacs text editor
2022-06-20 9:25 ` Rudolf Schlatte
2022-06-20 17:51 ` Bruno Barbier
[not found] ` <N51E0wj--3-2@missing-mail-id>
2022-06-21 4:58 ` carlmarcos--- via Users list for the GNU Emacs text editor [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=N53c58F--3-2@tutanota.com \
--to=help-gnu-emacs@gnu.org \
--cc=brubar.cs@gmail.com \
--cc=carlmarcos@tutanota.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).