From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#68246: 30.0.50; Add non-TS mode as extra parent of TS modes Date: Wed, 17 Jan 2024 10:20:34 +0000 Message-ID: References: <83a5phskd5.fsf@gnu.org> <83h6joqz0t.fsf@gnu.org> <834jfoq86m.fsf@gnu.org> <831qarrbjx.fsf@gnu.org> <87a5p84nlh.fsf@gmail.com> <83edekfldq.fsf@gnu.org> <4105c743-45d0-48a0-a8bb-1ab457b9a256@gutov.dev> 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="2457"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 68246@debbugs.gnu.org, Eli Zaretskii , casouri@gmail.com, Stefan Kangas , monnier@iro.umontreal.ca To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 17 11:21:14 2024 Return-path: Envelope-to: geb-bug-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 1rQ32n-0000SJ-VX for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 17 Jan 2024 11:21:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ32e-0006uV-1X; Wed, 17 Jan 2024 05:21:04 -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 1rQ32c-0006uE-4Y for bug-gnu-emacs@gnu.org; Wed, 17 Jan 2024 05:21:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rQ32b-000126-Mb for bug-gnu-emacs@gnu.org; Wed, 17 Jan 2024 05:21:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rQ32c-0001Aj-9y for bug-gnu-emacs@gnu.org; Wed, 17 Jan 2024 05:21:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Jan 2024 10:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68246 X-GNU-PR-Package: emacs Original-Received: via spool by 68246-submit@debbugs.gnu.org id=B68246.17054868564486 (code B ref 68246); Wed, 17 Jan 2024 10:21:02 +0000 Original-Received: (at 68246) by debbugs.gnu.org; 17 Jan 2024 10:20:56 +0000 Original-Received: from localhost ([127.0.0.1]:50884 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rQ32V-0001AH-OF for submit@debbugs.gnu.org; Wed, 17 Jan 2024 05:20:56 -0500 Original-Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]:43484) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rQ32T-0001A4-Oj for 68246@debbugs.gnu.org; Wed, 17 Jan 2024 05:20:54 -0500 Original-Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2cd04078ebeso110574671fa.1 for <68246@debbugs.gnu.org>; Wed, 17 Jan 2024 02:20:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705486847; x=1706091647; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Qs/Rs1n5qQ7STKKy0IdALoVEvJaWV58iZEJRKqAmAE0=; b=JDREzb5lJDS+DTjkZW1hXL7u5N7SVKgqo3rOIwspwry/NmX3XlF6P43naUeoQW2wl2 XO7/RNx8JQD2aHOe1lHUZfOUO6SD/Oorzjs8XNLyUD9V1cU/3zG6psn5Wh2wEVgPfs6Y qitg9TaXT2uppAD2Lp6FZOlGoLNyVCP8VMJWLqsNOj873AY5S76nTxKJ/KL0munodg0M 5rrE2ffANmycadBkQMKtmL+3bXDshkTKSyQZ+3vGCIfgHLwxGdJpBYALSbP/ZypvB/yB ImuxoAv8Lo3T0riz0ShTCO++THjfexS5Mk+k6Z4MQFOxyiwjCMz/KhQTIFlL1umXG60m x3QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705486847; x=1706091647; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qs/Rs1n5qQ7STKKy0IdALoVEvJaWV58iZEJRKqAmAE0=; b=Wknqjo2wWvSLMNwJ44UWUwQoR0O0ugX3h6KBKTCWj8/Un7gRRLEMXVf6I4ZpASee46 WX15IEVXqQKNOELc7rIS0XSXUvKO1BANZ+2AvVvgctjk/ppbp9i1QZH6xDpaX3ptX8ix nA+A8dYQd81IiggyokhOF0ICdMCO6hX2TElKaw4PBeFIUYDkwpiFkZoEh38wBhuKMo3l UETtrjlyuL19age3/zGbyEl58MgSkA8GoFcBb1IPoC6cneZGftbguwljG1xEVX5F3P66 OY0+vndePKDCgZHQddTWuOzDooPOB1MZ/sQkv3akhGColcT50NlgqjwOpzs9XYXtJme0 2qUw== X-Gm-Message-State: AOJu0Ywj7+Wh3Aanotkrugfz7trFZ1GF1kS8y+NVJBBjIkPWAmgW4deV x91iJwHUwyBa3C+SllrjAYMCpj1vjhAq68epf7k= X-Google-Smtp-Source: AGHT+IEbzLKyyRKr3vghzxfzfoizfeXWJpWjRDuNovzeSL+CHs0YeP9XFTIhxRvdMXHb7QjNCiO53+6MX3MI2wYooXo= X-Received: by 2002:a2e:9bc4:0:b0:2cd:1c04:4f6 with SMTP id w4-20020a2e9bc4000000b002cd1c0404f6mr473667ljj.24.1705486846508; Wed, 17 Jan 2024 02:20:46 -0800 (PST) In-Reply-To: <4105c743-45d0-48a0-a8bb-1ab457b9a256@gutov.dev> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:278378 Archived-At: On Wed, Jan 17, 2024 at 2:41=E2=80=AFAM Dmitry Gutov wro= te: > An "abstract" mode is supposedly one that doesn't do anything. So it > doesn't have to be callable. No. Not "abstract" as in "Java interface", abstract as in "Java abstract class". > Anyway, that's +1 feature required for the implementation. Almost trivial feature. See patch after sig. It'll make this work: (define-derived-mode foo-mode prog-mode "Fooey" :abstract t (message "Hey from foo-mode")) (define-derived-mode bar-mode foo-mode "Barey" (message "Hey from bar-mode")) 'foo-mode' can't be called, but 'bar-mode can, of course. And it will call its parent. > > What if we filter by prog-mode? It would leave the ':ruby-base' and > > ':python-base' as false positives, I guess. But then we could reasonab= ly > > say that anything ending with '-base' is abstract (or use the > > aforementioned explicit abstract prop). > > We would also filter out :css, for example. Sure? I see a super-normal css-base-mode inheriting from prog-mode. > TeX modes also do not derive > from prog-mode. TeX does have an LSP server, however. At the end of the day we have to come to a conclusion of what we want to do. I want to find major modes that correspond to languages, right? So: * these outliers start inheriting from prog-mode * we inject new lang-mode between prog-mode and fundamental-mode and make outliers derive from that. * we say these outliers aren't languages * we code exceptions for these outliers It could even be that (derived-mode-add-parents 'tex-mode '(prog-mode)) is exactly what's needed here, showcasing how I think this particular heavy hammer should be used for the exception, not the rule. > > Yes. I don't see the full scan of m-m-remap-alist as problematic > > from a effiency perspective. If we decide it's the database, it's > > the database. It's unfortunate that the "alist" implementation is > > hardcoded in the name (which is why I would prefer a (:language "Foo") > > kwarg to define-derived-mode) but we can abstract the alist aspect > > away with accessors and do the usual "Do not change this variable > > directly, use these accessors instead". > > I'm not saying in advance that it will be slow. Just that it's a > different function. Ah. Right. And I think it's a good one. Eglot needs it, and so does Yasnippet, probably. > >> BTW, get-current-mode-for-language could be implemented in terms of > >> set-buffer-language. > > > > What does get-current-mode-for-language do exactly? > > The major-mode currently configured to be used for the language (through > m-m-a-alist, in the current proposal). set-auto-mode will choose it. Perfect. But the, "set-buffer-language" comment? Does a buffer object have to exist for that job to be done? > > Right. So maybe > > > > (or (with-current-buffer buffer (get-language-for-mode major-mode)) > > (let (kw) > > (and buffer-file-name > > (keywordp (setq kw (alist-get buffer-file-name auto-mode-a= list))) > > kw)) > > (consult-oracles) > > (error "Don't know what language this is, sorry")) > > Replied to this one in another email: referring to the results of the > computation of set-auto-mode is easier. But that's a technical detail. For sure, reuse as much code as possible. I was just illustrating the intended fallback logic. Jo=C3=A3o diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el index dec5883767d..a9b67965416 100644 --- a/lisp/emacs-lisp/derived.el +++ b/lisp/emacs-lisp/derived.el @@ -143,6 +143,9 @@ define-derived-mode :interactive BOOLEAN Whether the derived mode should be `interactive' or not= . The default is t. + :abstract BOOLEAN + You'll never be able to use the CHILD mode directly + in a buffer, just use as a PARENT for other modes. BODY: forms to execute just before running the hooks for the new mode. Do not use `interactive' here. @@ -192,7 +195,9 @@ define-derived-mode (hook (derived-mode-hook-name child)) (group nil) (interactive t) - (after-hook nil)) + (abstract nil) + (after-hook nil) + (function-name child)) ;; Process the keyword args. (while (keywordp (car body)) @@ -201,9 +206,13 @@ define-derived-mode (:abbrev-table (setq abbrev (pop body)) (setq declare-abbrev nil)) (:syntax-table (setq syntax (pop body)) (setq declare-syntax nil)) (:after-hook (setq after-hook (pop body))) + (:abstract (setq abstract (pop body))) (:interactive (setq interactive (pop body))) (_ (pop body)))) + (when abstract + (setq function-name (gensym "--internal-")) + (put child 'abstract-mode function-name)) (setq docstring (derived-mode-make-docstring parent child docstring syntax abbrev)) @@ -245,13 +254,12 @@ define-derived-mode (put ',child 'derived-mode-parent ',parent)) ,(if group `(put ',child 'custom-mode-group ,group)) - (defun ,child () + (defun ,function-name () ,docstring ,(and interactive '(interactive)) ; Run the parent. (delay-mode-hooks - - (,(or parent 'kill-all-local-variables)) + (,(or (get parent 'abstract-mode) parent 'kill-all-local-variables)) ; Identify the child mode. (setq major-mode (quote ,child)) (setq mode-name ,name)