emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make all tree-sitter modes optional


From: Alan Mackenzie
Subject: Re: Make all tree-sitter modes optional
Date: Tue, 14 Feb 2023 21:02:25 +0000

Hello, Eli.

On Tue, Feb 14, 2023 at 21:29:01 +0200, Eli Zaretskii wrote:
> > Date: Tue, 14 Feb 2023 19:08:42 +0000
> > Cc: Juri Linkov <juri@linkov.net>, casouri@gmail.com,
> >   monnier@iro.umontreal.ca, larsi@gnus.org, theo@thornhill.no,
> >   jostein@secure.kjonigsen.net, emacs-devel@gnu.org
> > From: Alan Mackenzie <acm@muc.de>

[ .... ]

> > No, it is not adequate.  It is horrible.

> Not a very kind remark, to say the least.

Sorry, I should have written "It is horrible for me." - which is true.

> > How about commands c-make-ts-default-mode and c-make-ts-undefault-mode

> I'm okay with adding the latter, if it turns out easy enough and safe
> enough (of which I'm not sure at all), and if such a command will be
> implemented for all the *-ts-modes which have non-ts siblings, but I
> see no reason for the former, since there are several simple ways to
> cause the same effect, and they are all documented in NEWS.

OK, Try this (so far only on c-ts-mode.):


diff --git a/etc/NEWS b/etc/NEWS
index 2d15e39036a..0a745d7cde9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3239,10 +3239,13 @@ for which a "built-in" mode would be turned on.  For 
example:
 
     (add-to-list 'major-mode-remap-alist '(ruby-mode . ruby-ts-mode))
 
-If you try these modes and don't like them, you can go back to the
-"built-in" modes by restarting Emacs.  But please tell us why you
-didn't like the tree-sitter based modes, so that we could try
-improving them.
+Normally, the loading of one of the new modes amends 'auto-mode-alist'
+such that future visiting of the same type of file will continue to
+use that new mode.  If this is not what you want, do M-x
+<mode>-make-ts-undefault-mode.  For a more permanent effect, put, for
+example, the following into your initialization file:
+
+    (eval-after-load 'c-ts-mode '(c-make-ts-undefault-mode))
 
 Each major mode based on tree-sitter needs a language grammar library,
 usually named "libtree-sitter-LANG.so" ("libtree-sitter-LANG.dll" on
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 5093c3980b6..d6ea95a2980 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -904,6 +904,20 @@ c-or-c++-ts-mode
          (treesit-ready-p 'c))
     (add-to-list 'auto-mode-alist '("\\.h\\'" . c-or-c++-ts-mode)))
 
+(defun c-make-ts-undefault-mode ()
+  "Make the older C and C++ Modes the default major modes for C(++) files."
+  (interactive)
+  (setq auto-mode-alist (delete '("\\.h\\'" . c-or-c++-ts-mode)
+                                auto-mode-alist))
+  (setq auto-mode-alist
+        (delete '("\\(\\.[chi]\\|\\.lex\\|\\.y\\(acc\\)?\\|\\.x[bp]m\\)\\'" . 
c-ts-mode)
+               auto-mode-alist))
+  (setq auto-mode-alist
+        (delete
+        
'("\\(\\.ii\\|\\.\\(CC?\\|HH?\\)\\|\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\|\\.\\(cc\\|hh\\)\\)\\'"
+          . c++-ts-mode)
+        auto-mode-alist)))
+
 (provide 'c-ts-mode)
 
 ;;; c-ts-mode.el ends here

[ .... ]

> I think you have a very simplistic idea of what loading a *-ts-mode
> does, but if you can come up with a simple and safe implementation, I
> won't object adding such a command -- it cannot do any harm by just
> being there, and if it turns to be not what users want, we can always
> advise them not to use it.

[ .... ]

> > Either of these would allow the user to try out the new modes freely
> > without being coerced against their will to use the new -ts- modes.

> "Try out" is not what I had in mind for users who'd like to use these
> modes.

Some will want to try them out first, before definitively committing to
them.  I am such a user.

[ .... ]

> Then they [proposed amendments] aren't "reasonable" at this time.
> Maybe later, maybe on master.

That will be too late, the damage will have been done.  It is the first
experience people have of the new modes which will create their long term
impressions of them.  I remember something similar happening in Emacs
21.1, when the new fringes were not made optional.  Lots of users
complained loudly and bitterly.

> As I said several times, we have no good idea yet how users will react
> to what we have.  Maybe, after we hear from them, we decide to
> implement such switches, who knows.

We are ourselves all users, too.  We know how we have reacted, and it is
reasonable to try to prevent bad experiences for users similar to
ourselves.

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]