From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vladimir Nikishkin Newsgroups: gmane.emacs.devel Subject: Re: Fwd: A TAB operation reform question. Date: Tue, 11 Oct 2022 20:59:17 +0800 Message-ID: <878rlmsdrp.fsf@laptop.lockywolf.net> References: <87tu4blmf0.fsf@laptop.lockywolf.net> <87mta3krsg.fsf@laptop.lockywolf.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7692"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.6; emacs 29.0.50 Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Oct 11 17:34:18 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 1oiHGr-0001cQ-PO for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Oct 2022 17:34:17 +0200 Original-Received: from localhost ([::1]:54404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiHGq-0000mM-HZ for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Oct 2022 11:34:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiF8K-00078u-T4 for emacs-devel@gnu.org; Tue, 11 Oct 2022 09:17:20 -0400 Original-Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:33548) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiF8H-00045N-Mf for emacs-devel@gnu.org; Tue, 11 Oct 2022 09:17:20 -0400 Original-Received: by mail-ej1-x62d.google.com with SMTP id q9so26778393ejd.0 for ; Tue, 11 Oct 2022 06:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=/wUs1Hz7F6LkK+NRFdfW9bmzrtdwakyycIQk8fHHCFY=; b=ki2ahatiW6evNburekPtWtVRQ/rCnLhQiyIhS9PDdE5bTrWyKAaTFOJ9opQF/8G4Dw z9bo8qQ6rtF7Pwh6RLnmMPNWF+O+6Z1J8L64E1YhlsdKQSP4bSPmlCny3ifwdW2DxWyY 1DUIew4Dvpnl8v3ymvQ9YJIMDnYKHpPnFndYX5qIBNR6/AGVJchyt9l9fi8/DirtBXHE x6ynVhF/EpJ5Fc3vOEaY4BZq0S2Oodi7EFZBoGqQnxoLKDPvFh8K5O6k+LbtLH6HLpEg wE2KU48O+yjZlbE7uyXmHkKGnTTshPcRNuqe3WNqFdQ7rlc3g1NuKUmmtuYzYcEI1g2q WqZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/wUs1Hz7F6LkK+NRFdfW9bmzrtdwakyycIQk8fHHCFY=; b=ae83mtxsmqy6JZAMR1nLwUgZ8URaA+ZJ/LgtHK8YgjYSiGHXTiB7IMmbByIpxvnGPs nzqj0b9GkjMtiiVLxprT4HYwZlvtjPy5Yamgu8L1gAwK36ownUUhc/phQp4/vet2Q70H KN0koAr1+NfNAiyajUt0q6Hf6Sr9ETDQunNuXRyp9ZMjNeySf1CAgrJ3Ka0ZIM5nP45J EhlyPf+tDQGufubxLzwIsODC5jX0vh3iQV7cW+0PpmDoQ8A7JPonWN8Zkt5hxFTlItG3 wF93KpVNIL2kdf5d22HXLK6Fv0b2NoD+bWYzcFqIa2RVTQGTQLK+VVV9o4cRgQXnmVPw NeUg== X-Gm-Message-State: ACrzQf2cY/ev5TvZAjniXOb15HSLyDlfERrLY6WiuJ5GFTsiDV9CHe/8 8jtrpzSMTn0azz3FEbVxtMVdzbmy7E/yIoA4 X-Google-Smtp-Source: AMsMyM7Pj/Hbq2WivAfRinMSWcyko7hY/LIRF/rlggPr/nH6odpCzSw54Do4kVJa3J/gxOAE+NpDtw== X-Received: by 2002:a17:906:ee8e:b0:730:4a24:f311 with SMTP id wt14-20020a170906ee8e00b007304a24f311mr19157767ejb.420.1665494230746; Tue, 11 Oct 2022 06:17:10 -0700 (PDT) Original-Received: from laptop.lockywolf.net ([240e:36f:d5d:98b0:19b2:38e5:b967:a40]) by smtp.gmail.com with ESMTPSA id s14-20020a056402036e00b004582a37889csm9096353edw.16.2022.10.11.06.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 06:17:10 -0700 (PDT) In-reply-to: Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=lockywolf@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 11 Oct 2022 11:30:33 -0400 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" Xref: news.gmane.io gmane.emacs.devel:297493 Archived-At: This is more or less what I would like to suggest, except I am not particularly sure that advising is the way to go with this issue. I think that a customizable "hook-list" would be a cleaner option. Splitting `indent-for-tab-command' into separate functions would make sense anyway, even if a "dwim" infrastructure does not end up eventually adopted. Regarding prior research, the Emacs Wiki seems to be listing just two options for customizing TAB behaviour: smart-tab (available on melpa), and "tabkey2", not available on melpa. http://bazaar.launchpad.net/~nxhtml/nxhtml/main/view/head:/util/tabkey2.el Looking at tabkey2, it seems that it is mostly written with the same thoughts in mind, and it is problematic in the exactly the way mentioned above: since it is not providing a "hook" (loosely speaking) for other packages to connect to (due to being a standalone package), it has to accommodate as many modes as possible by itself. (See `tabkey2-company-backends' and `tabkey2-completion-functions') Stefan Monnier writes: > I agree there's a problem that needs fixing. > > TAB should be bound to a "DWIM" command which major modes should be able > to tweak and override any way they want, which basically means that this > command should do little more than run some kind of hook. > > Maybe we should split the code of `indent-for-tab-command` into a few > separate functions, each one implementing a particular functionality > (one for indent, one for completion, one for inserting a TAB, one for > indent region, IIRC), and then recombine them into the original > functionality by compositing them with `add-function`. > > The idea would be that major/minor modes would not (re)bind TAB any more > but would `add-function` to a new `tab-dwim-function` instead. > > End-users would then be able to rebind TAB for their own use without > having to fight with all the major/minor modes doing their own > rebindings of TAB. Of course, they'd also have the option of adding > their own functionality to that new `tab-dwim-function`. > > > Stefan > > > Vladimir Nikishkin [2022-10-11 10:37:06] wrote: > >> I am sorry for "forwarding" an email, but I initially thought that >> "help-gnu-emacs" would be more appropriate. >> >> But still, I would like to ask what Emacs developers think about this >> issue. Would it be possible to repurpose TAB from "sometimes TAB, >> sometimes indent, sometimes complete", to a more general-purpose dwim >> framework? >> >> Vladimir Nikishkin writes: >> >>> Hello, Emacs users and developers >>> >>> I would like to ask if a reform to the way TAB (C-i) works has been >>> considered? And if "yes", then how hard would it be to implement it? >>> >>> The motivation is the following: >>> >>> The way TAB works at the moment is peculiar. >>> >>> There is this "indent-for-tab-command", which either indents, or inserts >>> a tab-character, or completes... unless "tab-always-indent" is set to >>> some special value, but there are mode-specific >>> modename-tab-always-indent, but they are also sometimes ignored. Also, >>> org-mode overrides it with "org-cycle", and perhaps, other modes do too. >>> Also, "tab" is considered to be "the place somehow close to completion >>> functions", so M-C-i==M-TAB is "ispell-complete-word", and a lot of >>> other packages try to make their completion somehow close to TAB. >>> >>> This looks a bit like a mess, partly because TAB is almost universally >>> seen as a "dwim" entry point, but it is not officially so in Emacs. >>> >>> Could there be an alternative protocol? Could TAB be make a DWIM entry >>> point "officially"? >>> >>> In particular, could it be possible to make a "hard-switch" variable >>> "tab-always-inserts-tab", which would be the opposite of >>> "tab-always-indent", but simpler, and it would be possible to override >>> it in the major modes, thus making "c-tab-always-indent" unnecessary. >>> >>> If tab-always-inserts-tab is set to nil, TAB (for example) would be >>> looking in some customizable list of functions, say >>> "tab-dwim-list-functions", and run each function until some does not >>> return non-nil. The default list could be something like >>> (indent-if-possible indent-comment-if-possible hs-fold-if-possible >>> complete-if-possible insert-tab). >>> Using TAB with a prefix-argument would always insert a TAB. (which would >>> be an exception to the rule "default prefix argument is 4", but I think >>> it would be understandable.). >>> >>> This way, instead of rebinding tab to org-cycle, org-mode could prepend >>> "org-cycle" to this list, or make it the only member of the list, but >>> this would still allow the users to plug in custom dwim functions >>> further into the list, such as ispell-word (not completion), jump >>> between table cells, and such. -- Your sincerely, Vladimir Nikishkin (MiEr, lockywolf) (Laptop)