From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Unifying "foo-mode"s and "foo-ts-mode"s Date: Fri, 30 Dec 2022 16:24:56 +0100 Message-ID: <74FE4DBA-D1B0-4E68-BBE5-FDB96AD3E88D@thornhill.no> References: <877cyagmti.fsf@posteo.net> <831qoi85u7.fsf@gnu.org> <87mt76f4n4.fsf@posteo.net> <83sfgy6l0n.fsf@gnu.org> <877cy9b1k0.fsf_-_@posteo.net> <87wn69oy1c.fsf@thornhill.no> <87edsh9gzn.fsf@posteo.net> <87tu1dowpp.fsf@thornhill.no> <87o7rl7x4i.fsf@posteo.net> 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="36917"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org, Yuan Fu To: Philip Kaludercic Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 30 16:26:04 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 1pBHGl-0009KN-DL for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Dec 2022 16:26:03 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBHFy-0001UT-T6; Fri, 30 Dec 2022 10:25:14 -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 1pBHFx-0001Rl-Df for emacs-devel@gnu.org; Fri, 30 Dec 2022 10:25:13 -0500 Original-Received: from out2.migadu.com ([2001:41d0:2:aacc::]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBHFt-0006Df-6p; Fri, 30 Dec 2022 10:25:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1672413902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Hoza/E0mSNheZ3GAojR46OvvqMSw/qpEAgD/l4Wfog=; b=XY0yIDHcxuetxVC6LJlo0DJN/2vQVojSZLshPY/mYkoSfJpZHDEuGVu+gpNtrHR3Eskjm0 ABuzr+bYRSjeJeLUI2T0/3/TtUqd+6+wrZ3kiRxobxm2SArMG422BEvDjyHewYTuLCBl5c YfZW7ysyIPHRO3f6xyloQj/XLzrd/mqu+kgt3bROaPOtRKheFqd5Mze+c+XLOOfHURqcbK Q6cNwtJJPn4HfGL/qWkuw7QwvMotQO1IqK9AtJzwNfmv/3kCRDrSFbmhiNtZ31FNnyJ8i7 X4XbE/2OG4tF94Q9WThWyfOvlF4sASyZ2epyNu4gN8hjtqTcvBa1TH1Z38qhPQ== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-Reply-To: <87o7rl7x4i.fsf@posteo.net> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:2:aacc::; envelope-from=theo@thornhill.no; helo=out2.migadu.com 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_PASS=-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:302114 Archived-At: On 30 December 2022 16:02:37 CET, Philip Kaludercic = wrote: >Theodor Thornhill writes: > >> Philip Kaludercic writes: >> >>> Theodor Thornhill writes: >>> >>>> Philip Kaludercic writes: >>>> >>>>> Eli Zaretskii writes: >>>>> >>>>>> You can try=2E I would like to start a full feature freeze in a da= y or >>>>>> two, so I'm not sure you will have enough time=2E And it isn't lik= e we >>>>>> didn't try various approaches during the past two months, so frankl= y I >>>>>> don't think that a better way even exists=2E But if you come up wi= th >>>>>> some very bright idea, who knows? >>>>> >>>>> I have attached a sketch of my proposal with support for Python=2E >>>>> Instead of a separate python-ts-mode, we regulate tree-sitter suppor= t >>>>> using a user option `treesit-enabled-modes'=2E It can either be a l= ist >>>>> >>>> >>>> [=2E=2E=2E] >>>> >>>> IIUC this will make all other config run before the treesit-related >>>> code? =20 >>> >>> If that is the problem, that we can solve that by re-adjusting the ord= er >>> in which the expanded code occurs=2E=20 >>> >>>> In that case I think this cannot work, because we _don't_ want= to >>>> set all the before/after-change functions many modes set, for example= =2E >>> >>> What exactly is the issue here? Can't we overwrite it again if >>> necessary? >>> >> >> For example the CC modes set up lots of functions in the mode init, man= y >> of which override things like '*-function' variables, that if either no= t >> overriden explicitly by a treesit alternative or removed before mode >> init will impact performance=2E There are some modes that will be wors= e >> in this regard than others, but one of my earlier suggestions was to >> just: >> >> (define-derived-mode foo =2E=2E=2E=2E=2E=2E=2E=2E >> >> (cond >> (use-treesit-p >> (init-all-the-treesit-stuff)) >> (use-hypothetical-future-thing >> (init-all-the-hypothetical-future-stuff)) >> (t >> (init-all-the-other-stuff)))) > >This also looks good=2E > >> In this case we don't let any code bleed in between the modes, which IM= O >> is necessary=2E At least we should be very careful with _when_ it is o= k >> for such settings to bleed in=2E Things like comment-start/end etc can >> bleed in just fine, but stuff like >> >> ``` >> (c-init-language-vars js-mode) >> (setq-local indent-line-function #'js-indent-line) >> (setq-local beginning-of-defun-function #'js-beginning-of-defun) >> (setq-local end-of-defun-function #'js-end-of-defun) >> (setq-local open-paren-in-column-0-is-defun-start nil) >> (setq-local font-lock-defaults >> (list js--font-lock-keywords nil nil nil nil >> '(font-lock-syntactic-face-function >> =2E js-font-lock-syntactic-face-function))) >> (setq-local syntax-propertize-function #'js-syntax-propertize) >> (add-hook 'syntax-propertize-extend-region-functions >> #'syntax-propertize-multiline 'append 'local) >> (add-hook 'syntax-propertize-extend-region-functions >> #'js--syntax-propertize-extend-region 'append 'local) >> (setq-local prettify-symbols-alist js--prettify-symbols-alist) >> >> (setq-local parse-sexp-ignore-comments t) >> (setq-local which-func-imenu-joiner-function #'js--which-func-joiner) >> ``` >> >> Should absolutely not=2E >> >> Does that make sense? I don't think this is impossible, but my biggest >> argument was that we need to keep things distinct, or at least be very >> explicit on when we share code=2E > >Yes, I do understand this point, yet my impression has been that this >was not always necessary=2E The relative complexity of cc-mode might >necessitate a separate mode, but I don't see why that should be the rule >instead of an exception? IIRC it was mostly because we wanted to start creating things instead of b= ikeshedding over these details=2E=20 My thought process was to create separate modes now, and make a facility t= o map a language to a mode implementation=2E For example, imo it doesn't ma= ke sense for "the first" implementation to own a language's namespace=2E c-= mode should be able to leverage cc-mode _or_ c-ts-mode, rather than the oth= er way around=2E At least during these months that seemed smart, because we have many contr= ibutions now due to the simple nature of creating a foo-ts-mode=2E=20 Surgically injecting tree sitter into existing modes is prone to error, an= d requires quite deep knowledge of each existing mode's inner working=2E So I'd just hold off and maybe create a nice facility for Emacs 30=2E Something like (setq major-mode-backend '((c =2E cc-mode) (c++ =2E treesit))) Then M-x c-mode would trigger cc, and c++-mode would trigger c++-ts-mode= =2E And we keep the old implementations as the default until we know tree-sitt= er, has no disadvantages and swap the default=2E No need to deprecate anyth= ing or require config changes, imo=2E Theo