unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: 21871@debbugs.gnu.org
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	[thread overview]
Message-ID: <878sj23w4s.fsf@gmail.com> (raw)
In-Reply-To: <20151110163034.GH2626@acm.fritz.box> (Alan Mackenzie's message of "Tue, 10 Nov 2015 16:30:34 +0000")

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

Alan Mackenzie <acm@muc.de> 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


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 3847 bytes --]

From b3794a2a87c6aafc2174162f72f716a5801668a4 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
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
 \f
 ;; 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


  parent reply	other threads:[~2020-04-11 15:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-10 16:30 bug#21871: Emacs Lisp Mode (at least): spurious parens in column 0 don't get bold red highlighting Alan Mackenzie
     [not found] ` <mailman.2066.1447172952.7904.bug-gnu-emacs@gnu.org>
2015-11-12 12:44   ` Alan Mackenzie
2015-11-12 16:36     ` Glenn Morris
2015-11-12 18:12       ` Alan Mackenzie
     [not found] ` <mailman.2173.1447351928.7904.bug-gnu-emacs@gnu.org>
2015-11-12 18:54   ` Alan Mackenzie
2015-11-12 19:17     ` Eli Zaretskii
2016-05-15 21:50     ` Dmitry Gutov
2016-05-16 10:20       ` Alan Mackenzie
2016-05-16 13:18         ` Dmitry Gutov
2016-05-16 15:00           ` Andreas Röhler
2016-05-17  9:02           ` Alan Mackenzie
2017-09-02 13:19             ` Eli Zaretskii
2020-04-11 15:00 ` Noam Postavsky [this message]
2021-09-19 22:14 ` Stefan Kangas
2021-09-20 17:50   ` Alan Mackenzie
2021-09-21 23:07     ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878sj23w4s.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=21871@debbugs.gnu.org \
    --cc=acm@muc.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).