[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#13541: 24.2.92; awk-mode: wrong font locking regexp literals
From: |
Alan Mackenzie |
Subject: |
bug#13541: 24.2.92; awk-mode: wrong font locking regexp literals |
Date: |
Fri, 25 Jan 2013 17:50:57 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi, Leo.
On Thu, Jan 24, 2013 at 07:43:06PM +0800, Leo Liu wrote:
> In an awk buffer having the following text:
> #--BEGIN--
> NF { /xyz/ }
> NF {
> /xyz/
> }
> #--END--
> I have the second regexp properly font-locked but not the first one.
Yes.
Could you please try out, fairly thoroughly, the following patch, and let
me know how it goes. It aims to fontify a /regexp/ wherever one might
occur.
=== modified file 'lisp/progmodes/cc-awk.el'
*** lisp/progmodes/cc-awk.el 2013-01-01 09:11:05 +0000
--- lisp/progmodes/cc-awk.el 2013-01-25 17:47:38 +0000
***************
*** 211,217 ****
;; division sign.
(defconst c-awk-neutral-re
; "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)+") ; changed, 2003/6/7
! "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)")
;; A "neutral" char(pair). Doesn't change the "state" of a subsequent /.
;; This is space/tab, braces, an auto-increment/decrement operator or an
;; escaped character. Or one of the (invalid) characters @ or `. But NOT an
--- 211,217 ----
;; division sign.
(defconst c-awk-neutral-re
; "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)+") ; changed, 2003/6/7
! "\\([}@` \t]\\|\\+\\+\\|--\\|\\\\\\(.\\|[\n\r]\\)\\)")
;; A "neutral" char(pair). Doesn't change the "state" of a subsequent /.
;; This is space/tab, braces, an auto-increment/decrement operator or an
;; escaped character. Or one of the (invalid) characters @ or `. But NOT an
***************
*** 231,237 ****
;; will only work when there won't be a preceding " or / before the sought /
;; to foul things up.
(defconst c-awk-non-arith-op-bra-re
! "[[\(&=:!><,?;'~|]")
;; Matches an opening BRAcket, round or square, or any operator character
;; apart from +,-,/,*,%. For the purpose at hand (detecting a / which is a
;; regexp bracket) these arith ops are unnecessary and a pain, because of "++"
--- 231,237 ----
;; will only work when there won't be a preceding " or / before the sought /
;; to foul things up.
(defconst c-awk-non-arith-op-bra-re
! "[[\({&=:!><,?;'~|]")
;; Matches an opening BRAcket, round or square, or any operator character
;; apart from +,-,/,*,%. For the purpose at hand (detecting a / which is a
;; regexp bracket) these arith ops are unnecessary and a pain, because of "++"
***************
*** 242,247 ****
--- 242,257 ----
;; bracket, in a context where an immediate / would be a division sign. This
;; will only work when there won't be a preceding " or / before the sought /
;; to foul things up.
+ (defconst c-awk-pre-exp-alphanum-kwd-re
+ (concat "\\(^\\|[^_\n\r]\\)\\<"
+ (regexp-opt '("print" "return" "case") t)
+ "\\>\\([^_\n\r]\\|$\\)"))
+ ;; Matches all AWK keywords which can precede expressions (including
+ ;; /regexp/).
+ (defconst c-awk-kwd-regexp-sign-re
+ (concat c-awk-pre-exp-alphanum-kwd-re c-awk-neutrals*-re "/"))
+ ;; Matches a piece of AWK buffer ending in <kwd> /, where <kwd> is a keyword
+ ;; which can precede an expression.
;; REGEXPS USED FOR FINDING THE POSITION OF A "virtual semicolon"
(defconst c-awk-_-harmless-nonws-char-re "[^#/\"\\\\\n\r \t]")
***************
*** 721,729 ****
(goto-char anchor)
;; Analyze the line to find out what the / is.
(if (if anchor-state-/div
! (not (search-forward-regexp c-awk-regexp-sign-re (1+ /point) t))
! (search-forward-regexp c-awk-div-sign-re (1+ /point) t))
! ;; A division sign.
(progn (goto-char (1+ /point)) nil)
;; A regexp opener
;; Jump over the regexp innards, setting the match data.
--- 731,740 ----
(goto-char anchor)
;; Analyze the line to find out what the / is.
(if (if anchor-state-/div
! (not (search-forward-regexp c-awk-regexp-sign-re (1+ /point) t))
! (and (not (search-forward-regexp c-awk-kwd-regexp-sign-re (1+ /point)
t))
! (search-forward-regexp c-awk-div-sign-re (1+ /point) t)))
! ;; A division sign.
(progn (goto-char (1+ /point)) nil)
;; A regexp opener
;; Jump over the regexp innards, setting the match data.
> Leo
--
Alan Mackenzie (Nuremberg, Germany).
- bug#13541: 24.2.92; awk-mode: wrong font locking regexp literals, (continued)
- bug#13541: 24.2.92; awk-mode: wrong font locking regexp literals, Glenn Morris, 2013/01/24
- bug#12274: 24.2; awk-mode indentation failure, Alan Mackenzie, 2013/01/25
- bug#12274: 24.2; awk-mode indentation failure, Glenn Morris, 2013/01/25
- bug#12274: 24.2; awk-mode indentation failure, Alan Mackenzie, 2013/01/25
- bug#12274: 24.2; awk-mode indentation failure, Stefan Monnier, 2013/01/26
bug#13541: 24.2.92; awk-mode: wrong font locking regexp literals,
Alan Mackenzie <=
bug#13541: 24.2.92; awk-mode: wrong font locking regexp literals, Alan Mackenzie, 2013/01/29