From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#21871: Emacs Lisp Mode (at least): spurious parens in column 0 don't get bold red highlighting. Date: Sat, 11 Apr 2020 11:00:35 -0400 Message-ID: <878sj23w4s.fsf@gmail.com> References: <20151110163034.GH2626@acm.fritz.box> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="122190"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.90 (gnu/linux) Cc: 21871@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 11 17:01:31 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 1jNHdT-000Vi8-Fh for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Apr 2020 17:01:31 +0200 Original-Received: from localhost ([::1]:52548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNHdS-00088a-7u for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Apr 2020 11:01:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41009) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNHd5-00084I-7s for bug-gnu-emacs@gnu.org; Sat, 11 Apr 2020 11:01:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jNHd0-0006UX-SZ for bug-gnu-emacs@gnu.org; Sat, 11 Apr 2020 11:01:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45415) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jNHd0-0006U7-Nt for bug-gnu-emacs@gnu.org; Sat, 11 Apr 2020 11:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jNHd0-0003RC-4p for bug-gnu-emacs@gnu.org; Sat, 11 Apr 2020 11:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Apr 2020 15:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21871 X-GNU-PR-Package: emacs Original-Received: via spool by 21871-submit@debbugs.gnu.org id=B21871.158661724613186 (code B ref 21871); Sat, 11 Apr 2020 15:01:02 +0000 Original-Received: (at 21871) by debbugs.gnu.org; 11 Apr 2020 15:00:46 +0000 Original-Received: from localhost ([127.0.0.1]:56961 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jNHck-0003Qa-6K for submit@debbugs.gnu.org; Sat, 11 Apr 2020 11:00:46 -0400 Original-Received: from mail-qk1-f182.google.com ([209.85.222.182]:39685) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jNHch-0003QM-BG for 21871@debbugs.gnu.org; Sat, 11 Apr 2020 11:00:44 -0400 Original-Received: by mail-qk1-f182.google.com with SMTP id b62so5064640qkf.6 for <21871@debbugs.gnu.org>; Sat, 11 Apr 2020 08:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=6IekO+x+2fA5YSas8Wy2fgO/hSioa5sYmsfDYgWqiDI=; b=bAcjmcMdgYD0SSX4znBUM/F4kvNkgjyGtFQlGRcNJ3jnlZJGfMiXMpNaDg9UBx3gEJ zFi6+8Yw01+Y9b5c3uvfyZAHarfcqfTq9QbxZ0LX2Q/xcHKehT3jFDH6N83CHZfpyWd/ 3g02WpQo/XzRDmtkazpdh52ldH9s6kVCp4US9Tx1e7JbKaTx/TBb7PFtRg7jWB8RcGe7 OJJIG7V31cmtAqSV3heBoB6eHyWV2HdVDii5s8Z0Cdk5lkJ1Pv45hlBLpTArODNKe+Hg vCBAjYH9k4aLECbybJIuOxrMHbTnEkj906P2oBegojGmVe8VPjL8uVU02AogFtADLvnX 8iBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=6IekO+x+2fA5YSas8Wy2fgO/hSioa5sYmsfDYgWqiDI=; b=Hzt79IKepjnoN/Tixak/a0W5kaB/qJzpVnqn2OwESTGCVnYQK5Xw8QTY0JRMKRKjxC cIx31PpbSN+iVdGwc7RC+SlmIE1DtCjP8J/jPiXGxI5DrR/w+EpAh0SkM/dkioQYyX+T B7t2YPIp1Q0By2EQY5q1vOkXFsAtGwZpZz+56Fty/DqUmYzSSf5yMhmOpzpIigBCuEoj OZwtKqRiQhwTt3Rv5TMzEM5WDh0s1Q5mJrJLOZ2sEihzuq+153Y1KAsKpo/z6wx+C71Z FYYUKhfzcRb6S0+DOevAvd5IO5TwKrZ8wvdc4800n4XHzdLU5GQbmmBsMSiB+TC3LtWi fJ9w== X-Gm-Message-State: AGi0PubK3QsTEM07bNgheC1elY7ReLwRyuINejxJofB3K9w+i1Q5HEtM 9w2mZpX0BfpMZks5QKeifEjLULhU X-Google-Smtp-Source: APiQypKWTtGdZkyAwj5pN+uBhKmxAEhjjz7WeQQBrvtda3awKvP8NtoPMknc98CmI4Q8USdZQsImJQ== X-Received: by 2002:ae9:e708:: with SMTP id m8mr1894487qka.90.1586617237185; Sat, 11 Apr 2020 08:00:37 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-47.yyz.frontiernetworks.ca. [45.2.119.47]) by smtp.gmail.com with ESMTPSA id z6sm3825980qke.56.2020.04.11.08.00.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 11 Apr 2020 08:00:36 -0700 (PDT) In-Reply-To: <20151110163034.GH2626@acm.fritz.box> (Alan Mackenzie's message of "Tue, 10 Nov 2015 16:30:34 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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:178204 Archived-At: --=-=-= Content-Type: text/plain Alan Mackenzie writes: > In the Emacs manual page "Left Margin Paren", it says that: > > To help you catch violations of this convention, Font Lock mode > highlights confusing opening delimiters (those that ought to be quoted) > in bold red. > > , where "this convention" is the convention of not putting opening parens > in column 0 when they aren't at the beginning of defuns. > > In Emacs Lisp Mode, this highlighting isn't done. It isn't in CC Mode, > either. The recent thread in emacs-devel[1] reminded me I wrote a (still half-baked) patch for this. [1]: https://lists.gnu.org/r/emacs-devel/2020-04/msg00402.html --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=0001-WIP-Restore-highlighting-of-open-parens-in-column-0-.patch Content-Description: patch >From b3794a2a87c6aafc2174162f72f716a5801668a4 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 5 Aug 2017 12:31:02 -0400 Subject: [PATCH] [WIP] Restore highlighting of open parens in column-0 (Bug#21871) --- lisp/emacs-lisp/lisp-mode.el | 1 + lisp/font-lock.el | 38 ++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 3b0f5493ee..50707fd10a 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -642,6 +642,7 @@ lisp-mode-variables (setq-local imenu-generic-expression lisp-imenu-generic-expression) (setq-local multibyte-syntax-as-symbol t) ;; (setq-local syntax-begin-function 'beginning-of-defun) ;;Bug#16247. + (setq-local font-lock-syntax-paren-check t) ;; Bug#21871. (setq font-lock-defaults `(,(if elisp '(lisp-el-font-lock-keywords lisp-el-font-lock-keywords-1 diff --git a/lisp/font-lock.el b/lisp/font-lock.el index e0955b74ab..565f4b22b4 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -1779,6 +1779,11 @@ font-lock-fontify-keywords-region ;; Various functions. +(defvar-local font-lock-syntax-paren-check nil + "Major modes should set this to non-nil if they rely on the +`open-paren-in-column-0-is-defun-start' convention for movement +or fontification.") + (defun font-lock-compile-keywords (keywords &optional syntactic-keywords) "Compile KEYWORDS into the form (t KEYWORDS COMPILED...) Here each COMPILED is of the form (MATCHER HIGHLIGHT ...) as shown in the @@ -1798,24 +1803,29 @@ font-lock-compile-keywords (cons t (cons keywords (mapcar #'font-lock-compile-keyword keywords)))) (if (and (not syntactic-keywords) - (let ((beg-function (with-no-warnings syntax-begin-function))) - (or (eq beg-function #'beginning-of-defun) - (if (symbolp beg-function) - (get beg-function 'font-lock-syntax-paren-check)))) - (not beginning-of-defun-function)) + (or (and (let ((beg-function (with-no-warnings syntax-begin-function))) + (or (eq beg-function #'beginning-of-defun) + (if (symbolp beg-function) + (get beg-function 'font-lock-syntax-paren-check)))) + (not beginning-of-defun-function)) + font-lock-syntax-paren-check)) ;; Try to detect when a string or comment contains something that ;; looks like a defun and would thus confuse font-lock. (nconc keywords - `((,(if defun-prompt-regexp - (concat "^\\(?:" defun-prompt-regexp "\\)?\\s(") - "^\\s(") - (0 - (if (memq (get-text-property (match-beginning 0) 'face) - '(font-lock-string-face font-lock-doc-face - font-lock-comment-face)) - (list 'face font-lock-warning-face + `((,(let ((regexp + (if defun-prompt-regexp + (concat "^\\(?:" defun-prompt-regexp "\\)?\\s(") + "^\\s("))) + (lambda (bound) + (if open-paren-in-column-0-is-defun-start + (re-search-forward regexp bound t)))) + (0 + (if (memq (get-text-property (match-beginning 0) 'face) + '(font-lock-string-face font-lock-doc-face + font-lock-comment-face)) + (list 'face font-lock-warning-face 'help-echo "Looks like a toplevel defun: escape the parenthesis")) - prepend))))) + prepend))))) keywords)) (defun font-lock-compile-keyword (keyword) -- 2.11.0 --=-=-=--