From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to define a (derived) minor mode inaccessible to the user Date: Fri, 22 Jan 2021 10:38:15 -0500 Message-ID: References: <87eeidlfmw.fsf@mbork.pl> <875z3pknav.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18281"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 22 16:39:15 2021 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 1l2yWp-0004e3-BX for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 22 Jan 2021 16:39:15 +0100 Original-Received: from localhost ([::1]:36746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2yWo-0007dE-C0 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 22 Jan 2021 10:39:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2yW1-0007d0-10 for help-gnu-emacs@gnu.org; Fri, 22 Jan 2021 10:38:25 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:36753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2yVy-0004Ly-31 for help-gnu-emacs@gnu.org; Fri, 22 Jan 2021 10:38:24 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 3169C80241; Fri, 22 Jan 2021 10:38:18 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 8C7B68065D; Fri, 22 Jan 2021 10:38:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1611329896; bh=UO6EXN9DJnqR/9IiExyoq07OnHzvL6aKWcrdG9lGI1k=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Mwn/n+4Br4n1yySc6sAb3/F8eNT4mTlAH0s/hJXT3bPrbEKzkzkQnNG509uCM6K9k /WGiUvFZ2KtnDY+aKbJyeu7i7m0Hq5wFFRbw6q1ANhv4RhtXuza6rs7Q0EU9imJGQ6 B9VbHOC2qzl0GNhUEn6Zui6nImJ32Hl1hMbUhbY3qveQ6oDBwwtqEyhgaKospKvTS9 IBREw1pp2GUYNmScVYHVLvmLp1Fd9Z8a6Z+FjNydadO12mBC5/IcvxYCJlUh4vFsp5 gzaPaewIPwxzREibnEv/FqNnvYmyfs4esaHVvglGluPFMczQf6ChAOIHKsbYoKCL4U D76m/I0OVTfDA== Original-Received: from alfajor (65-110-220-188.cpe.pppoe.ca [65.110.220.188]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5F582120298; Fri, 22 Jan 2021 10:38:16 -0500 (EST) In-Reply-To: <875z3pknav.fsf@mbork.pl> (Marcin Borkowski's message of "Fri, 22 Jan 2021 16:23:52 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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:127320 Archived-At: >> The `interactive-form` property is virtually never used. Instead, the >> interactive form is traditionally stored within the function. > So how does `execute-extended-command' know what to list, then? You can use `commandp` to know if it's got an interactive form or not, and `interactive-form` (the function) to extract it from a function. > A cursory look told me that it uses `read-extended-command', which uses > `commandp'. So, how does `commandp' know? (I'm not well versed in C, > but do I guess correctly that it checks the `interactive-form' property, > and if nil, it (somehow) looks for `(interactive ...)' in its > definition?) Pretty much, yes (with the extra handling for the cases where the function is not a `(lambda ...)` list but a byte-compiled object, or an autoloaded function, or a function implemented in C). >> If you *really* care about hiding the major mode from the user >> I suggest you use an "obscure" or "scary" name. > Well, the convention is to use two dashes, but how can the end-user (not > knowing Elisp and the conventions) know that? That's indeed the convention for functions. For commands we don't really have a convention for "commands that should be hidden from `M-x". We used to prevent completion from revealing obsolete commands. It's been reverted recently (to my disappointment), but we could add a similar feature for "commands not to be used via M-x" (could be used for those commands that only work when bound to a mouse event, for example). Maybe `smex` offers something like that. When I rewrote `execute-extended-command' into Elisp, I hoped that it would encourage people to hack on it and add features to it (like this one), but sadly it doesn't seem to have had much effect of this kind so far. We could add some property that holds a predicate function which `execute-extended-command' could use to filter out commands which can't be used in the current context (e.g. the predicate could check the major mode, for those commands which only work in a given major mode). > So, basically you move the function definition from the function cell to > the value cell of `my-mode', right? Clever! Is it actually used > anywhere in Emacs? No, and I don't recommend it. E.g `C-h m` will then fail to show the proper docstring of the major mode. Stefan