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

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

Re: Using called-interactively-p


From: Marcin Borkowski
Subject: Re: Using called-interactively-p
Date: Thu, 06 Jul 2023 20:55:05 +0200
User-agent: mu4e 1.1.0; emacs 30.0.50

On 2023-07-05, at 17:40, uzibalqa <uzibalqa@proton.me> wrote:

> ------- Original Message -------
> On Thursday, July 6th, 2023 at 3:25 AM, Marcin Borkowski <mbork@mbork.pl> 
> wrote:
>
>
>> On 2023-07-05, at 15:35, uzibalqa uzibalqa@proton.me wrote:
>> 
>> > I have the following function that executes the command (do-this) when
>> > the function skatpad is called interactively by the user, but executes
>> > (do-that) if the function is called from elisp code.
>> > 
>> > The documentation suggests to use "called-interactively-p" instead of
>> > (interactive-p).
>> > 
>> > Looking at the documentation, it is not quite clear whether KIND should be
>> > a symbol or a string. This problem of distinguishing between a symbol and
>> > a string, is something that occurs frequently in the documentation. A 
>> > source
>> > of constant deliberation for me.
>> 
>> 
>> I would definitely bet on symbol. Using strings for things like this
>> seems highly unusual for me (in Elisp, as opposed to e.g. JavaScript).
>> 
>> OTOH, you can check if you want to (do-this) or (do-that) using a simple
>> trick with an optional parameter -- see
>> https://www.gnu.org/software/emacs/manual/html_node/elisp/Distinguish-Interactive.html
>> 
>> Hth,
>
> The examples are much clearer.  But the documentation with the preference on 
> using
> single quotes is confounding.   As the documentation is for the most part 
> devoid
> of examples, distinctions should be made explicit. 

I agree - I was just saying that when in doubt, I would bet on symbols.
You're right that there are not very many examples in the docs.  OTOH,
you can always look at the source code, which more often than not is
enlightening.

For example, in the first few lines of `called-interactively-p' there is
this:

--8<---------------cut here---------------start------------->8---
(when (not (and (eq kind 'interactive)
... )))
--8<---------------cut here---------------end--------------->8---

which implies that indeed, `KIND' should be a symbol.  And you don't
even have to study the whole code -- just search for `kind' and see how
it is used.

Hth,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

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