From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#23461: perl-mode: Displaying HERE-docs as strings instead of comments [PATCH] Date: Wed, 23 Dec 2020 11:34:12 -0500 Message-ID: References: <87sg7xxo0s.fsf@hajtower> <87zh24611c.fsf@hajtower> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6419"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 23461@debbugs.gnu.org To: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 23 17:35:26 2020 Return-path: Envelope-to: geb-bug-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 1ks76j-0001XG-H6 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 23 Dec 2020 17:35:25 +0100 Original-Received: from localhost ([::1]:46522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ks76i-0001Gv-GA for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 23 Dec 2020 11:35:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ks76N-0001GM-Tx for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 11:35:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ks76M-0008US-3B for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 11:35:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ks76M-0000wu-0U for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 11:35:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 23 Dec 2020 16:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23461 X-GNU-PR-Package: emacs Original-Received: via spool by 23461-submit@debbugs.gnu.org id=B23461.16087412643597 (code B ref 23461); Wed, 23 Dec 2020 16:35:01 +0000 Original-Received: (at 23461) by debbugs.gnu.org; 23 Dec 2020 16:34:24 +0000 Original-Received: from localhost ([127.0.0.1]:53962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks75j-0000vx-PU for submit@debbugs.gnu.org; Wed, 23 Dec 2020 11:34:24 -0500 Original-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 Original-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) Original-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== Original-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) In-Reply-To: <87zh24611c.fsf@hajtower> ("Harald =?UTF-8?Q?J=C3=B6rg?="'s message of "Wed, 23 Dec 2020 15:37:51 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:196624 Archived-At: > 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