Mercurial > emacs
annotate lisp/progmodes/cwarn.el @ 100267:c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-id.el (org-id-locations-file): Wrap file name with
`convert-standard-filename'.
(org-id-files): New variable.
(org-id-use-hash): New option.
(org-id-update-id-locations): Also search in all files current
listed in `org-id-files'. Convert the resulting alist to a hash
if the user customation says so.
(org-id-locations-save): Handle he case if `org-id-locations' is a
hash.
(org-id-locations-load): Convert the alist to a hash.
(org-id-add-location): Handle the hast case.
(kill-emacs-hook): Make sure id locations are saved when Emacs is
exited.
(org-id-hash-to-alist, org-id-alist-to-hash)
(org-id-paste-tracker): New functions.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-agenda.el (org-agenda-goto-calendar): Remove duplicate let
bindings of calendar variables.
* org-table.el (org-table-find-row-type): Renamed from
`org-find-row-type'.
(org-table-rewrite-old-row-references): Renamed from
`org-rewrite-old-row-references'.
(org-table-shift-refpart): Renamed from `org-shift-refpart'.
(org-table-cleanup-narrow-column-properties): Renamed from
`org-cleanup-narrow-column-properties'.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-table.el (org-find-row-type): New arguments DESC and CLINE,
for better error messages.
(org-table-get-descriptor-line): Supply the new arguments to
`org-find-row-type'.
(org-table-error-on-row-ref-crossing-hline): New option.
* org.el (org-target-link-regexp): Make buffer-local.
(org-move-subtree-down): Fix bug with trees at beginning of
buffer.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-faces.el (org-set-tag-faces): New function.
(org-tags-special-faces-re): New variable.
* org.el (org-font-lock-add-tag-faces, org-get-tag-face): New functions.
* org-faces.el (org-tag-faces): New option.
(org-tag): Mention `org-tag-faces' in the docstring.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-exp.el (org-export-html-style-default): Implement new
quoting.
* org-jsinfo.el (org-infojs-template): Implement new quoting.
* org-w3m.el (w3m-minor-mode-hook): Also add the special copy
command to the `w3m-minor-mode-map'.
* org-archive.el (org-archive-to-archive-sibling): Protect
`this-command' to avoid appending kills during archiving.
* org-exp.el (org-export-with-priority): New variable.
(org-export-add-options-to-plist): Use `org-export-plist-vars'
instead of internal list of strings and properties.
(org-print-icalendar-entries): Retrieve the location property with
inheritance.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-exp.el (org-export-with-todo-keywords): New option.
(org-export-plist-vars): Include also the keys for the #+OPTIONS
line.
(org-default-export-plist, org-export-add-options-to-plist)
(org-export-as-ascii, org-export-as-html): Use the new structure
of `org-export-plist-vars'.
* org.el (org-map-entries): Return all values.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-matcher-time): Recognize more special values.
* org-gnus.el (fboundp): Fix defvaralias for XEmacs.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-tags-exclude-from-inheritance): New option.
(org-tag-inherit-p, org-remove-uniherited-tags): Respect
`org-tags-exclude-from-inheritance'.
* org-agenda.el (org-agenda-show-inherited-tags): New option.
(org-format-agenda-item): Add inherited tags to the agenda line
string, and make sure that properties are kept when downcasing the
tags list.
(org-agenda-add-inherited-tags): New function.
(org-downcase-keep-props): New function.
* org.el (org-scan-tags): Mark inherited tags with a text
property.
(org-get-tags-at): Mark inherited tags with a text property.
(org-add-prop-inherited): New function.
* org-agenda.el (org-agenda-add-inherited-tags): New function.
(org-agenda-show-inherited-tags): New option.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-modules): Add org-w3m to the default modules.
* org-table.el (orgtbl-self-insert-command): Make S-SPC work in
orgtbl-mode.
(orgtabl-create-or-convert-from-region): New command.
* org-exp.el (org-export-as-ascii): Remove the handling of
targets.
(org-export-ascii-preprocess): Handle targets already in this
function.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-timer.el (org-timer-start-time): Define this variable.
(org-timer-item): Make argument optional.
* org-list.el (org-insert-item): Automatically insert a timer item
if the current list is a timer list.
* org-timer.el: New file.
* org-publish.el (org-publish-org-index): Only exclude the index
file in the main directory from being added to the site-map.
(org-publish-get-project-from-filename): If the current project is
a component, start publishing from the parent project.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-table.el (orgtbl-ret): Fix RET at beginning-of-buffer.
* org-publish.el (org-publish-org-index): Improve removal of
temporary buffers.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Sun, 07 Dec 2008 18:36:02 +0000 |
parents | 52b7a8c22af5 |
children | a9dc0e7c3f2b |
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 | 2 |
79717 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
64699
629afbe74e61
Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents:
64085
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
26963 | 5 |
6 ;; Author: Anders Lindgren <andersl@andersl.com> | |
7 ;; Keywords: c, languages, faces | |
8 ;; X-Url: http://www.andersl.com/emacs | |
9 ;; Version: 1.3.1 1999-12-13 | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
26963 | 14 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; (at your option) any later version. |
26963 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
26963 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;;{{{ Documentation | |
29 | |
30 ;; Description: | |
31 ;; | |
32 ;; CWarn is a package that highlights suspicious C and C++ constructions. | |
33 ;; | |
34 ;; For example, take a look at the following piece of C code: | |
35 ;; | |
36 ;; if (x = 0); | |
37 ;; foo(); | |
38 ;; | |
39 ;; The code contains two, possibly fatal, bugs. The first is that the | |
40 ;; 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
|
41 ;; probably meant to use the comparison operator "==". |
26963 | 42 ;; |
43 ;; The second problem is that an extra semicolon is placed after | |
44 ;; closing parenthesis of the test expression. This makes the body of | |
45 ;; the if statement to be an empty statement, not the call to the | |
46 ;; function "foo", as the user probably intended. | |
47 ;; | |
48 ;; This package is capable of highlighting the following C and C++ | |
49 ;; constructions: | |
50 ;; | |
51 ;; * Assignments inside expressions, including variations like "+=". | |
52 ;; * Semicolon following immediately after `if', `for', and `while' | |
53 ;; (except, of course, after a `do .. while' statement). | |
54 ;; * C++ functions with reference parameters. | |
55 ;; | |
56 ;; 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
|
57 ;; reference parameters) are considered errors by the language |
26963 | 58 ;; definitions. |
59 | |
60 ;; Usage: | |
61 ;; | |
62 ;; CWarn is implemented as two minor modes: `cwarn-mode' and | |
63 ;; `global-cwarn-mode'. The former can be applied to individual buffers | |
64 ;; and the latter to all buffers. | |
65 ;; | |
66 ;; Activate this package by Customize, or by placing the following line | |
67 ;; into the appropriate init file: | |
68 ;; | |
69 ;; (global-cwarn-mode 1) | |
70 ;; | |
71 ;; Also, `font-lock-mode' or `global-font-lock-mode' must be enabled. | |
72 | |
73 ;; Afterthought: | |
74 ;; | |
75 ;; After using this package for several weeks it feels as though I | |
76 ;; find stupid typo-style bugs while editing rather than at compile- | |
77 ;; or run-time, if I ever find them. | |
78 ;; | |
79 ;; On the other hand, I find myself using assignments inside | |
80 ;; expressions much more often than I used to do. The reason is that | |
81 ;; there is no risk of interpreting an assignment operator as a | |
82 ;; comparison ("hey, the assignment operator is red, duh!"). | |
83 | |
84 ;; Reporting bugs: | |
85 ;; | |
86 ;; Out of the last ten bugs you found, how many did you report? | |
87 ;; | |
88 ;; When reporting a bug, please: | |
89 ;; | |
90 ;; * Send a mail the maintainer of the package, or to the author | |
91 ;; if no maintainer exists. | |
92 ;; * Include the name of the package in the title of the mail, to | |
93 ;; simplify for the recipient. | |
94 ;; * State exactly what you did, what happened, and what you expected | |
95 ;; to see when you found the bug. | |
96 ;; * 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
|
97 ;; repeat the operations that triggered the error and include |
26963 | 98 ;; the backtrace in the letter. |
99 ;; * If possible, include an example that activates the bug. | |
100 ;; * Should you speculate about the cause of the problem, please | |
101 ;; state explicitly that you are guessing. | |
102 | |
103 ;;}}} | |
104 | |
105 ;;; Code: | |
106 | |
107 ;;{{{ Dependencies | |
108 | |
109 (eval-when-compile (require 'cl)) | |
110 | |
111 (require 'custom) | |
112 (require 'font-lock) | |
113 (require 'cc-mode) | |
114 | |
115 ;;}}} | |
116 ;;{{{ Variables | |
117 | |
118 (defgroup cwarn nil | |
119 "Highlight suspicious C and C++ constructions." | |
30811
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
120 :version "21.1" |
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
121 :link '(url-link "http://www.andersl.com/emacs") |
26963 | 122 :group 'faces) |
123 | |
124 (defvar cwarn-mode nil | |
125 "*Non-nil when Cwarn mode is active. | |
126 | |
127 Never set this variable directly, use the command `cwarn-mode' | |
128 instead.") | |
129 | |
130 (defcustom cwarn-configuration | |
131 '((c-mode (not reference)) | |
132 (c++-mode t)) | |
133 "*List of items each describing which features are enable for a mode. | |
134 Each item is on the form (mode featurelist), where featurelist can be | |
135 on one of three forms: | |
136 | |
137 * A list of enabled features. | |
138 * A list starting with the atom `not' followed by the features | |
139 which are not enabled. | |
140 * The atom t, that represent that all features are enabled. | |
141 | |
142 See variable `cwarn-font-lock-feature-keywords-alist' for available | |
143 features." | |
30811
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
144 :type '(repeat sexp) |
26963 | 145 :group 'cwarn) |
146 | |
147 (defcustom cwarn-font-lock-feature-keywords-alist | |
148 '((assign . cwarn-font-lock-assignment-keywords) | |
149 (semicolon . cwarn-font-lock-semicolon-keywords) | |
150 (reference . cwarn-font-lock-reference-keywords)) | |
30811
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
151 "An alist mapping a CWarn feature to font-lock keywords. |
26963 | 152 The keywords could either a font-lock keyword list or a symbol. |
153 If it is a symbol it is assumed to be a variable containing a font-lock | |
154 keyword list." | |
30811
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
155 :type '(alist :key-type (choice (const assign) |
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
156 (const semicolon) |
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
157 (const reference)) |
40159
c302267b48cd
(cwarn-font-lock-feature-keywords-alist):
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
158 :value-type (sexp :tag "Value")) |
26963 | 159 :group 'cwarn) |
160 | |
161 (defcustom cwarn-verbose t | |
162 "*When nil, CWarn mode will not generate any messages. | |
163 | |
164 Currently, messages are generated when the mode is activated and | |
165 deactivated." | |
166 :group 'cwarn | |
167 :type 'boolean) | |
168 | |
169 (defcustom cwarn-mode-text " CWarn" | |
170 "*String to display in the mode line when CWarn mode is active. | |
171 | |
172 \(When the string is not empty, make sure that it has a leading space.)" | |
173 :tag "CWarn mode text" ; To separate it from `global-...' | |
174 :group 'cwarn | |
175 :type 'string) | |
176 | |
177 (defcustom cwarn-load-hook nil | |
178 "*Functions to run when CWarn mode is first loaded." | |
179 :tag "Load Hook" | |
180 :group 'cwarn | |
181 :type 'hook) | |
182 | |
183 ;;}}} | |
184 ;;{{{ The modes | |
185 | |
186 ;;;###autoload | |
44447
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
187 (define-minor-mode cwarn-mode |
30811
2ae4e53657a3
(cwarn) <defgroup>: Add :version, :link.
Dave Love <fx@gnu.org>
parents:
26963
diff
changeset
|
188 "Minor mode that highlights suspicious C and C++ constructions. |
26963 | 189 |
190 Note, in addition to enabling this minor mode, the major mode must | |
191 be included in the variable `cwarn-configuration'. By default C and | |
192 C++ modes are included. | |
193 | |
194 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
|
195 :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
|
196 (cwarn-font-lock-keywords cwarn-mode) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
197 (if font-lock-mode (font-lock-fontify-buffer))) |
26963 | 198 |
199 ;;;###autoload | |
200 (defun turn-on-cwarn-mode () | |
201 "Turn on CWarn mode. | |
202 | |
203 This function is designed to be added to hooks, for example: | |
204 (add-hook 'c-mode-hook 'turn-on-cwarn-mode)" | |
205 (cwarn-mode 1)) | |
206 | |
207 ;;}}} | |
208 ;;{{{ Help functions | |
209 | |
210 (defun cwarn-is-enabled (mode &optional feature) | |
211 "Non-nil if CWarn FEATURE is enabled for MODE. | |
212 feature is an atom representing one construction to highlight. | |
213 | |
214 Check if any feature is enabled for MODE if no feature is specified. | |
215 | |
216 The valid features are described by the variable | |
217 `cwarn-font-lock-feature-keywords-alist'." | |
218 (let ((mode-configuraion (assq mode cwarn-configuration))) | |
219 (and mode-configuraion | |
220 (or (null feature) | |
221 (let ((list-or-t (nth 1 mode-configuraion))) | |
222 (or (eq list-or-t t) | |
223 (if (eq (car-safe list-or-t) 'not) | |
224 (not (memq feature (cdr list-or-t))) | |
225 (memq feature list-or-t)))))))) | |
226 | |
227 (defun cwarn-inside-macro () | |
228 "True if point is inside a C macro definition." | |
229 (save-excursion | |
230 (beginning-of-line) | |
231 (while (eq (char-before (1- (point))) ?\\) | |
232 (forward-line -1)) | |
233 (back-to-indentation) | |
234 (eq (char-after) ?#))) | |
235 | |
44447
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
236 (defun cwarn-font-lock-keywords (addp) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
237 "Install/Remove keywords into current buffer. |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
238 If ADDP is non-nil, install else remove." |
26963 | 239 (dolist (pair cwarn-font-lock-feature-keywords-alist) |
240 (let ((feature (car pair)) | |
241 (keywords (cdr pair))) | |
242 (if (not (listp keywords)) | |
243 (setq keywords (symbol-value keywords))) | |
44447
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
244 (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
|
245 (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
|
246 nil keywords))))) |
26963 | 247 |
248 ;;}}} | |
249 ;;{{{ Backward compatibility | |
250 | |
251 ;; This piece of code will be part of CC mode as of Emacs 20.4. | |
252 (if (not (fboundp 'c-at-toplevel-p)) | |
253 (defun c-at-toplevel-p () | |
254 "Return a determination as to whether point is at the `top-level'. | |
255 Being at the top-level means that point is either outside any | |
256 enclosing block (such function definition), or inside a class | |
257 definition, but outside any method blocks. | |
258 | |
259 If point is not at the top-level (e.g. it is inside a method | |
260 definition), then nil is returned. Otherwise, if point is at a | |
261 top-level not enclosed within a class definition, t is returned. | |
262 Otherwise, a 2-vector is returned where the zeroth element is the | |
263 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
|
264 element is the buffer position of the enclosing class' opening |
26963 | 265 brace." |
266 (let ((state (c-parse-state))) | |
267 (or (not (c-most-enclosing-brace state)) | |
268 (c-search-uplist-for-classkey state)))) | |
269 ) | |
270 | |
271 ;;}}} | |
272 ;;{{{ Font-lock keywords and match functions | |
273 | |
274 ;; This section contains font-lock keywords. A font lock keyword can | |
275 ;; either contain a regular expression or a match function. All | |
276 ;; keywords defined here use match functions since the C and C++ | |
277 ;; constructions highlighted by CWarn are too complex to be matched by | |
278 ;; regular expressions. | |
279 ;; | |
280 ;; A match function should act like a normal forward search. They | |
281 ;; should return non-nil if they found a candidate and the match data | |
282 ;; 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
|
283 ;; The functions should not generate errors, in that case font-lock |
26963 | 284 ;; will fail to highlight the buffer. A match function takes one |
285 ;; argument, LIMIT, that represent the end of area to be searched. | |
286 ;; | |
287 ;; The variable `cwarn-font-lock-feature-keywords-alist' contains a | |
288 ;; mapping from CWarn features to the font-lock keywords defined | |
289 ;; below. | |
290 | |
44447
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
291 (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
|
292 "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
|
293 `(let ((res nil)) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
294 (while |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
295 (progn |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
296 (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
|
297 (and res |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
298 (save-excursion |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
299 (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
|
300 (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
|
301 (not (save-match-data |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
302 ,@body)) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
303 (error t)))))) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
304 res)) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
305 |
26963 | 306 ;;{{{ Assignment in expressions |
307 | |
308 (defconst cwarn-font-lock-assignment-keywords | |
309 '((cwarn-font-lock-match-assignment-in-expression | |
310 (1 font-lock-warning-face)))) | |
311 | |
312 (defun cwarn-font-lock-match-assignment-in-expression (limit) | |
313 "Match assignments inside expressions." | |
44447
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
314 (cwarn-font-lock-match |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
315 "[^!<>=]\\(\\([-+*/%&^|]\\|<<\\|>>\\)?=\\)[^=]" |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
316 (backward-up-list 1) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
317 (and (memq (following-char) '(?\( ?\[)) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
318 (not (progn |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
319 (skip-chars-backward " ") |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
320 (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
|
321 (or |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
322 ;; Default parameter of function. |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
323 (c-at-toplevel-p) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
324 (looking-at "for\\>"))))))) |
26963 | 325 |
326 ;;}}} | |
327 ;;{{{ Semicolon | |
328 | |
329 (defconst cwarn-font-lock-semicolon-keywords | |
330 '((cwarn-font-lock-match-dangerous-semicolon (0 font-lock-warning-face)))) | |
331 | |
332 (defun cwarn-font-lock-match-dangerous-semicolon (limit) | |
333 "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
|
334 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
|
335 (cwarn-font-lock-match |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
336 ";" |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
337 (backward-sexp 2) ; Expression and keyword. |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
338 (or (looking-at "\\(for\\|if\\)\\>") |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
339 (and (looking-at "while\\>") |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
340 (condition-case nil |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
341 (progn |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
342 (backward-sexp 2) ; Body and "do". |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
343 (not (looking-at "do\\>"))) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
344 (error t)))))) |
26963 | 345 |
346 ;;}}} | |
347 ;;{{{ Reference | |
348 | |
349 (defconst cwarn-font-lock-reference-keywords | |
350 '((cwarn-font-lock-match-reference (1 font-lock-warning-face)))) | |
351 | |
352 (defun cwarn-font-lock-match-reference (limit) | |
353 "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
|
354 (cwarn-font-lock-match |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
355 "[^&]\\(&\\)[^&=]" |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
356 (backward-up-list 1) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
357 (and (eq (following-char) ?\() |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
358 (not (cwarn-inside-macro)) |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
359 (c-at-toplevel-p)))) |
26963 | 360 |
361 ;;}}} | |
362 | |
363 ;;}}} | |
364 ;;{{{ The end | |
365 | |
44447
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
366 (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
|
367 "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
|
368 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
|
369 `major-mode' in `cwarn-configuration'." |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
370 (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
|
371 |
811bba65a69f
(global-cwarn-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41827
diff
changeset
|
372 ;;;###autoload |
75639
e499a9252500
(global-cwarn-mode): define-global-minor-mode changed to
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
373 (define-globalized-minor-mode global-cwarn-mode |
67296
5db0c081adbe
(global-cwarn-mode): Use define-global-minor-mode
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
374 cwarn-mode turn-on-cwarn-mode-if-enabled) |
26963 | 375 |
376 (provide 'cwarn) | |
377 | |
378 (run-hooks 'cwarn-load-hook) | |
379 | |
380 ;;}}} | |
381 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79717
diff
changeset
|
382 ;; arch-tag: 225fb5e2-0838-4eb1-88ce-3811c5e4d738 |
26963 | 383 ;;; cwarn.el ends here |