From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Making a function than can only be used interactively Date: Mon, 04 Jul 2022 06:51:46 +0200 Message-ID: <8735fhlbee.fsf@gnu.org> References: <87v8sekls5.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29658"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.3; emacs 29.0.50 Cc: Bruno Barbier , help-gnu-emacs@gnu.org To: carlmarcos@tutanota.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 04 07:02:50 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o8EET-0007bi-AD for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 04 Jul 2022 07:02:49 +0200 Original-Received: from localhost ([::1]:49144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o8EER-0007JI-Qg for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 04 Jul 2022 01:02:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8ECz-0007J7-VB for help-gnu-emacs@gnu.org; Mon, 04 Jul 2022 01:01:18 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:47664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8ECy-0007k5-IP; Mon, 04 Jul 2022 01:01:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:To:From: References; bh=jY5wIdKaHyPZobvhBOhf+lkkDBL/hDFWbSe51zYTwo4=; b=Ky5kMDGUR/ehL8 F56BRntDT4Mfa40rsMhm5N9T1sH5jhp7jCT386MOnVKgkxSh1F1kXFFBKXFWDMY3iFs+HJcQwBbLn X14RQW7t3m+gZzNWdI6KKO/BexQC4Kj1eltl6Ds7whiQ2mNXPyfE5prouGfthHzgqDxdpwBrxTXoO bMX9thLGX+6ldM18bQFLhwO7E90mQ6DYrg5NWsdg1TtZ9FNrK4k2ric3G7bmvsYjKjFzYvjUUoaVr C6Ak1F9der6EVUk7DhVu6BYkstNrK4lY7q0fa/I7EERkJOVhEFS4/Mpy2MY9HsEYdHtZZJwIcZuMx aswbsv1362C7qBJlVltA==; Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:50627) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o8ECj-0000hv-RF; Mon, 04 Jul 2022 01:01:02 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 453C127C0054; Mon, 4 Jul 2022 01:01:01 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 04 Jul 2022 01:01:01 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudehkedgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpehffgfhvfevufffjgfkgggtgfesth hqredttderjeenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhsughhsehgnhhu rdhorhhgqeenucggtffrrghtthgvrhhnpefgtedtudeivdfhfffhfefhvefhuedvheejje efleffheekffeutdfhgfejiefhgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehthhhorhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlh hithihqdekieejfeekjeekgedqieefhedvleekqdhtshguhheppehgnhhurdhorhhgsehf rghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Jul 2022 01:01:00 -0400 (EDT) In-reply-to: X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138285 Archived-At: carlmarcos--- via Users list for the GNU Emacs text editor writes: >>> 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) >> ;;=3D> Debugger entered--Lisp error: (error "You may not call me") >> > > Focusing on the former two `(if (called-interactively-p 'interactive)` and > `(only-interactive)`.=C2=A0 I would need some meatier examples.=C2=A0=20 > > Using `(if (called-interactively-p 'interactive)`, would I need to put > the entire implementations inside the if `statement`? Yes, the 42 would become a (progn ...). Or just do (interactive) (unless (called-interactively-p 'interactive) (error "You may not call me from lisp")) at the beginning of the defun followed by your "normal" code. But please have a look at the docs for called-interactively-p which explain why it's usually a bad idea, e.g., my only-interactive will for example also signal an error when used in a keyboard macro. And as my examples pointed out, it's easy to circumvent your restriction. The conventional recommended way to do what you want is to just document in your commands docstring that it's not meant to be called from lisp using a `(declare interactive-only)' spec. Have a look at the docstring and source code for `next-line' as an example. HTH, Tassilo