changeset 104049:7fcfa9c429bd

(elint-current-buffer, elint-defun): Add autoload cookies. If necessary, initialize. (elint-log): Handle non-file buffers. (elint-initialize): Add optional argument to reinitialize. (elint-find-builtin-variables): Save excursion.
author Glenn Morris <rgm@gnu.org>
date Fri, 24 Jul 2009 03:52:42 +0000
parents 712697e0dfcc
children 8ee742481c0a
files lisp/ChangeLog lisp/emacs-lisp/elint.el
diffstat 2 files changed, 57 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Jul 23 14:41:05 2009 +0000
+++ b/lisp/ChangeLog	Fri Jul 24 03:52:42 2009 +0000
@@ -1,3 +1,11 @@
+2009-07-24  Glenn Morris  <rgm@gnu.org>
+
+	* emacs-lisp/elint.el (elint-current-buffer, elint-defun):
+	Add autoload cookies.  If necessary, initialize.
+	(elint-log): Handle non-file buffers.
+	(elint-initialize): Add optional argument to reinitialize.
+	(elint-find-builtin-variables): Save excursion.
+
 2009-07-23  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* emacs-lisp/lisp-mode.el (emacs-lisp-mode-map): Add menu entries
--- a/lisp/emacs-lisp/elint.el	Thu Jul 23 14:41:05 2009 +0000
+++ b/lisp/emacs-lisp/elint.el	Fri Jul 24 03:52:42 2009 +0000
@@ -28,9 +28,9 @@
 ;; misspellings and undefined variables, although it can also catch
 ;; function calls with the wrong number of arguments.
 
-;; Before using, call `elint-initialize' to set up some argument
-;; data.  This takes a while.  Then call elint-current-buffer or
-;; elint-defun to lint a buffer or a defun.
+;; To use, call elint-current-buffer or elint-defun to lint a buffer
+;; or defun.  The first call runs `elint-initialize' to set up some
+;; argument data, which may take a while.
 
 ;; The linter will try to "include" any require'd libraries to find
 ;; the variables defined in those.  There is a fair amount of voodoo
@@ -151,9 +151,13 @@
 ;;; User interface
 ;;;
 
+;;;###autoload
 (defun elint-current-buffer ()
-  "Lint the current buffer."
+  "Lint the current buffer.
+If necessary, this first calls `elint-initalize'."
   (interactive)
+  (or elint-builtin-variables
+      (elint-initialize))
   (elint-clear-log (format "Linting %s" (or (buffer-file-name)
 					    (buffer-name))))
   (elint-display-log)
@@ -164,9 +168,13 @@
   (let ((elint-top-form-logged t))
     (elint-log-message "\nLinting finished.\n")))
 
+;;;###autoload
 (defun elint-defun ()
-  "Lint the function at point."
+  "Lint the function at point.
+If necessary, this first calls `elint-initalize'."
   (interactive)
+  (or elint-builtin-variables
+      (elint-initialize))
   (save-excursion
     (or (beginning-of-defun) (error "Lint what?"))
     (let ((pos (point))
@@ -610,7 +618,10 @@
 
 (defun elint-log (type string args)
   (elint-log-message (format "%s:%d:%s: %s"
-			     (file-name-nondirectory (buffer-file-name))
+			     (let ((f (buffer-file-name)))
+			       (if f
+				   (file-name-nondirectory f)
+				 (buffer-name)))
 			     (save-excursion
 			       (goto-char elint-current-pos)
 			       (1+ (count-lines (point-min)
@@ -680,18 +691,24 @@
 ;;;
 
 ;;;###autoload
-(defun elint-initialize ()
-  "Initialize elint."
-  (interactive)
-  (setq elint-builtin-variables (elint-find-builtin-variables)
-	elint-autoloaded-variables (elint-find-autoloaded-variables))
-  (mapc (lambda (x) (or (not (symbolp (car x)))
-			(eq (cdr x) 'unknown)
-			(put (car x) 'elint-args (cdr x))))
-	(elint-find-builtin-args))
-  (if elint-unknown-builtin-args
-      (mapc (lambda (x) (put (car x) 'elint-args (cdr x)))
-	    elint-unknown-builtin-args)))
+(defun elint-initialize (&optional reinit)
+  "Initialize elint.
+If elint is already initialized, this does nothing, unless
+optional prefix argument REINIT is non-nil."
+  (interactive "P")
+  (if (and elint-builtin-variables (not reinit))
+      (message "Elint is already initialized")
+    (message "Initializing elint...")
+    (setq elint-builtin-variables (elint-find-builtin-variables)
+	  elint-autoloaded-variables (elint-find-autoloaded-variables))
+    (mapc (lambda (x) (or (not (symbolp (car x)))
+			  (eq (cdr x) 'unknown)
+			  (put (car x) 'elint-args (cdr x))))
+	  (elint-find-builtin-args))
+    (if elint-unknown-builtin-args
+	(mapc (lambda (x) (put (car x) 'elint-args (cdr x)))
+	      elint-unknown-builtin-args))
+    (message "Initializing elint...done")))
 
 
 (defun elint-find-builtin-variables ()
@@ -699,19 +716,20 @@
   ;; Cribbed from help-fns.el.
   (let ((docbuf " *DOC*")
 	vars var)
-    (if (get-buffer docbuf)
-	(progn
-	  (set-buffer docbuf)
-	  (goto-char (point-min)))
-      (set-buffer (get-buffer-create docbuf))
-      (insert-file-contents-literally
-       (expand-file-name internal-doc-file-name doc-directory)))
-    (while (search-forward "V" nil t)
-      (and (setq var (intern-soft
-		      (buffer-substring (point) (line-end-position))))
-	   (boundp var)
-	   (setq vars (cons var vars))))
-    vars))
+    (save-excursion
+      (if (get-buffer docbuf)
+	  (progn
+	    (set-buffer docbuf)
+	    (goto-char (point-min)))
+	(set-buffer (get-buffer-create docbuf))
+	(insert-file-contents-literally
+	 (expand-file-name internal-doc-file-name doc-directory)))
+      (while (search-forward "V" nil t)
+	(and (setq var (intern-soft
+			(buffer-substring (point) (line-end-position))))
+	     (boundp var)
+	     (setq vars (cons var vars))))
+      vars)))
 
 (defun elint-find-autoloaded-variables ()
   "Return a list of all autoloaded variables."