From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Dimech Newsgroups: gmane.emacs.help Subject: Re: Making a function than can only be used interactively Date: Mon, 4 Jul 2022 23:59:49 +0200 Message-ID: References: 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="15424"; mail-complaints-to="usenet@ciao.gmane.io" Cc: tsdh@gnu.org, help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 05 00:01:35 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 1o8U8N-0003pe-Kh for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 05 Jul 2022 00:01:35 +0200 Original-Received: from localhost ([::1]:51152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o8U8M-0004Xb-11 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 04 Jul 2022 18:01:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8U6l-0004Q6-Se for help-gnu-emacs@gnu.org; Mon, 04 Jul 2022 17:59:55 -0400 Original-Received: from mout.gmx.net ([212.227.15.18]:51785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8U6j-0000jO-TB; Mon, 04 Jul 2022 17:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656971989; bh=nfEyM9efaM+Oef0dbcZ9j1xcTHuWyg8lDabiizflObo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=iyQQr89hND5hhHdNOCg5KLZZ7aoM4atp6K698ttA6oyskrPUhmMOoAQl6Gk41c8gL wQjF2VuTVugo5i+buu4/ttKFsASsAjt3mIWtx5P7CO/bWhfGAk6V2+pkSBNX6Db/33 Fl5FBzXRDQbHwWgdYkRnMwR244CSArbhCHnO8i/Y= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [92.251.127.164] ([92.251.127.164]) by web-mail.gmx.net (3c-app-mailcom-bs07.server.lan [172.19.170.175]) (via HTTP); Mon, 4 Jul 2022 23:59:49 +0200 Importance: normal Sensitivity: Normal In-Reply-To: X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:xwZLqEHIsXo8Kp84j8HhfZOVbKo7SRKb1X/2sYJ+VEIzYQGKYZxEItf3fWt+8r5arEFfP DEYY7Lk6xPnX1zjJ3iWUnAuuORxBQA9XG628EM1iV4g2hzlKZ2kSl1Skh7U62egQ9oZ3s3c9VNJp c/c7gpWwD8mISEUfFsTnBf+jTOSJIZVw3Rr8O4ThvKZS+TR56JZXqmdmRKystAzve/5o6v/htvTJ v/0ds9S8P7NIwkMRaH28Rkxk9lo1BscyDrrSSVSujPAppOxvKBIjrHJOEyOHKzt/4gnhf3hSsKwJ uo= X-UI-Out-Filterresults: notjunk:1;V03:K0:6cI8RUZwPsw=:Y0VTfPqDKBXQbZLvbPpuWI Uzf9tytuxQCE5dKzMBeS+85mrawHQg+ldvAQ3hDuLDaEm61kyfrjQFDbICvednVhlOtpzRRYz RZLiRJSO37oeVftUnAcOnsN1TsbF55cFxvRRax3WBYAqoh58GS4PHnjs2RhI+63kBjnHAk7KK XpCL6Zqfc2pZgIkMnyDVLk7AR1eNJowYrKBxxagS72syRruF1/LiOACZFtUeqaMBGbLuectXW s8x9aNJ/xkuVSCn73B2w8zOcSK65drEoTstTwOGvLNKnH3e6eQiRayTlrd1XgVci4jGqdXboX ovLV2hq8+RXdZLjaLw2QNHoTixNcNlmiYOXEwBnnXx8smJAIVntV4S/3HRrtSqDimmVoKmsLT t7wlX8YqNVCiWh46UY2zGCtP19wsneskAwsQC0ZewaeNUyxjXvna3T8sPaNScV8gARl0emuo4 twTusE2y9Pz4dHy8KPi61xrL9CTiAjX4yt0GwKo2fN4dqOULnY+7aXxFpA7JJ3Lml2COmD5To Bf7HM9JuMZUICjxJf7bkE2R9adPdAQukIYPeRPH+bkcK/bJObayrrLaNtBOUH2KePRQKB9Kh7 SWcK7bc7CN2U5tECMMUfKblXUNzFzK38z0lWHpQyE8ij5MdPbY52LmJ4gga3yCSyfHCMyjp6b Q47uu4Y9bTm91QdicglXM+DtVnnsaNUTsiLLK9dRlknNRrC2p4iUyl0aI34jTh+cmLBG5iOVA xSJ+S2dTF79Bzj92s12KqhMhmM1bjamJOm1ccAcGWpXncmpVatY5zlnoBx1p4iaGNoFcHL5b Received-SPF: pass client-ip=212.227.15.18; envelope-from=dimech@gmx.com; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:138304 Archived-At: > Sent: Tuesday, July 05, 2022 at 9:18 AM > From: "Stefan Monnier" > To: "Christopher Dimech" > Cc: tsdh@gnu.org, help-gnu-emacs@gnu.org > Subject: Re: Making a function than can only be used interactively > > > Another debate is that although one can declare a non-interactive func= tion, > > and an interactive function that can run non-interactively; there is n= o > > construct that can define a purely interactive function. > > That's because an "interactive function" is just a normal function > together with some auxiliary info to tell `call-interactive` how to call > it "interactively". Internally `call-interactively` will end up calling > the function via `funcall`, i.e. "non-interactively". So at > a low-level, technically you just can't have a function that can be > called interactively and not non-interactively. You can try and kludge > it up above if you really want to (like we've seen in a few different > ways), but we're back to the question: what's the benefit? Could be that the above is not fully understood. Reporting warnings when running a specific function non-interactively, when non-interactive call is not recommended, would be the way to go. But users have to program it that way. > > Does a function know whether it was run from lisp code or from the use= r in > > an Emacs session? > > Trying to behave differently depending on who/how a function was called > goes against the design principle of functions, so it tends to be kludgy > and unreliable, like `called-interactively-p`. Can't argue much with that. > BTW, here's another way to make a function that "can't" be called > non-interactively: > > (defun foo (a b c &optional extra) > (interactive > (list ... 'dont-you-dare-call-me-non-interactively)) > (unless (eql extra 'dont-you-dare-call-me-non-interactively) > (error "foo called non-interactively")) > ...) Something like that could be enough. Also a warning to warning buffer might help. > You can make it "more robust" with something like: > > (defalias 'foo > (let ((witness (make-symbol "dont-you-dare-call-me-non-interactive= ly"))) > (lambda (a b c &optional extra) > (interactive > (list ... witness)) > (unless (eql extra witness) > (error "foo called non-interactively")) > ...))) > > But again: is it really worth the trouble? What is there to gain? > Instead of beating the undesired callers with a stick, why not try and > convince them to do something else with carrot? > > Stefan You can gain an even bigger headache working with such code.