From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: How to define a prefixed map for a minor mode? Date: Sun, 07 Jun 2020 12:18:04 +0200 Message-ID: <87pnab5gdf.fsf@fastmail.fm> References: <87h7vnmks7.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="8095"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.6; emacs 27.0.91 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 Sun Jun 07 12:18:31 2020 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 1jhsNr-0001zw-GX for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 07 Jun 2020 12:18:31 +0200 Original-Received: from localhost ([::1]:52786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhsNq-0003NH-Ki for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 07 Jun 2020 06:18:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhsNX-0003M8-Lt for help-gnu-emacs@gnu.org; Sun, 07 Jun 2020 06:18:11 -0400 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:35137) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhsNW-0004KY-M5 for help-gnu-emacs@gnu.org; Sun, 07 Jun 2020 06:18:11 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 878755C00B7; Sun, 7 Jun 2020 06:18:08 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 07 Jun 2020 06:18:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; s=fm3; bh=pT1b9C5dbb8syX5vhK1aTyjAmo wf0M1zrKw9xPrdJAI=; b=mTiLnQCVq4MxnmXmIGbz9oWy/4RXtrXfOPX3ZF6hLz ZKwc+8kSHqY2Rg5whRfdBA6DtuxvnJRjtrzt5v60B6V26akAcVpTgN+V0lOvoLFn MZb2WmvJ+GCHk0nAKi6CNGPNX8PsXJCjEh8RdB5H2ZTaXrRTfh0vQEhb8/9TWXaz YFPu/scEuSl/KEQCMrI95olPSF0eLRvtnjCmQDo8fCYrXCZxmpymKwJbA2NLtxWC bsed7u1to2brjx99AfDJJ5ns+Q4BQX/kNM2/w+2ydT3V3emOJIV1ka9GpNoQnam/ 6FVw9CuDbWU0JnJLT1YkAc0ougsNQN1mNLXVI4SVeYMQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=pT1b9C 5dbb8syX5vhK1aTyjAmowf0M1zrKw9xPrdJAI=; b=luHJm2EUYraNtfsrK0CWW6 OfpmSXHT5SGy1jX+tbRlDLgiXgOrKBGh0tJ11uyfqKWjIMOz5hrON+9MfWCqgUJc 3Qe7a3YIF48/ucMGmodrZ90oIExN/EhdUa/Iyzzr/Zk/ZcZ7FpYM1XQGhYwu56lp sE50Q5ctSFufA9Xu1VBd1c7XDrTi3hn35tqQahscW0fo6UtFfSedyCX9JXOHSezZ yZXZ6Kn7ZiawkTi8BBfrj25gsiEMyo/3gQid26N16W640Cg8w1OyUtPgtW4NgCe6 MEPq+8uk/4oNOpCRVyM21e1EQSP2JIfHwIIiciAE0ZWkVcU+WCb/+XhLq8Nigbhw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudegledgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvufgjfffkgggtsehttdertddtredtnecuhfhrohhmpeflohhoshht ucfmrhgvmhgvrhhsuceojhhoohhsthhkrhgvmhgvrhhssehfrghsthhmrghilhdrfhhmqe enucggtffrrghtthgvrhhnpefhudffuefhudelhffgleeukeegudevtedtudduhfefteeu gedvvedtuddugffffeenucfkphepleehrdeltddrvddtuddriedvnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhoohhsthhkrhgvmhgvrhhs sehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: from Swift.fastmail.com (ip5f5ac93e.dynamic.kabel-deutschland.de [95.90.201.62]) by mail.messagingengine.com (Postfix) with ESMTPA id AC1E33061856; Sun, 7 Jun 2020 06:18:06 -0400 (EDT) In-reply-to: <87h7vnmks7.fsf@mbork.pl> Received-SPF: pass client-ip=66.111.4.27; envelope-from=joostkremers@fastmail.fm; helo=out3-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/07 06:18:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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:123263 Archived-At: On Sun, Jun 07 2020, Marcin Borkowski wrote: > Hi all, > > continuing my work on a (simplistic) Emacs CAT, I want to define > a minor > mode. However, I'm stuck on defining its keymap. I want all > the > commands prefixed by e.g. `C-c .', and here's what I have: > > --8<---------------cut > here---------------start------------->8--- > (setq ecat-basic-map (make-sparse-keymap)) > > (define-key ecat-basic-map (kbd "p") > #'ecat-highlight-previous-sentence) > (define-key ecat-basic-map (kbd "n") > #'ecat-highlight-next-sentence) > (define-key ecat-basic-map (kbd ".") > #'ecat-highlight-this-sentence) > > (easy-mmode-defmap ecat-mode-map > `(((kbd "C-c .") . ecat-basic-map)) > "Keymap for `ecat-mode'.") > > (define-minor-mode ecat-mode > "Toggle Emacs CAT mode." > :lighter " CAT" > :keymap ecat-mode-map > (if ecat-mode > (ecat-highlight-this-sentence) > (delete-overlay ecat-sentence-overlay))) > --8<---------------cut > here---------------end--------------->8--- > > Alas, this does not seem to work - after pressing `C-c .' (when > the mode > is one!) I get "C-c . is undefined". > > What am I doing wrong? Is there a "canonical" method of > defining > a minor mode whose bindings start with some prefix? > > TIA, In one package of mine, I do this: ``` (eval-and-compile (define-prefix-command 'ebib-slave-map) (suppress-keymap 'ebib-slave-map 'no-digits) (define-key ebib-slave-map "c" #'ebib-slave-create-slave) (define-key ebib-slave-map "a" #'ebib-slave-add-entry) (define-key ebib-slave-map "d" #'ebib-slave-delete-entry) (define-key ebib-slave-map "m" #'ebib-slave-switch-to-master)) ``` and in the major mode's map: ``` (defvar ebib-index-mode-map (let ((map (make-keymap))) (suppress-keymap map 'no-digits) ;; [...] (define-key map "M" 'ebib-slave-map) ;; [...] map) "Keymap for the ebib index buffer.") ``` I'm not sure if that's what you're looking for, though, because `ebib-slave-map` isn't tied to a minor mode. But perhaps you can adapt it to your needs. -- Joost Kremers Life has its moments