[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making a function than can only be used interactively
From: |
Tassilo Horn |
Subject: |
Re: Making a function than can only be used interactively |
Date: |
Sun, 03 Jul 2022 21:53:43 +0200 |
User-agent: |
mu4e 1.8.3; emacs 29.0.50 |
carlmarcos--- via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
>>> Is it possible to make an interactive function than can only be used
>>> interactively?
>>
>> I'm not sure I understand your question. A function, that may be
>> called interactively, is called a "command" in Emacs. And a command
>> can definitely be called interactively, either by using it's name
>> (using M-x) or binding it to a key.
>>
> I do not want people to use the function non-interactively.
How restrictive is that! :-)
--8<---------------cut here---------------start------------->8---
(defun only-interactive ()
(interactive)
(if (called-interactively-p 'interactive)
42
(error "You may not call me")))
(only-interactive)
;;=> Debugger entered--Lisp error: (error "You may not call me")
(call-interactively 'only-interactive)
;;=> 42
(cl-letf (((symbol-function 'called-interactively-p)
(lambda (&rest _args) t)))
(only-interactive))
;;=> 42
--8<---------------cut here---------------end--------------->8---
So as you see, there are many ways around it.
Bye,
Tassilo
- Making a function than can only be used interactively, carlmarcos, 2022/07/03
- Re: Making a function than can only be used interactively, Bruno Barbier, 2022/07/03
- Message not available
- Re: Making a function than can only be used interactively, Stefan Monnier, 2022/07/03
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/03
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/03
- Re: Making a function than can only be used interactively, Stefan Monnier, 2022/07/03
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/03
- Re: Making a function than can only be used interactively, Stefan Monnier, 2022/07/03
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/03