[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Emacs-21.1: cwarn-mode doesn't highlight shift assignments >> =, <<=
From: |
Broadey Kevin-BKB003 |
Subject: |
RE: Emacs-21.1: cwarn-mode doesn't highlight shift assignments >> =, <<= |
Date: |
Tue, 4 Dec 2001 10:57:48 -0000 |
Couldn't resist a bit of elisp hacking! Here's a diff to highlight <<= and
>>=. It also highlights the whole of the operator rather than just the =.
This makes it show up better IMHO.
I'm not entirely happy with the regexp. I had to stick "[^!<>=]" at the
beginning to stop the = in comparison operators being highlighted. It works,
but I think there should be a cleaner way to catch a plain assignment "=".
$ gdiff -u cwarn.el.orig cwarn.el
--- cwarn.el.orig Tue Dec 4 10:18:45 2001
+++ cwarn.el Tue Dec 4 10:44:13 2001
@@ -1,5 +1,9 @@
;;; cwarn.el --- highlight suspicious C and C++ constructions
+;; 4-Dec-01 kevin.broadey@motorola.com
+;; Add shift-assignment operators to list highlighted, and highlight
+;; the whole operator rather than just the "=".
+
;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
;; Author: Anders Lindgren <andersl@andersl.com>
@@ -394,7 +398,11 @@
(let ((res nil))
(while
(progn
- (setq res (re-search-forward "[^!<>=]\\(=\\)[^=]" limit t))
+ ;; the [^!<>=] at the beginning of the regexp is needed to stop the "=" in
+ ;; comparison operators == != <= >= being highlighted. Is there a better
+ ;; way to anchor the regexp?
+ (setq res (re-search-forward "[^!<>=]\\(\\([-+*/%&^|]\\|<<\\|>>\\)?=\\)[^=]"
+ limit t))
(and res
(save-excursion
(goto-char (match-beginning 1))
Here's my test file:-
void foo (void)
{
/* assignment operators */
if (a = b);
if (a += b);
if (a -= b);
if (a *= b);
if (a /= b);
if (a &= b);
if (a |= b);
if (a ^= b);
if (a <<= b);
if (a >>= b);
/* comparison operators */
if (a == b);
if (a != b);
if (a <= b);
if (a >= b);
}
--
Kevin
> -----Original Message-----
> From: Kevin Broadey [mailto:Kevin_Broadey-BKB003@email.mot.com]
> Sent: 04 December 2001 10:19
> To: bug-gnu-emacs@gnu.org
> Cc: andersl@andersl.com
> Subject: Emacs-21.1: cwarn-mode doesn't highlight shift
> assignments >>=, <<=
>
>
>
> In GNU Emacs 21.1.4 (sparc-sun-solaris2.7, Motif Version 2.1.0)
> of 2001-11-30 on bah128
> configured using `configure
> --prefix=/org/users/kevinbr/gnu/emacs-21.1
> --exec-prefix=/org/users/kevinbr/gnu/emacs-21.1/SunOS
> --with-x-toolkit=motif'
> Important settings:
> value of $LC_ALL: nil
> value of $LC_COLLATE: nil
> value of $LC_CTYPE: nil
> value of $LC_MESSAGES: nil
> value of $LC_MONETARY: nil
> value of $LC_NUMERIC: nil
> value of $LC_TIME: nil
> value of $LANG: nil
> locale-coding-system: nil
> default-enable-multibyte-characters: nil
>
> cwarn-mode looks like a great idea. I used to have this in my
> .emacs to guard against the same problem:-
>
> (let ((c-font-lock-extras
> '(
> ;; assignment operators:
> ("[-+*/%&^|]=" . font-lock-warning-face) ; -= +=
> *= %= &= ^= |=
> ("\\(>>\\|<<\\)=" . font-lock-warning-face) ; <<= >>=
> ("[<>!=]=" . 'default) ; <= >= != ==
> ("=\\|\\+\\+\\|--" . font-lock-warning-face) ; = ++ --
> )))
> (font-lock-add-keywords 'c-mode c-font-lock-extras)
> (font-lock-add-keywords 'c++-mode c-font-lock-extras))
>
> but cwarn is better as it only highlights the suspicious ones.
>
> Unfortunately cwarn doesn't highlight the assigning shift operators
> "<<=" and ">>=". Not a major problem, but it should do for
> completeness. I guess it's difficult as you need to ignore "<=" and
> ">=".
>
> One other suggestion - can you get it to highlight the whole of the
> operator rather than just the "="?
>
> --
> Kevin Broadey
>
- RE: Emacs-21.1: cwarn-mode doesn't highlight shift assignments >> =, <<=,
Broadey Kevin-BKB003 <=