annotate lisp/progmodes/cwarn.el @ 62620:564274a2eaa2

(mail-get-names): Avoid beginning-of-buffer.
author Richard M. Stallman <rms@gnu.org>
date Sun, 22 May 2005 13:43:55 +0000
parents 6535e32999e7
children 18a818a2ee7c 02f1dbc4a199
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 30812
diff changeset
1 ;;; cwarn.el --- highlight suspicious C and C++ constructions
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
61283
6535e32999e7 (cwarn-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: Anders Lindgren <andersl@andersl.com>
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Keywords: c, languages, faces
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; X-Url: http://www.andersl.com/emacs
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Version: 1.3.1 1999-12-13
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; any later version.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;;{{{ Documentation
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; Description:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; CWarn is a package that highlights suspicious C and C++ constructions.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; For example, take a look at the following piece of C code:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; if (x = 0);
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; foo();
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; The code contains two, possibly fatal, bugs. The first is that the
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; assignment operator "=" is used as part of the test; the user
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
42 ;; probably meant to use the comparison operator "==".
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; The second problem is that an extra semicolon is placed after
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; closing parenthesis of the test expression. This makes the body of
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; the if statement to be an empty statement, not the call to the
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; function "foo", as the user probably intended.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; This package is capable of highlighting the following C and C++
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; constructions:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; * Assignments inside expressions, including variations like "+=".
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; * Semicolon following immediately after `if', `for', and `while'
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; (except, of course, after a `do .. while' statement).
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; * C++ functions with reference parameters.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; Note that none of the constructions highlighted (especially not C++
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
58 ;; reference parameters) are considered errors by the language
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; definitions.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; Usage:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; CWarn is implemented as two minor modes: `cwarn-mode' and
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; `global-cwarn-mode'. The former can be applied to individual buffers
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; and the latter to all buffers.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; Activate this package by Customize, or by placing the following line
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;; into the appropriate init file:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; (global-cwarn-mode 1)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;; Also, `font-lock-mode' or `global-font-lock-mode' must be enabled.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; Afterthought:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;; After using this package for several weeks it feels as though I
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; find stupid typo-style bugs while editing rather than at compile-
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; or run-time, if I ever find them.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;; On the other hand, I find myself using assignments inside
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;; expressions much more often than I used to do. The reason is that
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ;; there is no risk of interpreting an assignment operator as a
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;; comparison ("hey, the assignment operator is red, duh!").
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;; Reporting bugs:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;; Out of the last ten bugs you found, how many did you report?
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; When reporting a bug, please:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;; * Send a mail the maintainer of the package, or to the author
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; if no maintainer exists.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;; * Include the name of the package in the title of the mail, to
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; simplify for the recipient.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; * State exactly what you did, what happened, and what you expected
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 ;; to see when you found the bug.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 ;; * If the bug cause an error, set the variable `debug-on-error' to t,
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
98 ;; repeat the operations that triggered the error and include
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 ;; the backtrace in the letter.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 ;; * If possible, include an example that activates the bug.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 ;; * Should you speculate about the cause of the problem, please
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 ;; state explicitly that you are guessing.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 ;;; Code:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 ;;{{{ Dependencies
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (eval-when-compile (require 'cl))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (require 'custom)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (require 'font-lock)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 (require 'cc-mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 ;;{{{ Variables
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (defgroup cwarn nil
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 "Highlight suspicious C and C++ constructions."
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
121 :version "21.1"
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
122 :link '(url-link "http://www.andersl.com/emacs")
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 :group 'faces)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (defvar cwarn-mode nil
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 "*Non-nil when Cwarn mode is active.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 Never set this variable directly, use the command `cwarn-mode'
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 instead.")
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (defcustom cwarn-configuration
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 '((c-mode (not reference))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (c++-mode t))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 "*List of items each describing which features are enable for a mode.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 Each item is on the form (mode featurelist), where featurelist can be
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 on one of three forms:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 * A list of enabled features.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 * A list starting with the atom `not' followed by the features
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 which are not enabled.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 * The atom t, that represent that all features are enabled.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 See variable `cwarn-font-lock-feature-keywords-alist' for available
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 features."
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
145 :type '(repeat sexp)
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 :group 'cwarn)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (defcustom cwarn-font-lock-feature-keywords-alist
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 '((assign . cwarn-font-lock-assignment-keywords)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (semicolon . cwarn-font-lock-semicolon-keywords)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (reference . cwarn-font-lock-reference-keywords))
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
152 "An alist mapping a CWarn feature to font-lock keywords.
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 The keywords could either a font-lock keyword list or a symbol.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 If it is a symbol it is assumed to be a variable containing a font-lock
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 keyword list."
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
156 :type '(alist :key-type (choice (const assign)
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
157 (const semicolon)
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
158 (const reference))
40159
c302267b48cd (cwarn-font-lock-feature-keywords-alist):
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
159 :value-type (sexp :tag "Value"))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 :group 'cwarn)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (defcustom cwarn-verbose t
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 "*When nil, CWarn mode will not generate any messages.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 Currently, messages are generated when the mode is activated and
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 deactivated."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 :type 'boolean)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (defcustom cwarn-mode-text " CWarn"
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 "*String to display in the mode line when CWarn mode is active.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 \(When the string is not empty, make sure that it has a leading space.)"
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 :tag "CWarn mode text" ; To separate it from `global-...'
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 :type 'string)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (defcustom cwarn-load-hook nil
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 "*Functions to run when CWarn mode is first loaded."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 :tag "Load Hook"
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 :type 'hook)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 ;;{{{ The modes
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 ;;;###autoload
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
188 (define-minor-mode cwarn-mode
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
189 "Minor mode that highlights suspicious C and C++ constructions.
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 Note, in addition to enabling this minor mode, the major mode must
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 be included in the variable `cwarn-configuration'. By default C and
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 C++ modes are included.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 With ARG, turn CWarn mode on if and only if arg is positive."
61283
6535e32999e7 (cwarn-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
196 :group 'cwarn :lighter cwarn-mode-text
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
197 (cwarn-font-lock-keywords cwarn-mode)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
198 (if font-lock-mode (font-lock-fontify-buffer)))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 ;;;###autoload
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (defun turn-on-cwarn-mode ()
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 "Turn on CWarn mode.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 This function is designed to be added to hooks, for example:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (add-hook 'c-mode-hook 'turn-on-cwarn-mode)"
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (cwarn-mode 1))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 ;;{{{ Help functions
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (defun cwarn-is-enabled (mode &optional feature)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 "Non-nil if CWarn FEATURE is enabled for MODE.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 feature is an atom representing one construction to highlight.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 Check if any feature is enabled for MODE if no feature is specified.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 The valid features are described by the variable
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 `cwarn-font-lock-feature-keywords-alist'."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (let ((mode-configuraion (assq mode cwarn-configuration)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (and mode-configuraion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (or (null feature)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (let ((list-or-t (nth 1 mode-configuraion)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (or (eq list-or-t t)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (if (eq (car-safe list-or-t) 'not)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (not (memq feature (cdr list-or-t)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (memq feature list-or-t))))))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (defun cwarn-inside-macro ()
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 "True if point is inside a C macro definition."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (save-excursion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (beginning-of-line)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (while (eq (char-before (1- (point))) ?\\)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (forward-line -1))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (back-to-indentation)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (eq (char-after) ?#)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
237 (defun cwarn-font-lock-keywords (addp)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
238 "Install/Remove keywords into current buffer.
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
239 If ADDP is non-nil, install else remove."
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (dolist (pair cwarn-font-lock-feature-keywords-alist)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (let ((feature (car pair))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (keywords (cdr pair)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 (if (not (listp keywords))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (setq keywords (symbol-value keywords)))
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
245 (if (cwarn-is-enabled major-mode feature)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
246 (funcall (if addp 'font-lock-add-keywords 'font-lock-remove-keywords)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
247 nil keywords)))))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 ;;{{{ Backward compatibility
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 ;; This piece of code will be part of CC mode as of Emacs 20.4.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (if (not (fboundp 'c-at-toplevel-p))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (defun c-at-toplevel-p ()
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 "Return a determination as to whether point is at the `top-level'.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 Being at the top-level means that point is either outside any
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 enclosing block (such function definition), or inside a class
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 definition, but outside any method blocks.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 If point is not at the top-level (e.g. it is inside a method
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 definition), then nil is returned. Otherwise, if point is at a
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 top-level not enclosed within a class definition, t is returned.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 Otherwise, a 2-vector is returned where the zeroth element is the
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 buffer position of the start of the class declaration, and the first
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
265 element is the buffer position of the enclosing class' opening
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 brace."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (let ((state (c-parse-state)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (or (not (c-most-enclosing-brace state))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (c-search-uplist-for-classkey state))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 )
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 ;;{{{ Font-lock keywords and match functions
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 ;; This section contains font-lock keywords. A font lock keyword can
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 ;; either contain a regular expression or a match function. All
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 ;; keywords defined here use match functions since the C and C++
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 ;; constructions highlighted by CWarn are too complex to be matched by
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 ;; regular expressions.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 ;; A match function should act like a normal forward search. They
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 ;; should return non-nil if they found a candidate and the match data
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 ;; should correspond to the highlight part of the font-lock keyword.
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
284 ;; The functions should not generate errors, in that case font-lock
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 ;; will fail to highlight the buffer. A match function takes one
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 ;; argument, LIMIT, that represent the end of area to be searched.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 ;; The variable `cwarn-font-lock-feature-keywords-alist' contains a
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 ;; mapping from CWarn features to the font-lock keywords defined
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 ;; below.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
292 (defmacro cwarn-font-lock-match (re &rest body)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
293 "Match RE but only if BODY holds."
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
294 `(let ((res nil))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
295 (while
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
296 (progn
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
297 (setq res (re-search-forward ,re limit t))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
298 (and res
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
299 (save-excursion
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
300 (when (match-beginning 1) (goto-char (match-beginning 1)))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
301 (condition-case nil ; In case something barfs.
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
302 (not (save-match-data
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
303 ,@body))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
304 (error t))))))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
305 res))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
306
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 ;;{{{ Assignment in expressions
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (defconst cwarn-font-lock-assignment-keywords
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 '((cwarn-font-lock-match-assignment-in-expression
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (1 font-lock-warning-face))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (defun cwarn-font-lock-match-assignment-in-expression (limit)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 "Match assignments inside expressions."
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
315 (cwarn-font-lock-match
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
316 "[^!<>=]\\(\\([-+*/%&^|]\\|<<\\|>>\\)?=\\)[^=]"
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
317 (backward-up-list 1)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
318 (and (memq (following-char) '(?\( ?\[))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
319 (not (progn
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
320 (skip-chars-backward " ")
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
321 (skip-chars-backward "a-zA-Z0-9_")
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
322 (or
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
323 ;; Default parameter of function.
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
324 (c-at-toplevel-p)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
325 (looking-at "for\\>")))))))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 ;;{{{ Semicolon
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (defconst cwarn-font-lock-semicolon-keywords
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 '((cwarn-font-lock-match-dangerous-semicolon (0 font-lock-warning-face))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (defun cwarn-font-lock-match-dangerous-semicolon (limit)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 "Match semicolons directly after `for', `while', and `if'.
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
335 The semicolon after a `do { ... } while (x);' construction is not matched."
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
336 (cwarn-font-lock-match
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
337 ";"
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
338 (backward-sexp 2) ; Expression and keyword.
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
339 (or (looking-at "\\(for\\|if\\)\\>")
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
340 (and (looking-at "while\\>")
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
341 (condition-case nil
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
342 (progn
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
343 (backward-sexp 2) ; Body and "do".
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
344 (not (looking-at "do\\>")))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
345 (error t))))))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 ;;{{{ Reference
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (defconst cwarn-font-lock-reference-keywords
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 '((cwarn-font-lock-match-reference (1 font-lock-warning-face))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (defun cwarn-font-lock-match-reference (limit)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 "Font-lock matcher for C++ reference parameters."
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
355 (cwarn-font-lock-match
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
356 "[^&]\\(&\\)[^&=]"
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
357 (backward-up-list 1)
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
358 (and (eq (following-char) ?\()
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
359 (not (cwarn-inside-macro))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
360 (c-at-toplevel-p))))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 ;;{{{ The end
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366
44447
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
367 (defun turn-on-cwarn-mode-if-enabled ()
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
368 "Turn on CWarn mode in the current buffer if applicable.
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
369 The mode is turned if some feature is enabled for the current
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
370 `major-mode' in `cwarn-configuration'."
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
371 (if (cwarn-is-enabled major-mode) (turn-on-cwarn-mode)))
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
372
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
373 ;;;###autoload
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
374 (easy-mmode-define-global-mode global-cwarn-mode cwarn-mode
811bba65a69f (global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41827
diff changeset
375 turn-on-cwarn-mode-if-enabled)
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (provide 'cwarn)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (run-hooks 'cwarn-load-hook)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 44447
diff changeset
383 ;;; arch-tag: 225fb5e2-0838-4eb1-88ce-3811c5e4d738
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 ;;; cwarn.el ends here