unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Bruno Barbier <brubar.cs@gmail.com>
To: carlmarcos@tutanota.com, Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Using show-paren-style function in elisp code
Date: Mon, 20 Jun 2022 19:51:06 +0200	[thread overview]
Message-ID: <E1o3LX5-0008Ee-It@lists.gnu.org> (raw)
In-Reply-To: <N5-79NL--3-2@tutanota.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


    
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




  parent reply	other threads:[~2022-06-20 17:51 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 [this message]
     [not found] ` <N51E0wj--3-2@missing-mail-id>
2022-06-21  4:58   ` carlmarcos--- via Users list for the GNU Emacs text editor

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=E1o3LX5-0008Ee-It@lists.gnu.org \
    --to=brubar.cs@gmail.com \
    --cc=carlmarcos@tutanota.com \
    --cc=help-gnu-emacs@gnu.org \
    /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).