From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Delegating user-reserved key binding space definition to users Date: Sat, 26 Nov 2022 06:44:09 +0000 Message-ID: <877czikyfa.fsf@localhost> References: <57b69c22e167d429d21bb969feb22887@webmail.orcon.net.nz> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5011"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Psionic K , Emacs developers To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 26 07:44:39 2022 Return-path: Envelope-to: ged-emacs-devel@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 1oyovV-00014x-SZ for ged-emacs-devel@m.gmane-mx.org; Sat, 26 Nov 2022 07:44:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyoub-0002uW-1j; Sat, 26 Nov 2022 01:43:41 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyouX-0002uO-Fg for emacs-devel@gnu.org; Sat, 26 Nov 2022 01:43:39 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyouV-0000Ms-6E for emacs-devel@gnu.org; Sat, 26 Nov 2022 01:43:37 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 8FB5D240026 for ; Sat, 26 Nov 2022 07:43:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1669445012; bh=HoOyf3DAuEfuk0RViLgbZi3r3ide2aDsGQHSBXf/i/M=; h=From:To:Cc:Subject:Date:From; b=Fsuk8aegxJUN5B93yRlJeW2Lk3V2+QkxkN1xVZj4c578LqyeStpsuvGyjDPhkHemu 4oxiwX+VOF7UgJn0dQTn7Lqlht1Tv0xfMGjptkwynbePFuxiQ0x44K493OfNhUxwFp 2XuxgfKYAAgG22xAVLdqZfK7LW3NiZ1/DdpPF8pm82041PshvnA/zLbMtlR0/wQkHs EXGNLKpLa7ndKyRp5s2KogRsJSTxQgFVBorClE8IqNQFh6IIBaefEZpGsW72KhAPWP WvMutAqBcW24AvLAPivPSBaNBaKdnavPJOJZCjnhPjqKD2Mv9YfsLtJ208/beb/NXA GXm5Q5SciF2iw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NK2Hl0rKXz6tnx; Sat, 26 Nov 2022 07:43:30 +0100 (CET) In-Reply-To: Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300547 Archived-At: Stefan Monnier writes: >> The problem I'm working to reach is allowing packages to correctly shadow >> the user's bindings (and not incorrectly shadow) instead of ad-hoc >> imitation of the global map defaults. Ad-hoc imitation makes it very >> tedious to, for instance, change the key sequence for expressing "next" >> without losing coherence among all packages with a corresponding "next" >> concept. > > I don't think anyone doubts that it's desirable. > The question is how to get that. I suggest introducing a notion of "generalized" commands. Such commands will represent common actions executed by users (like move to next/previous element). Major and minor modes can then define specific implementation of the actions. In terms of OOP, I am talking about virtual methods and major/minor modes providing the implementations. The implementations will be chosen according to the current major mode or maybe some other condition. Default implementation (like `next-line') can also be provided. The generalized commands can then be freely re-bound by users with immediate effect on all the major modes. An example (not very clean) implementation of this concept is available at https://github.com/yantar92/meta-functions/blob/master/meta-functions.el: ; Quick implementation of meta-functions, which allows running multiple ;; functions, which do similar logical operations by one single "meta" ;; function in different major modes. For example, one may want to define ;; meta-next-line to call `next-line' normally, but ;; `org-agenda-next-line' in org-agenda mode. Both can be bound to, say ;; "M-j", without a need to change the key-bindings on both fundamental ;; and org-agenda modes. ;; Example usage: ;; (use-package meta-functions ;; :config ;; (meta-defun meta-next-element () ;; "Go to next element." ;; :mode org-agenda-mode (org-agenda-next-item 1) ; call org-agenda-next-item in org-agenda ;; :cond (lambda () (and (eq major-mode 'org-mode) (org-at-heading-p))) (org-next-visible-heading 1) ; call org-next-visible-headting when at heading in org-mode ;; (next-line)) ; call-next line in any other case ;; ) ;; or the same can be written as ;; (meta-defun meta-next-element "Go to next element." next-line) ;; (meta-defun meta-next-element :mode org-agenda-mode (org-agenda-next-item 1)) ;; (meta-defun meta-next-element :mode org-mode :cond org-at-heading-p (org-next-visible-heading 1)) ;; ;; Similar packages: ;; https://gitlab.com/jjzmajic/handle implements similar functionality to unify functions across major modes ;; However, handle is very major-mode centric. meta-functions is more function-centric ;; Also, meta-functions is not only limited to current major mode defining which function to call. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at