annotate lisp/emacs-lisp/elint.el @ 101333:3c967cc822f1

Added missing ChangeLog entry
author John Wiegley <johnw@newartisans.com>
date Thu, 22 Jan 2009 01:43:02 +0000
parents a9dc0e7c3f2b
children 5ae300b1d079
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: 20014
diff changeset
1 ;;; elint.el --- Lint Emacs Lisp
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
74466
1d4b1a32fd66 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68648
diff changeset
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 94655
diff changeset
4 ;; 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: Peter Liljenberg <petli@lysator.liu.se>
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: May 1997
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: lisp
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; (at your option) any later version.
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; This is a linter for Emacs Lisp. Currently, it mainly catches
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; mispellings and undefined variables, although it can also catch
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; function calls with the wrong number of arguments.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
59506
3da5314608ab Fixed typo in Commentary section.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 58938
diff changeset
31 ;; Before using, call `elint-initialize' to set up some argument
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; data. This takes a while. Then call elint-current-buffer or
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; elint-defun to lint a buffer or a defun.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; The linter will try to "include" any require'd libraries to find
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; the variables defined in those. There is a fair amount of voodoo
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; involved in this, but it seems to work in normal situations.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;; History:
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; To do:
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; * A list of all standard Emacs variables would be nice to have...
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; * Adding type checking. (Stop that sniggering!)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; Code:
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (defvar elint-log-buffer "*Elint*"
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 "*The buffer to insert lint messages in.")
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;;
58938
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
52 ;;; Data
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
53 ;;;
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
54
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
55 (defconst elint-standard-variables
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
56 '(abbrev-mode auto-fill-function buffer-auto-save-file-name
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
57 buffer-backed-up buffer-display-count buffer-display-table buffer-display-time buffer-file-coding-system buffer-file-format
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
58 buffer-file-name buffer-file-number buffer-file-truename
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
59 buffer-file-type buffer-invisibility-spec buffer-offer-save
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
60 buffer-read-only buffer-saved-size buffer-undo-list
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
61 cache-long-line-scans case-fold-search ctl-arrow cursor-type comment-column
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
62 default-directory defun-prompt-regexp desktop-save-buffer enable-multibyte-characters fill-column fringes-outside-margins goal-column
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
63 header-line-format indicate-buffer-boundaries indicate-empty-lines
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
64 left-fringe-width
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
65 left-margin left-margin-width line-spacing local-abbrev-table local-write-file-hooks major-mode
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
66 mark-active mark-ring mode-line-buffer-identification
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
67 mode-line-format mode-line-modified mode-line-process mode-name
63511
964ef053b1bc (elint-init-env): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 59506
diff changeset
68 overwrite-mode
58938
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
69 point-before-scroll right-fringe-width right-margin-width
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
70 scroll-bar-width scroll-down-aggressively scroll-up-aggressively selective-display
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
71 selective-display-ellipses tab-width truncate-lines vc-mode vertical-scroll-bar)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
72 "Standard buffer local vars.")
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
73
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
74 (defconst elint-unknown-builtin-args
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
75 '((while test &rest forms)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
76 (insert-before-markers-and-inherit &rest text)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
77 (catch tag &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
78 (and &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
79 (funcall func &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
80 (insert &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
81 (vconcat &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
82 (run-hook-with-args hook &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
83 (message-or-box string &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
84 (save-window-excursion &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
85 (append &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
86 (logior &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
87 (progn &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
88 (insert-and-inherit &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
89 (message-box string &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
90 (prog2 x y &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
91 (prog1 first &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
92 (insert-before-markers &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
93 (call-process-region start end program &optional delete
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
94 destination display &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
95 (concat &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
96 (vector &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
97 (run-hook-with-args-until-success hook &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
98 (track-mouse &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
99 (unwind-protect bodyform &rest unwindforms)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
100 (save-restriction &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
101 (quote arg)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
102 (make-byte-code &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
103 (or &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
104 (cond &rest clauses)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
105 (start-process name buffer program &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
106 (run-hook-with-args-until-failure hook &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
107 (if cond then &rest else)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
108 (apply function &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
109 (format string &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
110 (encode-time second minute hour day month year zone &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
111 (min &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
112 (logand &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
113 (logxor &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
114 (max &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
115 (list &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
116 (message string &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
117 (defvar symbol init doc)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
118 (call-process program &optional infile destination display &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
119 (with-output-to-temp-buffer bufname &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
120 (nconc &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
121 (save-excursion &rest body)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
122 (run-hooks &rest hooks)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
123 (/ x y &rest zs)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
124 (- x &rest y)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
125 (+ &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
126 (* &rest args)
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
127 (interactive &optional args))
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
128 "Those built-ins for which we can't find arguments.")
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
129
f3ac898990de (elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents: 58740
diff changeset
130 ;;;
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;;; ADT: top-form
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (defsubst elint-make-top-form (form pos)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 "Create a top form.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 FORM is the form, and POS is the point where it starts in the buffer."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (cons form pos))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (defsubst elint-top-form-form (top-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 "Extract the form from a TOP-FORM."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (car top-form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defsubst elint-top-form-pos (top-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 "Extract the position from a TOP-FORM."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (cdr top-form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;;; ADT: env
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defsubst elint-make-env ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 "Create an empty environment."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (list (list nil) nil nil))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (defsubst elint-env-add-env (env newenv)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 "Augment ENV with NEWENV.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 None of them is modified, and the new env is returned."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (list (append (car env) (car newenv))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (append (car (cdr env)) (car (cdr newenv)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (append (car (cdr (cdr env))) (car (cdr (cdr newenv))))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (defsubst elint-env-add-var (env var)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 "Augment ENV with the variable VAR.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 The new environment is returned, the old is unmodified."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (cons (cons (list var) (car env)) (cdr env)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (defsubst elint-env-add-global-var (env var)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 "Augment ENV with the variable VAR.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ENV is modified so VAR is seen everywhere.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ENV is returned."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (nconc (car env) (list (list var)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (defsubst elint-env-find-var (env var)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 "Non-nil if ENV contains the variable VAR.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 Actually, a list with VAR as a single element is returned."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (assq var (car env)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (defsubst elint-env-add-func (env func args)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 "Augment ENV with the function FUNC, which has the arguments ARGS.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 The new environment is returned, the old is unmodified."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (list (car env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (cons (list func args) (car (cdr env)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (car (cdr (cdr env)))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (defsubst elint-env-find-func (env func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 "Non-nil if ENV contains the function FUNC.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 Actually, a list of (FUNC ARGS) is returned."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (assq func (car (cdr env))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defsubst elint-env-add-macro (env macro def)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 "Augment ENV with the macro named MACRO.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 DEF is the macro definition (a lambda expression or similar).
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 The new environment is returned, the old is unmodified."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (list (car env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (car (cdr env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (cons (cons macro def) (car (cdr (cdr env))))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (defsubst elint-env-macro-env (env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 "Return the macro environment of ENV.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 This environment can be passed to `macroexpand'."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (car (cdr (cdr env))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (defsubst elint-env-macrop (env macro)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 "Non-nil if ENV contains MACRO."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (assq macro (elint-env-macro-env env)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;;; User interface
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (defun elint-current-buffer ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 "Lint the current buffer."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (interactive)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (elint-clear-log (format "Linting %s" (if (buffer-file-name)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (buffer-file-name)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (buffer-name))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (elint-display-log)
84899
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
219 (mapc 'elint-top-form (elint-update-env))
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;; Tell the user we're finished. This is terribly klugy: we set
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; elint-top-form-logged so elint-log-message doesn't print the
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; ** top form ** header...
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (let ((elint-top-form-logged t))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (elint-log-message "\nLinting complete.\n")))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
226
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (defun elint-defun ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 "Lint the function at point."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (interactive)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (save-excursion
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (if (not (beginning-of-defun))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (error "Lint what?"))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (let ((pos (point))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (def (read (current-buffer))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (elint-display-log)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (elint-update-env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (elint-top-form (elint-make-top-form def pos)))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ;;; Top form functions
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (defvar elint-buffer-env nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 "The environment of a elisp buffer.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 Will be local in linted buffers.")
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (defvar elint-buffer-forms nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 "The top forms in a buffer.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 Will be local in linted buffers.")
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (defvar elint-last-env-time nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 "The last time the buffers env was updated.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 Is measured in buffer-modified-ticks and is local in linted buffers.")
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (defun elint-update-env ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 "Update the elint environment in the current buffer.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 Don't do anything if the buffer hasn't been changed since this
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 function was called the last time.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 Returns the forms."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (if (and (local-variable-p 'elint-buffer-env (current-buffer))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (local-variable-p 'elint-buffer-forms (current-buffer))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (local-variable-p 'elint-last-env-time (current-buffer))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (= (buffer-modified-tick) elint-last-env-time))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;; Env is up to date
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 elint-buffer-forms
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ;; Remake env
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (set (make-local-variable 'elint-buffer-forms) (elint-get-top-forms))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (set (make-local-variable 'elint-buffer-env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (elint-init-env elint-buffer-forms))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (set (make-local-variable 'elint-last-env-time) (buffer-modified-tick))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 elint-buffer-forms))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
274
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (defun elint-get-top-forms ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 "Collect all the top forms in the current buffer."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (save-excursion
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (let ((tops nil))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (goto-char (point-min))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (while (elint-find-next-top-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (let ((pos (point)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (condition-case nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (setq tops (cons
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (elint-make-top-form (read (current-buffer)) pos)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 tops))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (end-of-file
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (goto-char pos)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (end-of-line)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (error "Missing ')' in top form: %s" (buffer-substring pos (point)))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 ))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (nreverse tops))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (defun elint-find-next-top-form ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 "Find the next top form from point.
42206
0f4506820432 Doc fix.
Pavel Janík <Pavel@Janik.cz>
parents: 38436
diff changeset
295 Return nil if there are no more forms, t otherwise."
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (parse-partial-sexp (point) (point-max) nil t)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (not (eobp)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (defun elint-init-env (forms)
63511
964ef053b1bc (elint-init-env): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 59506
diff changeset
300 "Initialize the environment from FORMS."
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (let ((env (elint-make-env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (while forms
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (setq form (elint-top-form-form (car forms))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 forms (cdr forms))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (cond
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;; Add defined variable
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ((memq (car form) '(defvar defconst defcustom))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (setq env (elint-env-add-var env (car (cdr form)))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;; Add function
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ((memq (car form) '(defun defsubst))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (setq env (elint-env-add-func env (car (cdr form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (car (cdr (cdr form))))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;; Add macro, both as a macro and as a function
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 ((eq (car form) 'defmacro)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (setq env (elint-env-add-macro env (car (cdr form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (cons 'lambda
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (cdr (cdr form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 env (elint-env-add-func env (car (cdr form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (car (cdr (cdr form))))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ;; Import variable definitions
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ((eq (car form) 'require)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (let ((name (eval (car (cdr form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (file (eval (car (cdr (cdr form))))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (setq env (elint-add-required-env env name file))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 ))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (defun elint-add-required-env (env name file)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 "Augment ENV with the variables definied by feature NAME in FILE."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (condition-case nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (let* ((libname (if (stringp file)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 file
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (symbol-name name)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 ;; First try to find .el files, then the raw name
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (lib1 (locate-library (concat libname ".el") t))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (lib (if lib1 lib1 (locate-library libname t))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 ;; Clear the messages :-/
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (message nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (if lib
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (save-excursion
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (set-buffer (find-file-noselect lib))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (elint-update-env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (setq env (elint-env-add-env env elint-buffer-env)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (error "dummy error...")))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (error
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (ding)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (message "Can't get variables from require'd library %s" name)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 env)
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
352
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (defun regexp-assoc (regexp alist)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 "Search for a key matching REGEXP in ALIST."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (let ((res nil))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (while (and alist (not res))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (if (and (stringp (car (car alist)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (string-match regexp (car (car alist))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (setq res (car alist))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (setq alist (cdr alist))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 res))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (defvar elint-top-form nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 "The currently linted top form, or nil.")
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (defvar elint-top-form-logged nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 "T if the currently linted top form has been mentioned in the log buffer.")
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (defun elint-top-form (form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 "Lint a top FORM."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (let ((elint-top-form form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (elint-top-form-logged nil))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (elint-form (elint-top-form-form form) elint-buffer-env)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 ;;; General form linting functions
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (defconst elint-special-forms
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 '((let . elint-check-let-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (let* . elint-check-let-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (setq . elint-check-setq-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (quote . elint-check-quote-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (cond . elint-check-cond-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (lambda . elint-check-defun-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (function . elint-check-function-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (setq-default . elint-check-setq-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (defun . elint-check-defun-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (defsubst . elint-check-defun-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (defmacro . elint-check-defun-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (defvar . elint-check-defvar-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (defconst . elint-check-defvar-form)
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
393 (defcustom . elint-check-defcustom-form)
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (macro . elint-check-macro-form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (condition-case . elint-check-condition-case-form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 "Functions to call when some special form should be linted.")
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
397
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (defun elint-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 "Lint FORM in the environment ENV.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 The environment created by the form is returned."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (cond
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 ((consp form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (let ((func (cdr (assq (car form) elint-special-forms))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (if func
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 ;; Special form
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (funcall func form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (let* ((func (car form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (args (elint-get-args func env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (argsok t))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (cond
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 ((eq args 'undefined)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (setq argsok nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (elint-error "Call to undefined function: %s" form))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
415
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 ((eq args 'unknown) nil)
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
417
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (t (setq argsok (elint-match-args form args))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 ;; Is this a macro?
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (if (elint-env-macrop env func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 ;; Macro defined in buffer, expand it
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (if argsok
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (elint-form (macroexpand form (elint-env-macro-env env)) env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (let ((fcode (if (symbolp func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (if (fboundp func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (indirect-function func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 func)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (if (and (listp fcode) (eq (car fcode) 'macro))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 ;; Macro defined outside buffer
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (if argsok
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (elint-form (macroexpand form) env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 ;; Function, lint its parameters
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (elint-forms (cdr form) env))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 ))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 ))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 ((symbolp form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 ;; :foo variables are quoted
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (if (and (/= (aref (symbol-name form) 0) ?:)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (elint-unbound-variable form env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (elint-warning "Reference to unbound symbol: %s" form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (t env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (defun elint-forms (forms env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 "Lint the FORMS, accumulating an environment, starting with ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 ;; grumblegrumbletailrecursiongrumblegrumble
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (while forms
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (setq env (elint-form (car forms) env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 forms (cdr forms)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (defun elint-unbound-variable (var env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 "T if VAR is unbound in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (not (or (eq var nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (eq var t)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (elint-env-find-var env var)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (memq var elint-standard-variables))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 ;;; Function argument checking
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (defun elint-match-args (arglist argpattern)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 "Match ARGLIST against ARGPATTERN."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (let ((state 'all)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (al (cdr arglist))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (ap argpattern)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (ok t))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (while
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (cond
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 ((and (null al) (null ap)) nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 ((eq (car ap) '&optional)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (setq state 'optional)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (setq ap (cdr ap))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 t)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 ((eq (car ap) '&rest)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 ((or (and (eq state 'all) (or (null al) (null ap)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (and (eq state 'optional) (and al (null ap))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (elint-error "Wrong number of args: %s, %s" arglist argpattern)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (setq ok nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 ((and (eq state 'optional) (null al))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 nil)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (t (setq al (cdr al)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 ap (cdr ap))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 t)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 ok))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (defun elint-get-args (func env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 "Find the args of FUNC in ENV.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 Returns `unknown' if we couldn't find arguments."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (let ((f (elint-env-find-func env func)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (if f
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (car (cdr f))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (if (symbolp func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (if (fboundp func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (let ((fcode (indirect-function func)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (if (subrp fcode)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (let ((args (get func 'elint-args)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (if args args 'unknown))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (elint-find-args-in-code fcode)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 'undefined)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (elint-find-args-in-code func)))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (defun elint-find-args-in-code (code)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 "Extract the arguments from CODE.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 CODE can be a lambda expression, a macro, or byte-compiled code."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (cond
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 ((byte-code-function-p code)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (aref code 0))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 ((and (listp code) (eq (car code) 'lambda))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (car (cdr code)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 ((and (listp code) (eq (car code) 'macro))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (elint-find-args-in-code (cdr code)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (t 'unknown)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 ;;; Functions to check some special forms
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (defun elint-check-cond-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 "Lint a cond FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (setq form (cdr form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (while form
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (if (consp (car form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (elint-forms (car form) env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (elint-error "cond clause should be a list: %s" (car form)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (setq form (cdr form)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (defun elint-check-defun-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 "Lint a defun/defmacro/lambda FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (setq form (if (eq (car form) 'lambda) (cdr form) (cdr (cdr form))))
84899
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
543 (mapc (function (lambda (p)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
544 (or (memq p '(&optional &rest))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
545 (setq env (elint-env-add-var env p)))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
546 ))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
547 (car form))
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (elint-forms (cdr form) env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (defun elint-check-let-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 "Lint the let/let* FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (let ((varlist (car (cdr form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (if (not varlist)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (progn
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (elint-error "Missing varlist in let: %s" form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 ;; Check for (let (a (car b)) ...) type of error
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (if (and (= (length varlist) 2)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (symbolp (car varlist))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (listp (car (cdr varlist)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (fboundp (car (car (cdr varlist)))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (elint-warning "Suspect varlist: %s" form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 ;; Add variables to environment, and check the init values
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (let ((newenv env))
84899
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
567 (mapc (function (lambda (s)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
568 (cond
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
569 ((symbolp s)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
570 (setq newenv (elint-env-add-var newenv s)))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
571 ((and (consp s) (<= (length s) 2))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
572 (elint-form (car (cdr s))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
573 (if (eq (car form) 'let)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
574 env
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
575 newenv))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
576 (setq newenv
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
577 (elint-env-add-var newenv (car s))))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
578 (t (elint-error
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
579 "Malformed `let' declaration: %s" s))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
580 )))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
581 varlist)
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 ;; Lint the body forms
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (elint-forms (cdr (cdr form)) newenv)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 ))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (defun elint-check-setq-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 "Lint the setq FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (or (= (mod (length form) 2) 1)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (elint-error "Missing value in setq: %s" form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (let ((newenv env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 sym val)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (setq form (cdr form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (while form
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (setq sym (car form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 val (car (cdr form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 form (cdr (cdr form)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (if (symbolp sym)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (if (elint-unbound-variable sym newenv)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (elint-warning "Setting previously unbound symbol: %s" sym))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (elint-error "Setting non-symbol in setq: %s" sym))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (elint-form val newenv)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (if (symbolp sym)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (setq newenv (elint-env-add-var newenv sym))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 newenv))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
607
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (defun elint-check-defvar-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 "Lint the defvar/defconst FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (if (or (= (length form) 2)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (= (length form) 3)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (and (= (length form) 4) (stringp (nth 3 form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (elint-env-add-global-var (elint-form (nth 2 form) env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (car (cdr form)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (elint-error "Malformed variable declaration: %s" form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 env))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
617
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
618 (defun elint-check-defcustom-form (form env)
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
619 "Lint the defcustom FORM in ENV."
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
620 (if (and (> (length form) 3)
52880
9417a94488d3 (elint-check-defcustom-form): Don't use `evenp' so we don't implicitly
John Paul Wallington <jpw@pobox.com>
parents: 52401
diff changeset
621 ;; even no. of keyword/value args ?
9417a94488d3 (elint-check-defcustom-form): Don't use `evenp' so we don't implicitly
John Paul Wallington <jpw@pobox.com>
parents: 52401
diff changeset
622 (zerop (logand (length form) 1)))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
623 (elint-env-add-global-var (elint-form (nth 2 form) env)
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
624 (car (cdr form)))
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
625 (elint-error "Malformed variable declaration: %s" form)
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
626 env))
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
627
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (defun elint-check-function-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 "Lint the function FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (let ((func (car (cdr-safe form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 (cond
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 ((symbolp func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (or (elint-env-find-func env func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (fboundp func)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 (elint-warning "Reference to undefined function: %s" form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 ((and (consp func) (memq (car func) '(lambda macro)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (elint-form func env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 ((stringp func) env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (t (elint-error "Not a function object: %s" form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 )))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (defun elint-check-quote-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 "Lint the quote FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 (defun elint-check-macro-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 "Check the macro FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 (elint-check-function-form (list (car form) (cdr form)) env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 (defun elint-check-condition-case-form (form env)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 "Check the condition-case FORM in ENV."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (let ((resenv env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 (if (< (length form) 3)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (elint-error "Malformed condition-case: %s" form)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (or (symbolp (car (cdr form)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (elint-warning "First parameter should be a symbol: %s" form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (setq resenv (elint-form (nth 2 form) env))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (let ((newenv (elint-env-add-var env (car (cdr form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (errforms (nthcdr 3 form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 errlist)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (while errforms
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (setq errlist (car (car errforms)))
84899
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
666 (mapc (function (lambda (s)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
667 (or (get s 'error-conditions)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
668 (get s 'error-message)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
669 (elint-warning
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
670 "Not an error symbol in error handler: %s" s))))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
671 (cond
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
672 ((symbolp errlist) (list errlist))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
673 ((listp errlist) errlist)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
674 (t (elint-error "Bad error list in error handler: %s"
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
675 errlist)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
676 nil))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
677 )
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 (elint-forms (cdr (car errforms)) newenv)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (setq errforms (cdr errforms))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 )))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 resenv))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
682
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 ;;; Message functions
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 ;; elint-error and elint-warning are identical, but they might change
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 ;; to reflect different seriousness of linting errors
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (defun elint-error (string &rest args)
47923
07d91c802db4 (elint-error, elint-warning): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 42268
diff changeset
691 "Report a linting error.
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 STRING and ARGS are thrown on `format' to get the message."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (let ((errstr (apply 'format string args)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (elint-log-message errstr)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 ))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
696
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (defun elint-warning (string &rest args)
47923
07d91c802db4 (elint-error, elint-warning): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 42268
diff changeset
698 "Report a linting warning.
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 STRING and ARGS are thrown on `format' to get the message."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (let ((errstr (apply 'format string args)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 (elint-log-message errstr)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 ))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 (defun elint-log-message (errstr)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 "Insert ERRSTR last in the lint log buffer."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (save-excursion
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (set-buffer (elint-get-log-buffer))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (goto-char (point-max))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (or (bolp) (newline))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 ;; Do we have to say where we are?
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (if elint-top-form-logged
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 nil
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (insert
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (let* ((form (elint-top-form-form elint-top-form))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (top (car form)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (cond
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 ((memq top '(defun defsubst))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (format "\n** function %s **\n" (car (cdr form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 ((eq top 'defmacro)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (format "\n** macro %s **\n" (car (cdr form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 ((memq top '(defvar defconst))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (format "\n** variable %s **\n" (car (cdr form))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (t "\n** top level expression **\n"))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (setq elint-top-form-logged t))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (insert errstr)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (newline)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (defun elint-clear-log (&optional header)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 "Clear the lint log buffer.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 Insert HEADER followed by a blank line if non-nil."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (save-excursion
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (set-buffer (elint-get-log-buffer))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (erase-buffer)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 (if header
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (progn
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (insert header)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (newline))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 )))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 (defun elint-display-log ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 "Display the lint log buffer."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (let ((pop-up-windows t))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (display-buffer (elint-get-log-buffer))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 (sit-for 0)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (defun elint-get-log-buffer ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 "Return a log buffer for elint."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (let ((buf (get-buffer elint-log-buffer)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (if buf
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 buf
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 (let ((oldbuf (current-buffer)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (prog1
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (set-buffer (get-buffer-create elint-log-buffer))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 (setq truncate-lines t)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (set-buffer oldbuf)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 )))
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
759
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 ;;;
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 ;;; Initializing code
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 ;;;
20014
2ecea967337d (elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents: 19210
diff changeset
763
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 ;;;###autoload
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (defun elint-initialize ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 "Initialize elint."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 (interactive)
84899
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
768 (mapc (function (lambda (x)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
769 (or (not (symbolp (car x)))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
770 (eq (cdr x) 'unknown)
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
771 (put (car x) 'elint-args (cdr x)))))
789f9201f375 (elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
772 (elint-find-builtin-args))
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 (mapcar (function (lambda (x)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (put (car x) 'elint-args (cdr x))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 elint-unknown-builtin-args))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 (defun elint-find-builtins ()
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 "Returns a list of all built-in functions."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (let ((subrs nil))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 (mapatoms (lambda (s) (if (and (fboundp s) (subrp (symbol-function s)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (setq subrs (cons s subrs)))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 subrs
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 ))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (defun elint-find-builtin-args (&optional list)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 "Returns a list of the built-in functions and their arguments.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 If LIST is nil, call `elint-find-builtins' to get a list of all built-in
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 functions, otherwise use LIST.
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 Each functions is represented by a cons cell:
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 \(function-symbol . args)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 If no documentation could be found args will be `unknown'."
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 (mapcar (function (lambda (f)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (let ((doc (documentation f t)))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (if (and doc (string-match "\n\n\\((.*)\\)" doc))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 (read (match-string 1 doc))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 (cons f 'unknown))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 )))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 (if list list
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 (elint-find-builtins))))
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 (provide 'elint)
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
807 ;; arch-tag: b2f061e2-af84-4ddc-8e39-f5e969ac228f
19210
ad26cf3804c3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 ;;; elint.el ends here