annotate lisp/progmodes/cwarn.el @ 42015:0473e709920b

*** empty log message ***
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 13 Dec 2001 19:25:07 +0000
parents 6bfa4dcc106e
children 811bba65a69f
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
40159
c302267b48cd (cwarn-font-lock-feature-keywords-alist):
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001 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
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; probably ment to use the comparison operator "==".
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++
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; reference parameters) are considered errors by the langauage
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,
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;; repreat the operations that triggered the error and include
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 global-cwarn-mode nil
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
132 "When on, suspicious C and C++ constructions are highlighted.
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 Set this variable using \\[customize] or use the command
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 `global-cwarn-mode'."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 :initialize 'custom-initialize-default
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
138 :set (lambda (symbol value)
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
139 (global-cwarn-mode (or value 0)))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 :type 'boolean
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 :require 'cwarn)
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 (defcustom cwarn-configuration
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 '((c-mode (not reference))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (c++-mode t))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 "*List of items each describing which features are enable for a mode.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 Each item is on the form (mode featurelist), where featurelist can be
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 on one of three forms:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 * A list of enabled features.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 * A list starting with the atom `not' followed by the features
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 which are not enabled.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 * The atom t, that represent that all features are enabled.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 See variable `cwarn-font-lock-feature-keywords-alist' for available
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 features."
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
157 :type '(repeat sexp)
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 :group 'cwarn)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (defcustom cwarn-font-lock-feature-keywords-alist
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 '((assign . cwarn-font-lock-assignment-keywords)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (semicolon . cwarn-font-lock-semicolon-keywords)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (reference . cwarn-font-lock-reference-keywords))
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
164 "An alist mapping a CWarn feature to font-lock keywords.
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 The keywords could either a font-lock keyword list or a symbol.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 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
167 keyword list."
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
168 :type '(alist :key-type (choice (const assign)
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
169 (const semicolon)
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
170 (const reference))
40159
c302267b48cd (cwarn-font-lock-feature-keywords-alist):
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
171 :value-type (sexp :tag "Value"))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 :group 'cwarn)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (defcustom cwarn-verbose t
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 "*When nil, CWarn mode will not generate any messages.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 Currently, messages are generated when the mode is activated and
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 deactivated."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 :type 'boolean)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (defcustom cwarn-mode-text " CWarn"
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 "*String to display in the mode line when CWarn mode is active.
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 \(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
186 :tag "CWarn mode text" ; To separate it from `global-...'
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 :type 'string)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (defcustom cwarn-mode-hook nil
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 "*Functions to run when CWarn mode is activated."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 :tag "CWarn mode hook" ; To separate it from `global-...'
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 :type 'hook)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (defcustom global-cwarn-mode-text ""
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 "*String to display when Global CWarn mode is active.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 The default is nothing since when this mode is active this text doesn't
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 vary over time, or between buffers. Hence mode line text
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 would only waste precious space."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 :type 'string)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (defcustom global-cwarn-mode-hook nil
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 "*Hook called when Global CWarn mode is activated."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 :type 'hook)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (defcustom cwarn-load-hook nil
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 "*Functions to run when CWarn mode is first loaded."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 :tag "Load Hook"
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 :group 'cwarn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 :type 'hook)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215
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 modes
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 ;;;###autoload
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (defun cwarn-mode (&optional arg)
30811
2ae4e53657a3 (cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents: 26963
diff changeset
221 "Minor mode that highlights suspicious C and C++ constructions.
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 Note, in addition to enabling this minor mode, the major mode must
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 be included in the variable `cwarn-configuration'. By default C and
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 C++ modes are included.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 With ARG, turn CWarn mode on if and only if arg is positive."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (interactive "P")
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (make-local-variable 'cwarn-mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (setq cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (if (null arg)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (not cwarn-mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (> (prefix-numeric-value arg) 0)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (if (and cwarn-verbose
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (interactive-p))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (message "Cwarn mode is now %s."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 (if cwarn-mode "on" "off")))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (if (not global-cwarn-mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 (if cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (cwarn-font-lock-add-keywords)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (cwarn-font-lock-remove-keywords)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (font-lock-fontify-buffer)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 (if cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (run-hooks 'cwarn-mode-hook)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 ;;;###autoload
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (defun turn-on-cwarn-mode ()
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 "Turn on CWarn mode.
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 This function is designed to be added to hooks, for example:
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (add-hook 'c-mode-hook 'turn-on-cwarn-mode)"
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (cwarn-mode 1))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 ;;;###autoload
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (defun global-cwarn-mode (&optional arg)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 "Hightlight suspicious C and C++ constructions in all buffers.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 With ARG, turn CWarn mode on globally if and only if arg is positive."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (interactive "P")
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (let ((old-global-cwarn-mode global-cwarn-mode))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (setq global-cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (if (null arg)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (not global-cwarn-mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (> (prefix-numeric-value arg) 0)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (if (and cwarn-verbose
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (interactive-p))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (message "Global CWarn mode is now %s."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (if global-cwarn-mode "on" "off")))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (when (not (eq global-cwarn-mode old-global-cwarn-mode))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 ;; Update for all future buffers.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (dolist (conf cwarn-configuration)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (if global-cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (cwarn-font-lock-add-keywords (car conf))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (cwarn-font-lock-remove-keywords (car conf))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 ;; Update all existing buffers.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (save-excursion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (dolist (buffer (buffer-list))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (set-buffer buffer)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 ;; Update keywords in alive buffers.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (when (and font-lock-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (not cwarn-mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (cwarn-is-enabled major-mode))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (if global-cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (cwarn-font-lock-add-keywords)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (cwarn-font-lock-remove-keywords))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (font-lock-fontify-buffer))))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 ;; Kills all added keywords :-(
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 ;; (font-lock-mode 0)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 ;; (makunbound 'font-lock-keywords)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 ;; (font-lock-mode 1))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (when global-cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (run-hooks 'global-cwarn-mode-hook)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 ;;{{{ Help functions
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (defun cwarn-is-enabled (mode &optional feature)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 "Non-nil if CWarn FEATURE is enabled for MODE.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 feature is an atom representing one construction to highlight.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 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
302
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 The valid features are described by the variable
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 `cwarn-font-lock-feature-keywords-alist'."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 (let ((mode-configuraion (assq mode cwarn-configuration)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 (and mode-configuraion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 (or (null feature)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (let ((list-or-t (nth 1 mode-configuraion)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (or (eq list-or-t t)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (if (eq (car-safe list-or-t) 'not)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (not (memq feature (cdr list-or-t)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 (memq feature list-or-t))))))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (defun cwarn-inside-macro ()
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 "True if point is inside a C macro definition."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (save-excursion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 (beginning-of-line)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (while (eq (char-before (1- (point))) ?\\)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (forward-line -1))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (back-to-indentation)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (eq (char-after) ?#)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (defun cwarn-font-lock-add-keywords (&optional mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 "Install keywords into major MODE, or into current buffer if nil."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (dolist (pair cwarn-font-lock-feature-keywords-alist)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (let ((feature (car pair))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (keywords (cdr pair)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (if (not (listp keywords))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (setq keywords (symbol-value keywords)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (if (cwarn-is-enabled (or mode major-mode) feature)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (font-lock-add-keywords mode keywords)))))
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-remove-keywords (&optional mode)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 "Remove keywords from major MODE, or from current buffer if nil."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (dolist (pair cwarn-font-lock-feature-keywords-alist)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (let ((feature (car pair))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (keywords (cdr pair)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (if (not (listp keywords))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (setq keywords (symbol-value keywords)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (if (cwarn-is-enabled (or mode major-mode) feature)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 (font-lock-remove-keywords mode keywords)))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 ;;{{{ Backward compatibility
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 ;; 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
347 (if (not (fboundp 'c-at-toplevel-p))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (defun c-at-toplevel-p ()
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 "Return a determination as to whether point is at the `top-level'.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 Being at the top-level means that point is either outside any
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 enclosing block (such function definition), or inside a class
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 definition, but outside any method blocks.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 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
355 definition), then nil is returned. Otherwise, if point is at a
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 top-level not enclosed within a class definition, t is returned.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 Otherwise, a 2-vector is returned where the zeroth element is the
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 buffer position of the start of the class declaration, and the first
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 element is the buffer position of the enclosing class's opening
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 brace."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (let ((state (c-parse-state)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (or (not (c-most-enclosing-brace state))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 (c-search-uplist-for-classkey state))))
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
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 ;;{{{ Font-lock keywords and match functions
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 ;; This section contains font-lock keywords. A font lock keyword can
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 ;; either contain a regular expression or a match function. All
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 ;; keywords defined here use match functions since the C and C++
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 ;; constructions highlighted by CWarn are too complex to be matched by
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 ;; regular expressions.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 ;;
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 ;; A match function should act like a normal forward search. They
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 ;; 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
377 ;; should correspond to the highlight part of the font-lock keyword.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 ;; The functions shold not generate errors, in that case font-lock
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 ;; will fail to highlight the buffer. A match function takes one
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 ;; argument, LIMIT, that represent the end of area to be searched.
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 ;; The variable `cwarn-font-lock-feature-keywords-alist' contains a
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 ;; mapping from CWarn features to the font-lock keywords defined
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 ;; below.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 ;;{{{ Assignment in expressions
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (defconst cwarn-font-lock-assignment-keywords
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 '((cwarn-font-lock-match-assignment-in-expression
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (1 font-lock-warning-face))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (defun cwarn-font-lock-match-assignment-in-expression (limit)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 "Match assignments inside expressions."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (let ((res nil))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (while
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (progn
41827
6bfa4dcc106e (cwarn-font-lock-match-assignment-in-expression):
Eli Zaretskii <eliz@gnu.org>
parents: 40159
diff changeset
397 (setq res (re-search-forward
6bfa4dcc106e (cwarn-font-lock-match-assignment-in-expression):
Eli Zaretskii <eliz@gnu.org>
parents: 40159
diff changeset
398 "[^!<>=]\\(\\([-+*/%&^|]\\|<<\\|>>\\)?=\\)[^=]"
6bfa4dcc106e (cwarn-font-lock-match-assignment-in-expression):
Eli Zaretskii <eliz@gnu.org>
parents: 40159
diff changeset
399 limit t))
26963
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (and res
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (save-excursion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (goto-char (match-beginning 1))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (condition-case nil ; In case "backward-up-list" barfs.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (progn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (backward-up-list 1)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (or (not (memq (following-char) '(?\( ?\[)))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (save-match-data
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (skip-chars-backward " ")
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (skip-chars-backward "a-zA-Z0-9_")
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (or
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 ;; Default parameter of function.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (c-at-toplevel-p)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (looking-at "for\\>")))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (error t))))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 res))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 ;;{{{ Semicolon
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (defconst cwarn-font-lock-semicolon-keywords
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 '((cwarn-font-lock-match-dangerous-semicolon (0 font-lock-warning-face))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (defun cwarn-font-lock-match-dangerous-semicolon (limit)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 "Match semicolons directly after `for', `while', and `if'.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 Tne semicolon after a `do { ... } while (x);' construction is not matched."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (let ((res nil))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 (while
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (progn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (setq res (search-forward ";" limit t))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (and res
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (save-excursion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (condition-case nil ; In case something barfs.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (save-match-data
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (backward-sexp 2) ; Expression and keyword.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (not (or (looking-at "\\(for\\|if\\)\\>")
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (and (looking-at "while\\>")
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (condition-case nil
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (progn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (backward-sexp 2) ; Body and "do".
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (not (looking-at "do\\>")))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (error t))))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (error t))))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 res))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 ;;{{{ Reference
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (defconst cwarn-font-lock-reference-keywords
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 '((cwarn-font-lock-match-reference (1 font-lock-warning-face))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 (defun cwarn-font-lock-match-reference (limit)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 "Font-lock matcher for C++ reference parameters."
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 (let ((res nil))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (while
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (progn
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (setq res (re-search-forward "[^&]\\(&\\)[^&=]" limit t))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (and res
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 (save-excursion
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 (goto-char (match-beginning 1))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 (condition-case nil ; In case something barfs.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 (save-match-data
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (backward-up-list 1)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 (or (not (eq (following-char) ?\())
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 (cwarn-inside-macro)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (not (c-at-toplevel-p))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 (error t))))))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 res))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 ;;{{{ The end
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (unless (assq 'cwarn-mode minor-mode-alist)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 (push '(cwarn-mode cwarn-mode-text)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 minor-mode-alist))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (unless (assq 'global-cwarn-mode minor-mode-alist)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (push '(global-cwarn-mode global-cwarn-mode-text)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 minor-mode-alist))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (provide 'cwarn)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (run-hooks 'cwarn-load-hook)
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 ;; This makes it possible to set Global CWarn mode from
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 ;; Customize.
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (if global-cwarn-mode
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (global-cwarn-mode 1))
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 ;;}}}
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491
f281dfbf8cd2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 ;;; cwarn.el ends here