From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode Date: Thu, 4 Jul 2019 01:52:04 +0100 Message-ID: References: <20190702131632.GA30597@ACM> <20190702160410.GB30597@ACM> <20190702182811.GC30597@ACM> <20190703105804.GA11238@ACM> <87wogz561t.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000009ba403058cd06317" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="66231"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel To: =?UTF-8?Q?K=C3=A9vin_Le_Gouguec?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 04 02:53:16 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hipzv-000H8M-Sy for ged-emacs-devel@m.gmane.org; Thu, 04 Jul 2019 02:53:16 +0200 Original-Received: from localhost ([::1]:42094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hipzu-00056Q-Q6 for ged-emacs-devel@m.gmane.org; Wed, 03 Jul 2019 20:53:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38443) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hipz0-000567-5P for emacs-devel@gnu.org; Wed, 03 Jul 2019 20:52:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hipyy-0000rf-Pw for emacs-devel@gnu.org; Wed, 03 Jul 2019 20:52:18 -0400 Original-Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]:33768) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hipyy-0000rK-KO for emacs-devel@gnu.org; Wed, 03 Jul 2019 20:52:16 -0400 Original-Received: by mail-io1-xd2a.google.com with SMTP id u13so4914058iop.0 for ; Wed, 03 Jul 2019 17:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=H3ncOhc1Z2GNblvBvpelSrGwaNtbfzY/DdIcVl6hYNg=; b=GRAawBzWAp1fvbQWSUKsB11IyVEDCeBIcBEbzdczTS4oNP6qAfv2FRimOYvplR7CtT 00VCsWayo52ufhLpNx4C2yWLklFhtBnqPE1IxorQSAikkMt8e28QbZH0dz6VwvpwTI92 sjDhGb/HBK2cnIX356B9zzg0OpolVA3LSth5eFZxE3QdgRzgMkimw1maKcwRbVdZ2yaU 4Chi4YfY7KtfDEUfFqldq4XtW4Ol1Y4ANFiGBts3n9qP3N9pMKbEe5+Y7aMMI2CxjzGP rFIsy1t72oDn7tlyIISidVygmIpDHvoAp0xXOWtKwctUq5BoYP9OpO4Bq6JPYC6ED4hC Z0VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=H3ncOhc1Z2GNblvBvpelSrGwaNtbfzY/DdIcVl6hYNg=; b=mwLq+bdXPhXvPfb29aeaoejivljgv9eG3h4GPWmwYMNgNR6XzsKTpWrPJYCt6Kjin8 jMfEU0VV8LC49uqAVYpsK+k4JClfENDu5WCCi3hiVvjKj0JMnqu3fAiLOM3S1L+XSAQT 7z1kNQKDDI0wAgiYVjLlsgiO5Vx5zRrmw8SEbSIM+s5bJPoqDVhnlfVG0aq3lqPMLsXn P57bXGPQKUaOJ/OYiaXPjJ8qk4bib0OlSaRrsbDR6mE/HCT1uzq/4LxG+vrtghuY8GY3 6/1Ryabika0I6JPmLtaQa5wI21nZVVZ22bV3nzbsipl0nvpdQDhl2ySzv5kgJkeP6V4R SLZA== X-Gm-Message-State: APjAAAV28eMXeII3ZrmW6gum8Uz/NN2k/N0AZwMAjZIna7FiIr9XDKjS vLkuRaeu9cyVTRr1d8Gy9VULEtpJI9NgNQIc86g= X-Google-Smtp-Source: APXvYqwHmLXmGx46Sx6FUFl9ClkUfSAdkgm7Oy5xLnxzNbeD5fCOPFyzHqbQaM+jPqXOvzPVphdmTj0pR74eQSkXL4A= X-Received: by 2002:a5d:9ec4:: with SMTP id a4mr38038457ioe.125.1562201535781; Wed, 03 Jul 2019 17:52:15 -0700 (PDT) In-Reply-To: <87wogz561t.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::d2a X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:238342 Archived-At: --0000000000009ba403058cd06317 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jul 3, 2019 at 7:25 PM K=C3=A9vin Le Gouguec wrote: > Looking at this situation from afar[1], invalid-syntax highlighting > sounds exactly like the kind of feature that could be implemented as a > flymake backend[2]. If you're not connecting these particular dots, I wrote Flymake (or rather, I rewrote it) recently, so that's why I'm partial to it. But there is also another very good and popular solution, Flycheck, which does basically the same thing (but is not bundled with Emacs). Anyway, if you open an Emacs C source and type M-x flymake-mode you should already get the full syntax validation of the buffer as performed by the compiler. In other projects, it's easy to setup (see the docstring for the flymake-cc-command variable). > - lifting some fontification code off CC mode since I assume the > flymake frontend would handle the presentation, > ... > apart and banging on it until it fits flymake's API is not the path of > least resistance. It's not trivial to write a Flymake backend, but it's not hard either. I wrote documentation for that in the manual and in docstrings. For this , you don't need to lift any code off CC-mode (or any other mode) if it follows basic assumptions. I hacked up a (very lightly tested) backend that will diagnose unterminated multi-line strings in most modes. This includes cc-derived modes if you monkey-patch them with (defun c-unescaped-nls-in-string-p (&optional quote-pos) t) ...or if you find some other way to disable the problematic feature. Here is the code. (cl-defun flymake-check-unterminated-strings (report-fn &key changes-start changes-end &allow-other-keys) "Flymake backend for checking unterminated strings in c-like modes" (save-excursion (cl-loop with collected =3D (list) with start =3D (or changes-start (point-min)) with start-ppss =3D (syntax-ppss) with end =3D (or changes-end (point-max)) initially (goto-char start) (when (nth 3 start-ppss) (goto-char (setq start (nth 8 start-ppss))) (setq start-ppss (syntax-ppss))) for ppss =3D start-ppss then (syntax-ppss) for next =3D (if (and (nth 3 ppss) (nth 8 ppss)) (let* ((lep (line-end-position)) (probe (char-before lep)) (string-end (ignore-errors (1+ (scan-sexps (nth 8 ppss) 1))))) (setq end (or string-end (point-max))) (cond ((eq probe ?\\) (1+ lep)) ((and (not (=3D lep (point))) (eq probe ?\"= )) (and string-end (1+ string-end))) (t (push (flymake-make-diagnostic (current-buffer) (point) (1+ lep) :error "unterminated string") collected) (and string-end (1+ string-end))))) (1+ (point))) while (and next (<=3D next end)) do (goto-char next) finally (funcall report-fn collected :region (cons start end)) (cl-return collected)))) You can try it with (add-hook 'flymake-diagnostic-functions #'flymake-check-unterminated-strings nil t) You might have to turn flymake off and on again. You also need a very recent Flymake (version 1.0.8 should be in GNU ELPA shortly). -- Jo=C3=A3o T=C3=A1vora --0000000000009ba403058cd06317 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: base64 PGRpdiBkaXI9Imx0ciI+T24gV2VkLCBKdWwgMywgMjAxOSBhdCA3OjI1IFBNIEvDqXZpbiBMZSBH b3VndWVjICZsdDs8YSBocmVmPSJtYWlsdG86a2V2aW4ubGVnb3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