From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Basile Starynkevitch Newsgroups: gmane.emacs.help Subject: Re: Question about syntax coloring using an external program Date: Sun, 15 Oct 2023 17:34:06 +0200 Message-ID: <73b359e7-a578-4b79-94b1-8f407ad3a764@starynkevitch.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15155"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: "team@refpersys.org" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 15 17:34:55 2023 Return-path: Envelope-to: geh-help-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 1qs38o-0003eE-8w for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 15 Oct 2023 17:34:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qs38E-0002UW-Ll; Sun, 15 Oct 2023 11:34:18 -0400 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 1qs38C-0002U8-QZ for help-gnu-emacs@gnu.org; Sun, 15 Oct 2023 11:34:16 -0400 Original-Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qs389-0005fQ-MN for help-gnu-emacs@gnu.org; Sun, 15 Oct 2023 11:34:16 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id A1A32240004; Sun, 15 Oct 2023 15:34:07 +0000 (UTC) Content-Language: en-US In-Reply-To: X-GND-Sasl: basile@starynkevitch.net Received-SPF: pass client-ip=2001:4b98:dc4:8::221; envelope-from=basile@starynkevitch.net; helo=relay1-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145290 Archived-At: Hello all, On 10/15/23 16:01, Fredrik Öhrström wrote: > I would like to invoke an external program to do syntax coloring and > formatting of the source inside an emacs buffer. I have created an elisp > solution using font-lock mode an regexes, but I would like a 100% correct > coloring solution. It suppose it could be implemented in pure elisp, but > for the moment I need to use an external program to do this. The external > program can annotate the source with tags that probably can be used by > emacs to color the source. > > However I am at a loss how to actually implement such a round trip in emacs. > I would greatly appreciate any pointers to similar existing solutions or > hints on how to do it! I am assuming you use GNU emacs (a recent one) on a GNU/Linux computer. In theory you could use approaches inspired by the following GNU emacs extensions: The ocaml merlin and tuareg modes: > https://ocaml.github.io/merlin/editor/emacs/ Since the ocaml compiler (i.e. ocamlc or ocamlopt) can compute typing information (e.g. if you compile Ocaml source foo.ml with ocamlc -bin-annot foo.ml, a binary file foo.cmt is created, containing type information; which is exploitable with another utility by emacs). Another approach involves the language server protocol LSP: See https://en.wikipedia.org/wiki/Language_Server_Protocol (I believe /LSP/ is somehow supported in some extensions of recent GNU emacs) Yet another approach would involve GNU emacs extensibility (this might require patching GNU emacs source code); see its file src/dynlib.c (since dlopen seems to be callable from GNU emacs). See https://www.gnu.org/software/emacs/manual/html_node/elisp/Dynamic-Modules.html and https://www.gnu.org/software/emacs/manual/html_node/elisp/Writing-Dynamic-Modules.html Whatever approach you take, please explain it on some public mailing list, and if possible publish your code (with a GNU emacs compatible license, perhaps GPLv3+). In the RefPerSys open source inference engine project (see https://github.com/RefPerSys/RefPerSys/ ....), we would need (in a few months) to do something similar. Thanks -- Basile Starynkevitch -http://starynkevitch.net/Basile/ email: (near Paris, France) only mines opinions - les opinions sont seulement miennes