From unknown Sun Aug 17 09:10:48 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#23461 <23461@debbugs.gnu.org> To: bug#23461 <23461@debbugs.gnu.org> Subject: Status: perl mode uses same color for comments and here documents Reply-To: bug#23461 <23461@debbugs.gnu.org> Date: Sun, 17 Aug 2025 16:10:48 +0000 retitle 23461 perl mode uses same color for comments and here documents reassign 23461 emacs submitter 23461 =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson severity 23461 wishlist tag 23461 fixed thanks From debbugs-submit-bounces@debbugs.gnu.org Thu May 05 17:04:50 2016 Received: (at submit) by debbugs.gnu.org; 5 May 2016 21:04:50 +0000 Received: from localhost ([127.0.0.1]:40752 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayQS2-0007dF-CS for submit@debbugs.gnu.org; Thu, 05 May 2016 17:04:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54201) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayQS1-0007d3-9t for submit@debbugs.gnu.org; Thu, 05 May 2016 17:04:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayQRm-0003RT-Vd for submit@debbugs.gnu.org; Thu, 05 May 2016 17:04:41 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:47103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayQRl-0003PM-QV for submit@debbugs.gnu.org; Thu, 05 May 2016 17:04:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayQRa-0004lH-AE for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 17:04:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayQRM-0003BR-GL for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 17:04:14 -0400 Received: from homie.mail.dreamhost.com ([208.97.132.208]:34286 helo=homiemail-a8.g.dreamhost.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayQRL-00030s-3H for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 17:04:08 -0400 Received: from homiemail-a8.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a8.g.dreamhost.com (Postfix) with ESMTP id 7ED2B5F206C for ; Thu, 5 May 2016 14:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to :subject:date:message-id:mime-version:content-type; s= jidanni.org; bh=1NUWagH7GJ813CM1jCU2odZCxFg=; b=EW4++e3RgxToaiDY k11IhymTImtIlwGmiygnqbY8/bqnojIjg7NRoD3KT0frtgi6Ex4b4vx8ZLrCRt1H Mmf7n/sKuf9y34RwM3RhR4jyzR4ACvN9rC1N6PMYOAi+G1lTDPisEqNs5meaCSJJ inDWuZHYlSr+I06qneDCM9A4hy4= Received: from jidanni.org (111-246-97-209.dynamic.hinet.net [111.246.97.209]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: jidanni@jidanni.org) by homiemail-a8.g.dreamhost.com (Postfix) with ESMTPSA id 3CA0F5F2068 for ; Thu, 5 May 2016 14:03:51 -0700 (PDT) From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson To: bug-gnu-emacs Subject: perl mode uses same color for comments and here documents Date: Fri, 06 May 2016 05:03:46 +0800 Message-ID: <87a8k4tdxp.fsf@jidanni.org> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) perl mode uses same color for comments and here documents. Isn't there some other color that can be chosen? print <<'EOF'; EOF # use XML::TreePP; emacs-version "24.5.1" From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 07 07:36:16 2019 Received: (at control) by debbugs.gnu.org; 7 Jul 2019 11:36:16 +0000 Received: from localhost ([127.0.0.1]:56217 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hk5Sq-00083l-Fo for submit@debbugs.gnu.org; Sun, 07 Jul 2019 07:36:16 -0400 Received: from mail-wr1-f53.google.com ([209.85.221.53]:44350) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hk5So-00083W-KM for control@debbugs.gnu.org; Sun, 07 Jul 2019 07:36:15 -0400 Received: by mail-wr1-f53.google.com with SMTP id p17so2928489wrf.11 for ; Sun, 07 Jul 2019 04:36:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Y0FGaWmhoeScixEIOyU4YeFJdm5x6vER6ec3F9+isxQ=; b=DNpswcfgDniDje8QwmTO9KPCWPbFXQD+h9eF8jcWkkpJd3mNoKbrp8+PfvH9RyJTJN uG4reTvlGi24OkdM5rrViODKqfDZ9DtygzuZ/ts9AhO1BL7sbe3SDCEjbcWevA1R0Q5m /14W44GxPtEn37yEcxKap+uIfNXpmxBNdjQX5cLL1AUcY/M6As7MO+K5+1CvM9wUpJ7q nShzsPjBzYFLJ8NoyxTPx6RPIduRjBwZZ4A3R2xufUWQ7tQSVIDywRC87KZxFw7uk+rI LT1qRBMPMjr1AW266ZCCAGGstU+H1uU2TfzcuFnYygnMe2TjHe8rvcYCJY0aGISkehzQ z8XA== X-Gm-Message-State: APjAAAVciaRX68ZtnKs0+ZnyZdsgcGawc28iuVsvaECOMs7qbydM9NHW dSAXQNlpKGXM9FiVNELBbcusnvY4D0L63b5kjP2mTPD2 X-Google-Smtp-Source: APXvYqxoHGWZ/AD8DAARJx1bdDAMqeICa7zLvUO79CC+0AhDfR84yOvrESIw0akg8+G3cB2Z3VYUNA/7CFKsJvD6vIE= X-Received: by 2002:a5d:4609:: with SMTP id t9mr12658851wrq.85.1562499368825; Sun, 07 Jul 2019 04:36:08 -0700 (PDT) MIME-Version: 1.0 From: Stefan Kangas Date: Sun, 7 Jul 2019 13:35:57 +0200 Message-ID: Subject: severity 23461 wishlist To: control@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 1.8 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: severity 23461 wishlist quit Content analysis details: (1.8 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (stefankangas[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.53 listed in list.dnswl.org] 0.2 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and EnvelopeFrom freemail headers are different 1.3 PDS_NO_HELO_DNS High profile HELO but no A record X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.8 (/) severity 23461 wishlist quit From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 09 01:52:33 2019 Received: (at 23461) by debbugs.gnu.org; 9 Oct 2019 05:52:33 +0000 Received: from localhost ([127.0.0.1]:51922 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iI4tl-00034g-Ce for submit@debbugs.gnu.org; Wed, 09 Oct 2019 01:52:33 -0400 Received: from quimby.gnus.org ([80.91.231.51]:54522) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iI4tk-00034Y-AE for 23461@debbugs.gnu.org; Wed, 09 Oct 2019 01:52:32 -0400 Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iI4tf-0003Tx-TQ; Wed, 09 Oct 2019 07:52:30 +0200 From: Lars Ingebrigtsen To: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson Subject: Re: bug#23461: perl mode uses same color for comments and here documents References: <87a8k4tdxp.fsf@jidanni.org> Date: Wed, 09 Oct 2019 07:52:27 +0200 In-Reply-To: <87a8k4tdxp.fsf@jidanni.org> (=?utf-8?B?IuepjeS4ueWwvA==?= Dan Jacobson"'s message of "Fri, 06 May 2016 05:03:46 +0800") Message-ID: <87zhiaqxd0.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: 積丹尼 Dan Jacobson writes: > perl mode uses same color for comments and here documents. > Isn't there some other color that can be chosen? > > print <<'EOF'; > > EOF > # use X [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson writes: > perl mode uses same color for comments and here documents. > Isn't there some other color that can be chosen? > > print <<'EOF'; > > EOF > # use XML::TreePP; Yes, that doesn't seem optimal... But as usual when trying to investigate what's going on with these syntax things, I have no idea what's going on. perl-mode detects these correctly, but I don't know where the mapping from whatever this does to faces happens, and I can't edebug through syntax-propertize-rules, and putting a `debug' into the thing is just ignored. Does anybody know where I should be poking around to find out what's going on here? ;; Here documents. ((concat "\\(?:" ;; << "EOF", << 'EOF', or << \EOF "<<\\(~\\)?[ \t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:al= num:]]*\\)" ;; The <) id 1krtkM-0004E2-7M for submit@debbugs.gnu.org; Tue, 22 Dec 2020 21:19:27 -0500 Received: from mout01.posteo.de ([185.67.36.65]:41770) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1krtkJ-0004Dk-BL for 23461@debbugs.gnu.org; Tue, 22 Dec 2020 21:19:24 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id D2D7616005C for <23461@debbugs.gnu.org>; Wed, 23 Dec 2020 03:19:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1608689956; bh=Jx9sqtZgT+Nqov61P0Gm0FgzfmwxLZd9OgjQE5AhAoA=; h=From:To:Cc:Subject:Date:From; b=ADAfFkTpDKuVnNyol7YFmKwlyvwdxHSyGUOQ/Yzm4AK6vYLJfV37M//QtNVpjGHri eTlB1Tx2GbkZeE0EH1ljvh1nlhAzeSLmSvsqyk6GXjh/2fhWFjPjW4wy8XDNv7f4aU LJhHl+Xd45K9mqulws+wAymvAzFSP/9EV8CCT3dAlPm8m9uRKQchUD5rvBDOJlnq6+ ds+R531P2VbZ1AJf9JotJngqwZbysasiH/S8FwwS/ScuksA08My/npXp+BB2g5oe2a I4WOtllS3eAkjM7zp3COopjUQEaRO9FG9/vwyAXAP+OeiN78CL03Dp6F2JRa17TQD+ 4N0xbe8tByxJw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D0xjH654Sz6tmB; Wed, 23 Dec 2020 03:19:15 +0100 (CET) From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) To: 23461@debbugs.gnu.org Subject: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Wed, 23 Dec 2020 03:19:15 +0100 Message-ID: <87sg7xxo0s.fsf@hajtower> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain This is a detour from my work on CPerl mode bugs ... while trying to steal some syntax concepts from perl-mode.pl, I stumbled over this old report. I guess I can explain what's going on. Short story: Perl mode marks HERE-docs syntactically as c-style comments, hence font-lock-mode selects the comments face. Investigating how to fix this leads to the longer story. There are two possible approaches: 1) use a string-style syntax (generic string) instead of c-style comments to flag HERE-documents. That way, font-lock picks up the correct face automagically. 2) Keep HERE_docs as c-style comments, but change the face mapping by injecting a function into font-lock-defaults which applies the string face to c-style comments. Both approaches work, but both are a bit whacky. For 1), changing the syntax code is easy but opens a can of worms: Indentation after the HERE-doc doesn't work any more. The reason is that Perl mode needs to go "back" to find out whether a statement is a continuation line. "Back" includes skipping back over comments, but that HERE-doc is no longer a comment, so it blocks the way to find whether the line before the HERE-doc ends a statement. To fix that, all calls to perl-backward-to-noncomment must be checked whether they need to skip backward over HERE-docs, too. I added a function perl-backward-to-noncomment-nonhere, and eventually it turned out that the simple perl-backward-to-noncomment seems to be superfluous. For 2), it feels wrong to have strings marked as comments, and it is a bit of a hack to insert a function into font-lock-keywords which doesn't even search for keywords. CPerl mode uses a similar trick, but CPerl mode is renowned for being whacky. Also, __DATA__ sections in Perl mode are marked generic strings, so there ought to be some disambiguation. The patch uses the first approach, and also adds tests which are independent of the chosen solution. As a bycatch, it also fixes the case where the line starting a HERE-doc ends in a comment, which was messed up by perl-mode. I could not find a bug report for that but test cases are included. Perhaps Stefan has an opinion on this, and chances are good that he can point to a better solution... -- Happy winter solstice, haj --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-perl-mode-Display-here-docs-as-strings-instead-of-co.patch Content-Description: perl-mode: Treat HERE-docs as strings >From a17f2323d9018fa312b6721fa7ea5744edc79039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= Date: Wed, 23 Dec 2020 02:34:33 +0100 Subject: [PATCH] ; perl-mode: Display here-docs as strings instead of comments. * lisp/progmodes/perl-mode.el (perl-syntax-propertize-function): Make HERE-doc start a generic string instead of a c-style comment. Handle the case where the line starting a HERE-doc ends with a comment. (perl--beginning-of-here-doc): New function. (perl-backward-to-noncomment-nonhere): New function. (perl-syntax-propertize-special-constructs): Make HERE-terminators end generic strings instead of c-style comments, using the new functions. * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-heredocs): New test (30 should-forms) for various aspects of HERE-documents. Works for CPerl mode, and with the patch also for Perl mode. * test/lisp/progmodes/cperl-mode-resources/here-docs.pl: New file with test cases. --- lisp/progmodes/perl-mode.el | 56 +++++++-- .../cperl-mode-resources/here-docs.pl | 111 ++++++++++++++++++ test/lisp/progmodes/cperl-mode-tests.el | 29 +++++ 3 files changed, 187 insertions(+), 9 deletions(-) create mode 100644 test/lisp/progmodes/cperl-mode-resources/here-docs.pl diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index fd8a51b5a5..a961f723d5 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -324,14 +324,29 @@ perl-syntax-propertize-function ;; disambiguate with the left-bitshift operator. "\\|" perl--syntax-exp-intro-regexp "<<\\(?2:\\sw+\\)\\)" ".*\\(\n\\)") - (4 (let* ((st (get-text-property (match-beginning 4) 'syntax-table)) + (4 (let* ((eol (match-beginning 4)) + (st (get-text-property eol 'syntax-table)) (name (match-string 2)) (indented (match-beginning 1))) (goto-char (match-end 2)) (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0)))) + ;; '>>' occurred in a string, or in a comment. ;; Leave the property of the newline unchanged. st - (cons (car (string-to-syntax "< c")) + ;; Before changing the syntax to generic string, let's + ;; check whether we are in an end-of-line comment, and + ;; if so, cheat by shifting the comment markers one char + ;; to the left. + (when (nth 4 (save-excursion (syntax-ppss eol))) + (when (equal (car (syntax-after (1- eol))) + (car (string-to-syntax "<"))) + ;; yet another edge case: "#" is the last character + ;; in that line, so there's actually no comment. + (put-text-property (- eol 2) (1- eol) + 'syntax-table (string-to-syntax "<"))) + (put-text-property (1- eol) eol + 'syntax-table (string-to-syntax ">"))) + (cons (car (string-to-syntax "|")) ;; Remember the names of heredocs found on this line. (cons (cons (pcase (aref name 0) (?\\ (substring name 1)) @@ -342,7 +357,7 @@ perl-syntax-propertize-function ;; We don't call perl-syntax-propertize-special-constructs directly ;; from the << rule, because there might be other elements (between ;; the << and the \n) that need to be propertized. - ("\\(?:$\\)\\s<" + ("\\(?:$\\)\\s|" (0 (ignore (perl-syntax-propertize-special-constructs end)))) ) (point) end))) @@ -364,12 +379,24 @@ perl-quote-syntax-table (modify-syntax-entry close ")" st)) st)) +(defun perl--beginning-of-here-doc (state) + "If STATE describes a here-document, return its start, else return nil." + ;; We need to distinguish here-docs from normal strings, and from + ;; quote-like constructs like q//. + (let ((in-string-p (nth 3 state)) + (string-start (nth 8 state))) + (and in-string-p + (= (syntax-class (syntax-after string-start)) 15) ; generic string + ;; here-doc strings have a syntax table cdr for the terminator(s) + (cdr-safe (get-text-property string-start 'syntax-table)) + string-start))) ; return the start position if all other tests are t + (defun perl-syntax-propertize-special-constructs (limit) "Propertize special constructs like regexps and formats." (let ((state (syntax-ppss)) char) (cond - ((eq 2 (nth 7 state)) + ((perl--beginning-of-here-doc state) ;; A Here document. (let ((names (cdr (get-text-property (nth 8 state) 'syntax-table)))) (when (cdr names) @@ -386,7 +413,7 @@ perl-syntax-propertize-special-constructs limit 'move)) (unless names (put-text-property (1- (point)) (point) 'syntax-table - (string-to-syntax "> c")))))) + (string-to-syntax "|")))))) ((or (null (setq char (nth 3 state))) (and (characterp char) (null (get-text-property (nth 8 state) 'syntax-table)))) @@ -910,14 +937,14 @@ perl-continuation-line-p "Move to end of previous line and return non-nil if continued." ;; Statement level. Is it a continuation or a new statement? ;; Find previous non-comment character. - (perl-backward-to-noncomment) + (perl-backward-to-noncomment-nonhere) ;; Back up over label lines, since they don't ;; affect whether our line is a continuation. (while (and (eq (preceding-char) ?:) (memq (char-syntax (char-after (- (point) 2))) '(?w ?_))) (beginning-of-line) - (perl-backward-to-noncomment)) + (perl-backward-to-noncomment-nonhere)) ;; Now we get the answer. (unless (memq (preceding-char) '(?\; ?\} ?\{)) (preceding-char))) @@ -959,7 +986,7 @@ perl-calculate-indent (state (syntax-ppss)) (containing-sexp (nth 1 state)) ;; Don't auto-indent in a quoted string or a here-document. - (unindentable (or (nth 3 state) (eq 2 (nth 7 state))))) + (unindentable (or (nth 3 state) (perl--beginning-of-here-doc state)))) (when (and (eq t (nth 3 state)) (save-excursion (goto-char (nth 8 state)) @@ -976,7 +1003,7 @@ perl-calculate-indent (if perl-indent-parens-as-block '(?\{ ?\( ?\[) '(?\{))) 0 ; move to beginning of line if it starts a function body ;; indent a little if this is a continuation line - (perl-backward-to-noncomment) + (perl-backward-to-noncomment-nonhere) (if (or (bobp) (memq (preceding-char) '(?\; ?\}))) 0 perl-continued-statement-offset))) @@ -1076,6 +1103,17 @@ perl-backward-to-noncomment "Move point backward to after the first non-white-space, skipping comments." (forward-comment (- (point-max)))) +(defun perl-backward-to-noncomment-nonhere () + "Move point backward, skipping comments and here-docs." + ;; Comments can appear after a here-doc, but also at the end of the + ;; line containing the here-doc delimiter(s). + (forward-comment (- (point-max))) + (unless (equal (point) (point-min)) + (let ((here-start (perl--beginning-of-here-doc + (save-excursion (syntax-ppss (1- (point))))))) + (when here-start (goto-char here-start))) + (forward-comment (- (point-max))))) + (defun perl-backward-to-start-of-continued-exp () (while (let ((c (preceding-char))) diff --git a/test/lisp/progmodes/cperl-mode-resources/here-docs.pl b/test/lisp/progmodes/cperl-mode-resources/here-docs.pl new file mode 100644 index 0000000000..39e4fe06ba --- /dev/null +++ b/test/lisp/progmodes/cperl-mode-resources/here-docs.pl @@ -0,0 +1,111 @@ +use 5.020; + +=head1 NAME + +here-docs.pl - resource file for cperl-test-here-docs + +=head1 DESCRIPTION + +This file holds a couple of HERE documents, with a variety of normal +and edge cases. For a formatted view of this description, run: + + (cperl-perldoc "here-docs.pl") + +For each of the HERE documents, the following checks will done: + +=over 4 + +=item * + +All occurrences of the string "look-here" are fontified as +'font-lock-string-face. Note that we deliberately test the face, not +the syntax property: Users won't care for the syntax property, but +they see the face. Different implementations with different syntax +properties have been seen in the past. + +=item * + +Indentation of the line(s) containing "look-here" is 0, i.e. there are no +leading spaces. + +=item * + +Indentation of the following perl statement containing "indent" should +be 0 if the statement contains "noindent", and according to the mode's +continued-statement-offset otherwise. + +=back + +=cut + +# Prologue to make the test file valid without warnings + +my $text; +my $any; +my $indentation; +my $anywhere = 'back again'; + +=head1 The Tests + +=head2 Test Case 1 + +We have two HERE documents in one line with different quoting styles. + +=cut + +## test case + +$text = <<"HERE" . <<'THERE' . $any; +#look-here and +HERE +$tlook-here and +THERE + +my $noindent = "This should be left-justified"; + +=head2 Test case 2 + +A HERE document followed by a continuation line + +=cut + +## test case + +$text = <) id 1krvJw-0003ET-3I for submit@debbugs.gnu.org; Tue, 22 Dec 2020 23:00:16 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47280) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1krvJq-0003D4-D3 for 23461@debbugs.gnu.org; Tue, 22 Dec 2020 23:00:13 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id AE75B44149B; Tue, 22 Dec 2020 23:00:04 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 645AB4411FC; Tue, 22 Dec 2020 23:00:03 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1608696003; bh=/U+CEOQ0quU+FqBn6mfd0PqcqM9uoHjLGzdeJlIJ8zM=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=CqCY/FMKUOUY4yERLt7k9EiR1aqjTDh51ppv8V7jneXiK+M8QkRn8hIsz025dTAMw rl8IbaMWtHroHu6Xca8ADE+F+Irg8JwWL+zSyjP8ghFRJgDm2dSP2BbOpSirp1kz0L X9Bp/1DBvkA/bZBMgOZRqMjMgmhLhnAZ5cQLyIGY9pbNLaI8K7xQJ1yZhou6CORYEF +Qwch9mZViRaSrgbPUz+XJ8C2V53O24odiML/+HsSjNNOsdSFjyKjGh69Vy/riXgQ0 +ua+1Thz8pCkJWyZ1WeLvkIGYqhG5HIekpRnUhWTrks+CN5Q3QaITokfL1kVfvMRQJ ALUmfln9nfIYA== Received: from alfajor (69-165-136-52.dsl.teksavvy.com [69.165.136.52]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 04277120352; Tue, 22 Dec 2020 23:00:02 -0500 (EST) From: Stefan Monnier To: haj@posteo.de (Harald =?windows-1252?Q?J=F6rg?=) Subject: Re: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] Message-ID: References: <87sg7xxo0s.fsf@hajtower> Date: Tue, 22 Dec 2020 23:00:01 -0500 In-Reply-To: <87sg7xxo0s.fsf@hajtower> ("Harald =?windows-1252?Q?J=F6rg=22?= =?windows-1252?Q?'s?= message of "Wed, 23 Dec 2020 03:19:15 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.079 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Investigating how to fix this leads to the longer story. There are two > possible approaches: > > 1) use a string-style syntax (generic string) instead of c-style > comments to flag HERE-documents. That way, font-lock picks up the > correct face automagically. > > 2) Keep HERE_docs as c-style comments, but change the face mapping by > injecting a function into font-lock-defaults which applies the > string face to c-style comments. 3) Use `font-lock-syntactic-face-function`? Stefan From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 23 09:38:02 2020 Received: (at 23461) by debbugs.gnu.org; 23 Dec 2020 14:38:02 +0000 Received: from localhost ([127.0.0.1]:52353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks5H7-0001lJ-R7 for submit@debbugs.gnu.org; Wed, 23 Dec 2020 09:38:02 -0500 Received: from mout01.posteo.de ([185.67.36.65]:40632) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks5H5-0001l0-Pu for 23461@debbugs.gnu.org; Wed, 23 Dec 2020 09:38:01 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 34127160062 for <23461@debbugs.gnu.org>; Wed, 23 Dec 2020 15:37:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1608734273; bh=vg8X8DaC9a8GDIIIjLkVYrtZkNBBEO/j4UYn9m4PIvE=; h=From:To:Cc:Subject:Date:From; b=jUTZ8MLfIYOrkqjTD+usoS7zrv3/ysq0C7VK/NK3ldfl1PI5ianJzpu6447VUgMWQ uNFHZUj9oesixonBYL89oPWaLwo91n8siUQcfI8xdNUJHQNJDtXsJ64pnPs09aAh5L rMqBwKB3GrjPaBHenyTBdlUFyyMiHY1RzHLwR5cHqUVXFrFsfVtzN6CBAYK71ajbwY 5bMZH1oP23b+RouA+Zu/P/4zvc0psaPgcicvf0VDpeWIQ2GFpDN21OXf61tcPCXmtu O4Oo7LukYfShgUNoCYyvZ6J+f48ePnHLCS3FCqFmuie56TagGMUKseHPGAkE9eMrV6 unPKyHIScE7cQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D1G5X24jgz6tmB; Wed, 23 Dec 2020 15:37:52 +0100 (CET) From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) To: Stefan Monnier Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] In-Reply-To: (Stefan Monnier's message of "Tue, 22 Dec 2020 23:00:01 -0500") References: <87sg7xxo0s.fsf@hajtower> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Wed, 23 Dec 2020 15:37:51 +0100 Message-ID: <87zh24611c.fsf@hajtower> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain Stefan Monnier writes: >> Investigating how to fix this leads to the longer story. There are two >> possible approaches: >> >> 1) use a string-style syntax (generic string) instead of c-style >> comments to flag HERE-documents. That way, font-lock picks up the >> correct face automagically. >> >> 2) Keep HERE_docs as c-style comments, but change the face mapping by >> injecting a function into font-lock-defaults which applies the >> string face to c-style comments. > > 3) Use `font-lock-syntactic-face-function`? Ah - thanks for this pointer! I wasn't aware of this function, though this feature is already in use in perl-mode.el. This looks like to be an improved variation of 2): HERE-docs remain marked as c-style comments, and `font-lock-syntactic-face-function` is used to display them as strings. A patch for this variation is attached. Tests and test resources are the same as with the first patch, and this patch also contains the same fix for HERE-doc starters with a trailing comment. -- Cheers, haj --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-perl-mode-Display-here-docs-as-strings-instead-of-co.patch Content-Description: Display HERE-docs as strings >From f5025280db960b956e64bd9c1a7049c0fa294c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= Date: Wed, 23 Dec 2020 15:17:27 +0100 Subject: [PATCH] ; perl-mode: Display here-docs as strings instead of comments. * lisp/progmodes/perl-mode.el (perl-font-lock-syntactic-face-function): Declare HERE-docs to be fontified as string. (perl-syntax-propertize-function): Handle comments after a HERE-doc starter line. * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-heredocs): New test (30 should-forms) for various aspects of HERE-documents. Works for CPerl mode, and with the patch also for Perl mode. * test/lisp/progmodes/cperl-mode-resources/here-docs.pl: New file with test cases. --- lisp/progmodes/perl-mode.el | 20 +++- .../cperl-mode-resources/here-docs.pl | 111 ++++++++++++++++++ test/lisp/progmodes/cperl-mode-tests.el | 29 +++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 test/lisp/progmodes/cperl-mode-resources/here-docs.pl diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index fd8a51b5a5..cc3eb4948a 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -324,13 +324,28 @@ perl-syntax-propertize-function ;; disambiguate with the left-bitshift operator. "\\|" perl--syntax-exp-intro-regexp "<<\\(?2:\\sw+\\)\\)" ".*\\(\n\\)") - (4 (let* ((st (get-text-property (match-beginning 4) 'syntax-table)) + (4 (let* ((eol (match-beginning 4)) + (st (get-text-property eol 'syntax-table)) (name (match-string 2)) (indented (match-beginning 1))) (goto-char (match-end 2)) (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0)))) + ;; '>>' occurred in a string, or in a comment. ;; Leave the property of the newline unchanged. st + ;; Before changing the syntax to c-style comment, let's + ;; check whether we are in an end-of-line comment, and + ;; if so, cheat by shifting the comment markers one char + ;; to the left. + (when (nth 4 (save-excursion (syntax-ppss eol))) + (when (equal (car (syntax-after (1- eol))) + (car (string-to-syntax "<"))) + ;; yet another edge case: "#" is the last character + ;; in that line, so there's actually no comment. + (put-text-property (- eol 2) (1- eol) + 'syntax-table (string-to-syntax "<"))) + (put-text-property (1- eol) eol + 'syntax-table (string-to-syntax ">"))) (cons (car (string-to-syntax "< c")) ;; Remember the names of heredocs found on this line. (cons (cons (pcase (aref name 0) @@ -485,6 +500,9 @@ perl-syntax-propertize-special-constructs (defun perl-font-lock-syntactic-face-function (state) (cond + ((and (eq 2 (nth 7 state)) ; c-style comment + (cdr-safe (get-text-property (nth 8 state) 'syntax-table))) ; HERE doc + 'font-lock-string-face) ((and (nth 3 state) (eq ?e (cdr-safe (get-text-property (nth 8 state) 'syntax-table))) ;; This is a second-arg of s{..}{...} form; let's check if this second diff --git a/test/lisp/progmodes/cperl-mode-resources/here-docs.pl b/test/lisp/progmodes/cperl-mode-resources/here-docs.pl new file mode 100644 index 0000000000..39e4fe06ba --- /dev/null +++ b/test/lisp/progmodes/cperl-mode-resources/here-docs.pl @@ -0,0 +1,111 @@ +use 5.020; + +=head1 NAME + +here-docs.pl - resource file for cperl-test-here-docs + +=head1 DESCRIPTION + +This file holds a couple of HERE documents, with a variety of normal +and edge cases. For a formatted view of this description, run: + + (cperl-perldoc "here-docs.pl") + +For each of the HERE documents, the following checks will done: + +=over 4 + +=item * + +All occurrences of the string "look-here" are fontified as +'font-lock-string-face. Note that we deliberately test the face, not +the syntax property: Users won't care for the syntax property, but +they see the face. Different implementations with different syntax +properties have been seen in the past. + +=item * + +Indentation of the line(s) containing "look-here" is 0, i.e. there are no +leading spaces. + +=item * + +Indentation of the following perl statement containing "indent" should +be 0 if the statement contains "noindent", and according to the mode's +continued-statement-offset otherwise. + +=back + +=cut + +# Prologue to make the test file valid without warnings + +my $text; +my $any; +my $indentation; +my $anywhere = 'back again'; + +=head1 The Tests + +=head2 Test Case 1 + +We have two HERE documents in one line with different quoting styles. + +=cut + +## test case + +$text = <<"HERE" . <<'THERE' . $any; +#look-here and +HERE +$tlook-here and +THERE + +my $noindent = "This should be left-justified"; + +=head2 Test case 2 + +A HERE document followed by a continuation line + +=cut + +## test case + +$text = <) id 1ks75j-0000vx-PU for submit@debbugs.gnu.org; Wed, 23 Dec 2020 11:34:24 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47236) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks75g-0000vj-Pk for 23461@debbugs.gnu.org; Wed, 23 Dec 2020 11:34:22 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 2E5E980056; Wed, 23 Dec 2020 11:34:15 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id B0CBB80853; Wed, 23 Dec 2020 11:34:13 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1608741253; bh=xtFHDYmo97/xDq9zf513cVLMieP8rWMA2+BZK7fcx1Y=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Lf3W4A8IkuWZ5HWg0Ts3p0GGLcmfeyiiHU8J6DKy2ZtWb0yUBDNokTsnX42WIHVtx hu86jjK5KTM4O3O4fIvf+/jF3oLFuCYyeJ7IXuGuvGtRcfxtJ4MIl98syYHh/vLzcn Cnf/W2CXDanqX9Y6wLsfw7zRXph87DCRnZhcwYtUCk+0WRKl3ExcUyEJekms+vLrMW +2G/y9SH5C3iPEED4vSBLVdNnmc+wFa/nkSmhLw23pktta4qRAJ/HxkUW1mKoq5VtM fS4k6o/xTemPQFV3tDh+qlKLyjTPixFtg4bEx+O2s82hoZZCGAg53qehSSPA9GXJjb 9anb0H9+5WiDg== Received: from alfajor (69-165-136-52.dsl.teksavvy.com [69.165.136.52]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5155F1204EB; Wed, 23 Dec 2020 11:34:13 -0500 (EST) From: Stefan Monnier To: haj@posteo.de (Harald =?windows-1252?Q?J=F6rg?=) Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] Message-ID: References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> Date: Wed, 23 Dec 2020 11:34:12 -0500 In-Reply-To: <87zh24611c.fsf@hajtower> ("Harald =?windows-1252?Q?J=F6rg=22?= =?windows-1252?Q?'s?= message of "Wed, 23 Dec 2020 15:37:51 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.074 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > This looks like to be an improved variation of 2): HERE-docs remain > marked as c-style comments, and `font-lock-syntactic-face-function` is > used to display them as strings. > > A patch for this variation is attached. Looks good, thanks. See nitpicks below, Stefan > (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0)))) > + ;; '>>' occurred in a string, or in a comment. > ;; Leave the property of the newline unchanged. Is think this `>>` is a type for `<<`, or am I missing something? > + ;; Before changing the syntax to c-style comment, let's > + ;; check whether we are in an end-of-line comment, and > + ;; if so, cheat by shifting the comment markers one char > + ;; to the left. I jump straight to reading the code before reading your email's text and it took me a bit of time to understand what this was about. I think part of the reason is the "we are in an end-of-line comment" since this is actually not about the case where the "<<" (which is where "we" are at this moment, in my mind) is inside a comment. So, I think the comment would be better if it just gave a straight example, like ;; Beware of `foo <<'BAR' #baz` because ;; the newline needs to close the comment ;; and can't be used to start the here-doc. Also rather than "shifting the comment markers one char to the left" I'd just say that "we terminate the comment *just before* the newline". > + (when (nth 4 (save-excursion (syntax-ppss eol))) > + (when (equal (car (syntax-after (1- eol))) > + (car (string-to-syntax "<"))) This is a pessimistic test, because it will misfire when you have foo <<'BAR' #baz# I think we should compare (1- eol) with (nth 8 (syntax-ppss eol)) instead. > + ;; yet another edge case: "#" is the last character > + ;; in that line, so there's actually no comment. > + (put-text-property (- eol 2) (1- eol) > + 'syntax-table (string-to-syntax "<"))) Indeed, terminating the comment just before the newline is a problem if "just before the newline" is the comment starter. I see that in that case, you mark the char before the # but that can also be a problem with things like: foo <<'BAR' "baz"# An alternative is to leave the comment alone and start the heredoc just after the newline instead (that approach suffers from the fact that we need to be careful we don't accidentally throw away that `syntax-table` text property when the next line is edited. We can do that using the `syntax-multiline` text property). > (defun perl-font-lock-syntactic-face-function (state) > (cond > + ((and (eq 2 (nth 7 state)) ; c-style comment > + (cdr-safe (get-text-property (nth 8 state) 'syntax-table))) ; HERE doc > + 'font-lock-string-face) I think some people won't like the string-face property for it. How 'bout we (require 'sh-script) and use the `sh-heredoc` face? Stefan From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 23 13:46:29 2020 Received: (at 23461) by debbugs.gnu.org; 23 Dec 2020 18:46:29 +0000 Received: from localhost ([127.0.0.1]:54163 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks99Z-0006O7-7I for submit@debbugs.gnu.org; Wed, 23 Dec 2020 13:46:29 -0500 Received: from mout02.posteo.de ([185.67.36.66]:41019) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks99W-0006Nv-Fa for 23461@debbugs.gnu.org; Wed, 23 Dec 2020 13:46:27 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id BFD1B2400FD for <23461@debbugs.gnu.org>; Wed, 23 Dec 2020 19:46:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1608749180; bh=7fmv/0G0zpESJibzQu3K8gYXAoePqFJb2iF7vZ4ias4=; h=From:To:Cc:Subject:Date:From; b=ncC7VsyGZASY8JF2qRJz+Sgw8hLe1BA939byxJ/HBu2khXw8bNbRbO1OPq8zducWT 8uZqrO3aoje7F4i0lDBlnnqivCVGUsrk0do0hJhMdasaGUg4cZKeok73V8ch2WNv2w oU8ryzfq4BnkT1lHeuU3VXaVp3bz6YxXnmGrg3QbrRu7nzeqcjmfTXYbVuVRKuoyrp hZRcGgdHfRSI9JJxF5Hr67ZS7nSmf/Ss3viFg5uTmwP0ZlyI8o8nXnpAWAPd7ed5aJ 1eTxcYhvzQ30UqeDWaVxGKL/gokStgXv9xc7LtvgaeipMkUW1Oq36m47jBQdweq36H TlyuueB7zu5ug== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D1McC71fDz6tmB; Wed, 23 Dec 2020 19:46:19 +0100 (CET) From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) To: Stefan Monnier Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] In-Reply-To: (Stefan Monnier's message of "Wed, 23 Dec 2020 11:34:12 -0500") References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Wed, 23 Dec 2020 19:46:19 +0100 Message-ID: <87r1ng5pj8.fsf@hajtower> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Stefan Monnier writes: >> This looks like to be an improved variation of 2): HERE-docs remain >> marked as c-style comments, and `font-lock-syntactic-face-function` is >> used to display them as strings. >> >> A patch for this variation is attached. > > Looks good, thanks. > See nitpicks below, Many thanks for your review! >> (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0)))) >> + ;; '>>' occurred in a string, or in a comment. >> ;; Leave the property of the newline unchanged. > > Is think this `>>` is a type for `<<`, or am I missing something? Ouch. That is a typo, of course. *I* have missed something. >> + ;; Before changing the syntax to c-style comment, let's >> + ;; check whether we are in an end-of-line comment, and >> + ;; if so, cheat by shifting the comment markers one char >> + ;; to the left. > > I jump straight to reading the code before reading your email's text and > it took me a bit of time to understand what this was about. > I think part of the reason is the "we are in an end-of-line comment" > since this is actually not about the case where the "<<" (which is > where "we" are at this moment, in my mind) is inside a comment. > So, I think the comment would be better if it just gave a straight > example, like > > ;; Beware of `foo <<'BAR' #baz` because > ;; the newline needs to close the comment > ;; and can't be used to start the here-doc. That's better, thank you! > Also rather than "shifting the comment markers one char to the left" > I'd just say that "we terminate the comment *just before* the newline". >> + (when (nth 4 (save-excursion (syntax-ppss eol))) >> + (when (equal (car (syntax-after (1- eol))) >> + (car (string-to-syntax "<"))) > > This is a pessimistic test, because it will misfire when you have > > foo <<'BAR' #baz# > > I think we should compare (1- eol) with (nth 8 (syntax-ppss eol)) > instead. You are right. I'm still not very experienced with this syntax stuff, as it turnes out. In hindsight it is clear that a "#" will still be a comment starter, even if it is already in a comment. >> + ;; yet another edge case: "#" is the last character >> + ;; in that line, so there's actually no comment. >> + (put-text-property (- eol 2) (1- eol) >> + 'syntax-table (string-to-syntax "<"))) > > Indeed, terminating the comment just before the newline is a problem if > "just before the newline" is the comment starter. I see that in that > case, you mark the char before the # but that can also be a problem with > things like: > > foo <<'BAR' "baz"# ...or, as I've discovered in the meantime, also bad, foo << BAR# foo << BAR;# (The latter breaks indentation after the HERE-doc because the ";" became a comment) So, back to the drawing board. If that edge case of an "empty comment" is just ignored, then the single # loses its comment-face (that is, by the way, the treatment of HERE-docs in sh-script.el), which is ugly but as far as I can tell harmless. Maybe this can be covered by assigning a font-lock-face property to these single comment starters... I'll check that. > An alternative is to leave the comment alone and start the heredoc just > after the newline instead (that approach suffers from the fact that we > need to be careful we don't accidentally throw away that `syntax-table` > text property when the next line is edited. We can do that using the > `syntax-multiline` text property). This is similar to how CPerl mode does it, and the fact that text properties can get lost when text is edited brought me here. The bugs Bug#14343 and Bug#28962 in CPerl mode come from lost text properties, and Bug#24101 is a consequence of starting a syntax property with the first character. So, I wanted to check how Perl mode covers that. I'll check whether `syntax-multiline` can add some more robustness. This points to the deeper problem: In Perl, we have some occasions where one character has two different roles. A line end ends a comment *and* starts a here-doc, and in s/foo/bar/ge the middle slash ends the search string *and* starts the replacement string. The programming modes seem to treat this by distributing the roles on two neighbouring characters, which comes with some ... inaccuracies if the characters nearby have roles of their own. >> (defun perl-font-lock-syntactic-face-function (state) >> (cond >> + ((and (eq 2 (nth 7 state)) ; c-style comment >> + (cdr-safe (get-text-property (nth 8 state) 'syntax-table))) ; HERE doc >> + 'font-lock-string-face) > > I think some people won't like the string-face property for it. > How 'bout we (require 'sh-script) and use the `sh-heredoc` face? I'd hesitate to do that. I think that in shell-script mode it is well justified to use a different face for HERE-docs, but in Perl it isn't. In Perl, a HERE-doc is just a string and can be used wherever a string can be used. So, string-face seems quite appropriate. In Shell, a HERE-doc is sort of an I/O redirection. You can't, for example, assign a HERE-doc to a shell variable. So, a different face seems appropriate. BTW: CPerl also mode uses string-face for HERE-docs. -- Cheers, haj From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 23 14:04:38 2020 Received: (at 23461) by debbugs.gnu.org; 23 Dec 2020 19:04:38 +0000 Received: from localhost ([127.0.0.1]:54183 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks9R8-0006qI-AS for submit@debbugs.gnu.org; Wed, 23 Dec 2020 14:04:38 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:36112) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks9R6-0006q3-2p for 23461@debbugs.gnu.org; Wed, 23 Dec 2020 14:04:37 -0500 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 8F98D100486; Wed, 23 Dec 2020 14:04:30 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D36B6100410; Wed, 23 Dec 2020 14:04:28 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1608750268; bh=G+j6VGAlP+n6Ig6x/sL/f5LBdKMwb9ONUY4bTXN89/E=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Rp1ZAyNK6cWtkaPPBg7T2YydSaBe7Eoy5llInFJafx0vK8UDXRf9Tkr/c240RBRj+ 6o+GU45hSaKF6TtCZPjWbsPstm77wNqWLNJQStQgr7V+ExWnwZKoVD0lckLkMtI6LC 5d8I3CG3JRPPFjV8Zo/JXjXb5J96AWBTwtUuz6nqpEaRkl5uFNv/3DoZo7kPx95TEp 6JZVkHJZD5hMs1OLWPawUt4Z7KUOvC54kowqdSv0SnbNf0kucuiK697wEB5rFpSGp5 +BCcTMnnPOudkLXJAtXBUummLltVDHF+FvX0mgkQOWph3XeIua4TNKGTpXE5djn6Hf rPXD0G4wzjnPw== Received: from alfajor (69-165-136-52.dsl.teksavvy.com [69.165.136.52]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7A0F4120409; Wed, 23 Dec 2020 14:04:28 -0500 (EST) From: Stefan Monnier To: haj@posteo.de (Harald =?windows-1252?Q?J=F6rg?=) Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] Message-ID: References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> <87r1ng5pj8.fsf@hajtower> Date: Wed, 23 Dec 2020 14:04:27 -0500 In-Reply-To: <87r1ng5pj8.fsf@hajtower> ("Harald =?windows-1252?Q?J=F6rg=22?= =?windows-1252?Q?'s?= message of "Wed, 23 Dec 2020 19:46:19 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.091 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> Indeed, terminating the comment just before the newline is a problem if >> "just before the newline" is the comment starter. I see that in that >> case, you mark the char before the # but that can also be a problem with >> things like: >> >> foo <<'BAR' "baz"# > > ...or, as I've discovered in the meantime, also bad, > > foo << BAR# > > foo << BAR;# > > (The latter breaks indentation after the HERE-doc because the ";" > became a comment) > > So, back to the drawing board. If that edge case of an "empty comment" > is just ignored, then the single # loses its comment-face (that is, by > the way, the treatment of HERE-docs in sh-script.el), which is ugly but > as far as I can tell harmless. Maybe this can be covered by assigning a > font-lock-face property to these single comment starters... I'll check > that. I suspect that shifting the "here-doc start" to the next line (in the "#\n" case only) and placing a `syntax-multiline` property on all three chars (#, \n, and the first char of the next line) will be our least bad option. > This points to the deeper problem: In Perl, we have some occasions where > one character has two different roles. A line end ends a comment *and* > starts a here-doc, and in s/foo/bar/ge the middle slash ends the search > string *and* starts the replacement string. The programming modes seem > to treat this by distributing the roles on two neighbouring characters, > which comes with some ... inaccuracies if the characters nearby have > roles of their own. Yes, this doesn't occur very often, but when it does there's no really satisfactory solution currently. I also encountered such situations in a few other modes (sorry, can't remember where, offhand). I've often thought about trying to add some way to "cram several syntax elements on a single character" or have some way to place an arbitrary "state change function" on a character which would take an PPSS and return a new one). But then I end up concluding that a completely new system would be preferable (e.g. one based on a DFA so that we don't need ad-hoc "multi-char comment markers" and so that fewer cases need to resort to text-property crutches). >>> (defun perl-font-lock-syntactic-face-function (state) >>> (cond >>> + ((and (eq 2 (nth 7 state)) ; c-style comment >>> + (cdr-safe (get-text-property (nth 8 state) 'syntax-table))) ; HERE doc >>> + 'font-lock-string-face) >> >> I think some people won't like the string-face property for it. >> How 'bout we (require 'sh-script) and use the `sh-heredoc` face? > > I'd hesitate to do that. I think that in shell-script mode it is well > justified to use a different face for HERE-docs, but in Perl it isn't. > In Perl, a HERE-doc is just a string and can be used wherever a string > can be used. So, string-face seems quite appropriate. In Shell, a > HERE-doc is sort of an I/O redirection. You can't, for example, assign > a HERE-doc to a shell variable. So, a different face seems appropriate. > > BTW: CPerl also mode uses string-face for HERE-docs. I must admit I don't use Perl very much these days, but when I used it, I used it as a "better shell", so I thought of Perl's here docs in exactly the same way as sh's here docs. So maybe a compromise is to add a new `perl-heredoc` face and make it inherit from `font-lock-string-face` by default? Stefan From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 23 14:06:11 2020 Received: (at 23461) by debbugs.gnu.org; 23 Dec 2020 19:06:11 +0000 Received: from localhost ([127.0.0.1]:54188 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks9Sc-0006sx-Rp for submit@debbugs.gnu.org; Wed, 23 Dec 2020 14:06:11 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:53043) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks9Sb-0006si-6C for 23461@debbugs.gnu.org; Wed, 23 Dec 2020 14:06:09 -0500 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 1969B100486; Wed, 23 Dec 2020 14:06:04 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 94778100410; Wed, 23 Dec 2020 14:06:02 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1608750362; bh=qvFioYkX38Id6S/S3mgDviknP477KSI5QLJfJfw0EZk=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=L40VF9luYEkYvm4CYy/N9804yWyryC/KZ66SkusJ2hcdJcx/oRQMhDEwP1EbprBOl sTBSyeADKafePoXLulqRUJbv5AFG6nfZi4VqZc920CqlyA/VaGaabV60F1Lk/lYMMt Z6JhKjoOWuiBdcHofCi2Tht9TkbDx4+3vjIbAnLPLg97NgfCu3mjS+RGra28YJPIkK T9SQ3Zv4+mCt7ZHeAwdMNuWuEb2BQIkkYh8q57JEQmSxh0O5pk7f5tCbLCE8CJAqXc phnnzc4I8xY6vdbkmjchrfHU1ODry3egae9+mF9mCcIepazdrEwcPua2cEgM2s2fS7 49uV8MzWCQOQA== Received: from alfajor (69-165-136-52.dsl.teksavvy.com [69.165.136.52]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 27A9B120340; Wed, 23 Dec 2020 14:06:02 -0500 (EST) From: Stefan Monnier To: haj@posteo.de (Harald =?windows-1252?Q?J=F6rg?=) Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] Message-ID: References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> <87r1ng5pj8.fsf@hajtower> Date: Wed, 23 Dec 2020 14:06:01 -0500 In-Reply-To: (Stefan Monnier's message of "Wed, 23 Dec 2020 14:04:27 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.091 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > I suspect that shifting the "here-doc start" to the next line (in the > "#\n" case only) and placing a `syntax-multiline` property on all three > chars (#, \n, and the first char of the next line) will be our least > bad option. BTW, the `syntax-multiline` property only "works" if/after you add `syntax-propertize-multiline` to `syntax-propertize-extend-region-functions`. Stefan From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 24 10:29:48 2020 Received: (at 23461) by debbugs.gnu.org; 24 Dec 2020 15:29:48 +0000 Received: from localhost ([127.0.0.1]:55909 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksSYm-0000st-8Y for submit@debbugs.gnu.org; Thu, 24 Dec 2020 10:29:48 -0500 Received: from mout02.posteo.de ([185.67.36.66]:58683) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksSYj-0000sZ-6B for 23461@debbugs.gnu.org; Thu, 24 Dec 2020 10:29:46 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id D1F392400FB for <23461@debbugs.gnu.org>; Thu, 24 Dec 2020 16:29:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1608823778; bh=0oezpeFyuYr1k1aXzXOM4SsXlhioCkVu+tJCLcyHaRc=; h=From:To:Cc:Subject:Date:From; b=jb/BKUTN1hHL6eyCweeygkVGAg5Chbm407nhromBdM/ZwN0ZRbLeJG7YsjaoAnQcq KWFN9DdUGhQXwRgJpU3jjqxuOVTb80/gIUa89OiSgYtz0QNf/AUuqiN7IxToZEOz6S hIgCRsctzWty5JIiSRxxN44EKPiBNKjYVBZcmiwickS6LEWcsw+ubPl3maB3w1xPL0 o6/sGW7VRHLOD/FqBTPIi5BKLGoUseyHCIVo0x+QCGCn8a+EFjBAy1AdVTS/bvgGwG XdrBfFx+n+ItCmGEsKoHoP1MBqvtd5H9IIit8BztPuXLcAtLprlA2oCqzDjzWkj7xk Kxdubbri7UoeA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D1vBp189kz9rxL; Thu, 24 Dec 2020 16:29:38 +0100 (CET) From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) To: Stefan Monnier Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] In-Reply-To: (Stefan Monnier's message of "Wed, 23 Dec 2020 14:04:27 -0500") References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> <87r1ng5pj8.fsf@hajtower> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Thu, 24 Dec 2020 16:29:37 +0100 Message-ID: <87r1nfkyse.fsf@hajtower> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Stefan Monnier writes: > I suspect that shifting the "here-doc start" to the next line (in the > "#\n" case only) and placing a `syntax-multiline` property on all three > chars (#, \n, and the first char of the next line) will be our least > bad option. I have some doubts here regarding the effort and the side effects.... The current regexp for here-doc detection ends with the newline, so either it needs to capture that first char of the next line, or the property needs to be explicitly set. Also, the regexp in the following rule ("\\(?:$\\)\\s<" would no longer fire to call `perl-syntax-propertize-special-constructs`. Finally, that first character of the here-doc would fail to pass the "(eq 2 (nth 7 state))" test which has been introduced to fix the "current" bug#23461 in `perl-font-lock-syntactic-face-function`; the same test is used in some other places. That's a lot of special cases to handle, for an edge case like a "#" starting a comment in the last column. As for side effects, it would break word movement for the first word of within the here-doc, like it has been observed for the replacement string of a regexp in Bug#24101. While that's not a big deal, I found it pretty stunning. I understand now why this is happening, but I've no fix. Compared to that, just ignoring that special case is easy. It has no non-local side effects. The only downside is that in this special case a comment starter "#" is converted to a comment terminator "#" - so left unfontified. I could easily live with that. > [...] > I must admit I don't use Perl very much these days, but when I used it, > I used it as a "better shell", so I thought of Perl's here docs in > exactly the same way as sh's here docs. > > So maybe a compromise is to add a new `perl-heredoc` face and make it > inherit from `font-lock-string-face` by default? That's a possibility, sure. -- Cheers, haj From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 24 12:32:23 2020 Received: (at 23461) by debbugs.gnu.org; 24 Dec 2020 17:32:24 +0000 Received: from localhost ([127.0.0.1]:55991 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksUTP-0003xO-MW for submit@debbugs.gnu.org; Thu, 24 Dec 2020 12:32:23 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:32954) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksUTO-0003xB-Ju for 23461@debbugs.gnu.org; Thu, 24 Dec 2020 12:32:23 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id C9FD2440649; Thu, 24 Dec 2020 12:32:16 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id B158B44061A; Thu, 24 Dec 2020 12:32:15 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1608831135; bh=7pV0nSCpYR/C8xaSw3C9f/QF2FuXwcnmQP7MX3II61E=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=hkRNuZy3OO+KpxbAANX5cGvgSIig/lRf+3lMvoWGkcY92VRexEcJ4GM7nsCNhAaFK /1XgsBu6mmo3MffuH4DZl9jqmbi9U42qVFJc88ImxNCkZg3UNGqcHqBclXlekOp2ch ZbMmRv381q/bQiv74yJh69niLk5o9u5yilDFdCReoEwwFwjpaadILbg8zOpBujEs8l j/X+zxDOVcPWg0Zu2Bz/dwTPwnI6zqo8M86VEP9OfxdAx6ZiU6eZ1gCAHbvocsePau fAy7Y5297bE8EXMx4m/EjoEn69UVGrZmp1iS8qftFgd57ZiizDqn2ZESjZUD705jEB A4AExHLZqPK3Q== Received: from alfajor (unknown [104.247.243.191]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5E705120124; Thu, 24 Dec 2020 12:32:15 -0500 (EST) From: Stefan Monnier To: haj@posteo.de (Harald =?windows-1252?Q?J=F6rg?=) Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] Message-ID: References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> <87r1ng5pj8.fsf@hajtower> <87r1nfkyse.fsf@hajtower> Date: Thu, 24 Dec 2020 12:32:14 -0500 In-Reply-To: <87r1nfkyse.fsf@hajtower> ("Harald =?windows-1252?Q?J=F6rg=22?= =?windows-1252?Q?'s?= message of "Thu, 24 Dec 2020 16:29:37 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.118 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > I have some doubts here regarding the effort and the side effects.... No doubt. Stefan From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 04 18:44:06 2021 Received: (at 23461) by debbugs.gnu.org; 4 Jan 2021 23:44:06 +0000 Received: from localhost ([127.0.0.1]:60589 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwZWA-0001Tq-2h for submit@debbugs.gnu.org; Mon, 04 Jan 2021 18:44:06 -0500 Received: from mout02.posteo.de ([185.67.36.66]:58461) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwZW7-0001TC-75 for 23461@debbugs.gnu.org; Mon, 04 Jan 2021 18:44:04 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 7499B2400FB for <23461@debbugs.gnu.org>; Tue, 5 Jan 2021 00:43:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1609803836; bh=ps90+8o1JhiTrcA8K70CX4qWFh7IqnAJyKVsUrnU0vk=; h=From:To:Cc:Subject:Date:From; b=SBBdiwtOyO/zoGS1jb53aioz69/decMZiKBC4vutO2oSC7p7s7LTN7nWF8cC65fjJ uM5AgFKRk3P4EN1FGex70SJO8y+HbENxMVbzHM5ghWNGTeHmIzyIt1b9pvBlf5Ufe0 JKOTMrDR346Mxfj6Bp1NX6yBEvjhf5NO6a9AOIsCk2rgSVKWURFfpCZ26macutpWCn UBFBqSKJdaSc9x4HU8FVcJEJHqkIiKXQtrdXBrfeuac1yyXvy3niIvoQOrd+67Fu0y WEvPVASDvU/W0JP5Alz/XnWaKFJGer+TJSUs+B8zyskaR7llu96fyVikmDR6C6thfN oKMOzL0WaompQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D8sf34Vryz9rxG; Tue, 5 Jan 2021 00:43:55 +0100 (CET) From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) To: 23461@debbugs.gnu.org Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] In-Reply-To: (Stefan Monnier's message of "Thu, 24 Dec 2020 12:32:14 -0500") References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> <87r1ng5pj8.fsf@hajtower> <87r1nfkyse.fsf@hajtower> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Tue, 05 Jan 2021 00:43:55 +0100 Message-ID: <87czyk1d50.fsf@hajtower> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain Stefan Monnier writes: >> I have some doubts here regarding the effort and the side effects.... > > No doubt. :) In the meantime I found that just ignoring the edge case of a lone "#" at the end of a line starting HERE-docs breaks indentation after the HERE-doc, so I no longer consider this as a valid option. I just failed to get all cases covered when the HERE-doc starter is moved to the next line. So here's another attempt to show HERE-docs with their own face, treat "normal" line-end comments correctly, and work around lines which end with the comment starter. It is a kludge, but maybe for such a rare edge case a kludge is acceptable. The trick: The lone "#" is now syntaxified as "whitespace" and font-lock-faced as comment. This is ugly, but also well-contained in the offending line, so should not have unwanted effects at a distance. The tests are designed for, and pass, for both Perl mode and CPerl mode. -- Cheers, haj --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-perl-mode-Display-here-docs-as-strings-instead-of-co.patch Content-Description: perl-mode: Display HERE-docs with their own face >From 9a19e5991b33db7b8a71b653078f2a3c0a7afd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= Date: Tue, 5 Jan 2021 00:09:02 +0100 Subject: [PATCH] ; perl-mode: Display here-docs as strings instead of comments * lisp/progmodes/perl-mode.el (perl-syntax-propertize-function): Handle HERE doc starter lines ending in a comment. (perl-heredoc): New face for HERE docs, inheriting from font-lock-string-face. (perl-font-lock-syntactic-face-function): Apply the new face to HERE docs (Bug#23461). * test/lisp/progmodes/cperl-mode-tests.el (cperl-test--run-bug-10483): Skip for Perl mode. The test explicitly calls a function of CPerl mode. * test/lisp/progmodes/cperl-mode-resources/here-docs.pl: New tests for HERE docs, common to Perl mode and CPerl mode. --- lisp/progmodes/perl-mode.el | 29 +++- .../cperl-mode-resources/here-docs.pl | 143 ++++++++++++++++++ test/lisp/progmodes/cperl-mode-tests.el | 31 ++++ 3 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 test/lisp/progmodes/cperl-mode-resources/here-docs.pl diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index ec20b01a0f..2a2a4978c6 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -324,13 +324,33 @@ perl-syntax-propertize-function ;; disambiguate with the left-bitshift operator. "\\|" perl--syntax-exp-intro-regexp "<<\\(?2:\\sw+\\)\\)" ".*\\(\n\\)") - (4 (let* ((st (get-text-property (match-beginning 4) 'syntax-table)) + (4 (let* ((eol (match-beginning 4)) + (st (get-text-property eol 'syntax-table)) (name (match-string 2)) (indented (match-beginning 1))) (goto-char (match-end 2)) (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0)))) + ;; '<<' occurred in a string, or in a comment. ;; Leave the property of the newline unchanged. st + ;; Beware of `foo <<'BAR' #baz` because + ;; the newline needs to start the here-doc + ;; and can't be used to close the comment. + (let ((eol-state (save-excursion (syntax-ppss eol)))) + (when (nth 4 eol-state) + (if (/= (1- eol) (nth 8 eol-state)) + ;; make the last char of the comment closing it + (put-text-property (1- eol) eol + 'syntax-table (string-to-syntax ">")) + ;; In `foo <<'BAR' #` the # is the last character + ;; before eol and can't both open and close the + ;; comment. Workaround: disguise the "#" as + ;; whitespace and fontify it as a comment. + (put-text-property (1- eol) eol + 'syntax-table (string-to-syntax "-")) + (put-text-property (1- eol) eol + 'font-lock-face + 'font-lock-comment-face)))) (cons (car (string-to-syntax "< c")) ;; Remember the names of heredocs found on this line. (cons (cons (pcase (aref name 0) @@ -483,8 +503,15 @@ perl-syntax-propertize-special-constructs ;; as twoarg). (perl-syntax-propertize-special-constructs limit))))))))) +(defface perl-heredoc + '((t (:inherit font-lock-string-face))) + "The face for here-documents. Inherits from font-lock-string-face.") + (defun perl-font-lock-syntactic-face-function (state) (cond + ((and (eq 2 (nth 7 state)) ; c-style comment + (cdr-safe (get-text-property (nth 8 state) 'syntax-table))) ; HERE doc + 'perl-heredoc) ((and (nth 3 state) (eq ?e (cdr-safe (get-text-property (nth 8 state) 'syntax-table))) ;; This is a second-arg of s{..}{...} form; let's check if this second diff --git a/test/lisp/progmodes/cperl-mode-resources/here-docs.pl b/test/lisp/progmodes/cperl-mode-resources/here-docs.pl new file mode 100644 index 0000000000..8af4625fff --- /dev/null +++ b/test/lisp/progmodes/cperl-mode-resources/here-docs.pl @@ -0,0 +1,143 @@ +use 5.020; + +=head1 NAME + +here-docs.pl - resource file for cperl-test-here-docs + +=head1 DESCRIPTION + +This file holds a couple of HERE documents, with a variety of normal +and edge cases. For a formatted view of this description, run: + + (cperl-perldoc "here-docs.pl") + +For each of the HERE documents, the following checks will done: + +=over 4 + +=item * + +All occurrences of the string "look-here" are fontified correcty. +Note that we deliberately test the face, not the syntax property: +Users won't care for the syntax property, but they see the face. +Different implementations with different syntax properties have been +seen in the past. + +=item * + +Indentation of the line(s) containing "look-here" is 0, i.e. there are no +leading spaces. + +=item * + +Indentation of the following perl statement containing "indent" should +be 0 if the statement contains "noindent", and according to the mode's +continued-statement-offset otherwise. + +=back + +=cut + +# Prologue to make the test file valid without warnings + +my $text; +my $any; +my $indentation; +my $anywhere = 'back again'; +my $noindent; + +=head1 The Tests + +=head2 Test Case 1 + +We have two HERE documents in one line with different quoting styles. + +=cut + +## test case + +$text = <<"HERE" . <<'THERE' . $any; +#look-here and +HERE +$tlook-here and +THERE + +$noindent = "This should be left-justified"; + +=head2 Test case 2 + +A HERE document followed by a continuation line + +=cut + +## test case + +$text = <) id 1kwiQ7-00067V-TT for submit@debbugs.gnu.org; Tue, 05 Jan 2021 04:14:28 -0500 Received: from quimby.gnus.org ([95.216.78.240]:41280) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwiQ6-00067E-Lj for 23461@debbugs.gnu.org; Tue, 05 Jan 2021 04:14:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID :In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wBVern7me//aed3vnvwdRyuqhqHMYHMQdxRjimcaCEQ=; b=BDN27CC3opZbL7NwWDmKnNWpoU cOlRfv0iNuIcp1FHQnzGBtjMUJSf7+TkD5Q0Wd7D9i9Mc+KhhF2E2lQF/T2qFT3MnTadvZDN5ScDy 6LDsnoguATZAmSVLubTF9AJRA4d9wbw9Cs1nmOjePlJ7CLUQrVZ2uag60R/cEBPU8CM4=; Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwiPv-0006yx-Dn; Tue, 05 Jan 2021 10:14:19 +0100 From: Lars Ingebrigtsen To: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> <87r1ng5pj8.fsf@hajtower> <87r1nfkyse.fsf@hajtower> <87czyk1d50.fsf@hajtower> X-Now-Playing: Big Audio Dynamite's _This Is Big Audio Dynamite_: "Bad" Date: Tue, 05 Jan 2021 10:14:13 +0100 In-Reply-To: <87czyk1d50.fsf@hajtower> ("Harald =?utf-8?Q?J=C3=B6rg=22's?= message of "Tue, 05 Jan 2021 00:43:55 +0100") Message-ID: <878s973fve.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: haj@posteo.de (Harald Jörg) writes: > The trick: The lone "#" is now syntaxified as "whitespace" and > font-lock-faced as comment. This is ugly, but also well-contained in > the offending line, so should not have unwanted effects at a d [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org, Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) haj@posteo.de (Harald J=C3=B6rg) writes: > The trick: The lone "#" is now syntaxified as "whitespace" and > font-lock-faced as comment. This is ugly, but also well-contained in > the offending line, so should not have unwanted effects at a distance. > > The tests are designed for, and pass, for both Perl mode and CPerl mode. Thanks; applied to Emacs 28. However, the cperl tests failed -- I stuck a (require 'perl-mode) into the test, and that made it work. I don't know whether that's the proper solution here, though -- please have a look. --=20 (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 04:14:39 2021 Received: (at control) by debbugs.gnu.org; 5 Jan 2021 09:14:39 +0000 Received: from localhost ([127.0.0.1]:40785 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwiQJ-00067x-7s for submit@debbugs.gnu.org; Tue, 05 Jan 2021 04:14:39 -0500 Received: from quimby.gnus.org ([95.216.78.240]:41294) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwiQI-00067j-1N for control@debbugs.gnu.org; Tue, 05 Jan 2021 04:14:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=mjx8MAjVSvmsRpX1xnuVufs02qlZY5eAoV1e7KJG+P4=; b=H6bTboj0qRLKjfd7YesgGB7CKx HDb9X1PvloLhKA6a0Hijdkz/R2NVZ18sTPwRZxqdsG5rRrcH1qBgizXoH5Zlh6495/QaTCzignmwl kDN8c64k7w/K+ZWJhWBAnk6lTDLuj0ZX3q4UF0ZKxNkOLBeuMycAVbeP7PEOo3QiRC+0=; Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwiQA-0006z8-Fg for control@debbugs.gnu.org; Tue, 05 Jan 2021 10:14:32 +0100 Date: Tue, 05 Jan 2021 10:14:29 +0100 Message-Id: <877dor3fuy.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #23461 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: tags 23461 fixed close 23461 28.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 23461 fixed close 23461 28.1 quit From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 07:30:48 2021 Received: (at 23461) by debbugs.gnu.org; 5 Jan 2021 12:30:48 +0000 Received: from localhost ([127.0.0.1]:41031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwlU7-0006TO-Sc for submit@debbugs.gnu.org; Tue, 05 Jan 2021 07:30:48 -0500 Received: from mout02.posteo.de ([185.67.36.66]:52817) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwlU5-0006M4-Qn for 23461@debbugs.gnu.org; Tue, 05 Jan 2021 07:30:46 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 7AE7F240100 for <23461@debbugs.gnu.org>; Tue, 5 Jan 2021 13:30:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1609849838; bh=Jkq0+2kJghCok+raccwlCPMJAtWK/TqthMirxfDajMg=; h=From:To:Cc:Subject:Date:From; b=GUHvw38tBHV80EycZCRLfF+RcOOB6npayiP5D15YhA3AlcIdMlrTLgmHXn4tZghUP ZSNlbA7WHKFjt2cC1xJUPxcHGsnkdAdFf462ps62R/7fYop/ZNfKFFnBb7gxlPVZ4n SrTyKAjFY+s2XqwDnQ1G4w40bH8wMjUrJEz4vlLBXktTKzVKlm7Pf4IjAUDr2yVznL ph/WQZe86mpcoykkVky8l0cq60nc2N0AFSNCIFj29R70ZtML6b21+i/Qb19MPonRsT K9i8bfj17bxCUcug2DL7Qde5O651rfOviAvrppnIB/M96qBMjB8i5lT5CdhV3250it lk+MzIwotLyvg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D9Bfj3PQ9z9rxQ; Tue, 5 Jan 2021 13:30:37 +0100 (CET) From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) To: Lars Ingebrigtsen Subject: Re: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] In-Reply-To: <878s973fve.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 05 Jan 2021 10:14:13 +0100") References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> <87r1ng5pj8.fsf@hajtower> <87r1nfkyse.fsf@hajtower> <87czyk1d50.fsf@hajtower> <878s973fve.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Tue, 05 Jan 2021 13:30:36 +0100 Message-ID: <875z4befbn.fsf@hajtower> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 23461 Cc: 23461@debbugs.gnu.org, Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Lars Ingebrigtsen writes: > haj@posteo.de (Harald J=C3=B6rg) writes: > >> The trick: The lone "#" is now syntaxified as "whitespace" and >> font-lock-faced as comment. This is ugly, but also well-contained in >> the offending line, so should not have unwanted effects at a distance. >> >> The tests are designed for, and pass, for both Perl mode and CPerl mode. > > Thanks; applied to Emacs 28. However, the cperl tests failed -- I stuck > a (require 'perl-mode) into the test, and that made it work. I don't > know whether that's the proper solution here, though -- please have a loo= k. Ouch - and thanks! Adding (require 'perl-mode) is the correct thing to do. In my batch tests I loaded it explicitly for no good reason, I've eliminated that now. The tests need both modes to account for different names of custom variables (here: cperl-continued-statement-offset vs. perl-continued-statement-offset) which affect the expected outcome. --=20 Thanks again, haj From unknown Sun Aug 17 09:10:48 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 03 Feb 2021 12:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator