]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/elint.el
; Merge from origin/emacs-25
[gnu-emacs] / lisp / emacs-lisp / elint.el
index 0b8aa0345008e17f81a7d4c32573cfc065d286d9..7f0f947ec04ef625072ce673a036574842fd3e82 100644 (file)
@@ -1,6 +1,6 @@
 ;;; elint.el --- Lint Emacs Lisp
 
-;; Copyright (C) 1997, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: Peter Liljenberg <petli@lysator.liu.se>
 ;; Created: May 1997
@@ -249,9 +249,9 @@ This environment can be passed to `macroexpand'."
     (elint-set-mode-line t)
     (with-current-buffer elint-log-buffer
       (unless (string-equal default-directory dir)
-       (elint-log-message (format "\f\nLeaving directory `%s'"
-                                  default-directory) t)
-       (elint-log-message (format "Entering directory `%s'" dir) t)
+       (elint-log-message (format-message "\f\nLeaving directory `%s'"
+                                           default-directory) t)
+       (elint-log-message (format-message "Entering directory `%s'" dir) t)
        (setq default-directory dir))))
   (let ((str (format "Linting file %s" file)))
     (message "%s..." str)
@@ -296,7 +296,7 @@ If necessary, this first calls `elint-initialize'."
   (elint-display-log)
   (elint-set-mode-line t)
   (mapc 'elint-top-form (elint-update-env))
-  ;; Tell the user we're finished.  This is terribly klugy: we set
+  ;; Tell the user we're finished.  This is terribly kludgy: we set
     ;; elint-top-form-logged so elint-log-message doesn't print the
     ;; ** top form ** header...
   (elint-set-mode-line)
@@ -335,7 +335,7 @@ Will be local in linted buffers.")
 Is measured in buffer-modified-ticks and is local in linted buffers.")
 
 ;; This is a minor optimization.  It is local to every buffer, and so
-;; does not prevent recursive requirs.  It does not list the requires
+;; does not prevent recursive requires.  It does not list the requires
 ;; of requires.
 (defvar elint-features nil
   "List of all libraries this buffer has required, or that have been provided.")
@@ -357,6 +357,8 @@ Returns the forms."
     (set (make-local-variable 'elint-buffer-env)
         (elint-init-env elint-buffer-forms))
     (if elint-preloaded-env
+        ;; FIXME: This doesn't do anything!  Should we setq the result to
+        ;; elint-buffer-env?
        (elint-env-add-env elint-preloaded-env elint-buffer-env))
     (set (make-local-variable 'elint-last-env-time) (buffer-modified-tick))
     elint-buffer-forms))
@@ -370,9 +372,9 @@ Returns the forms."
        (let ((elint-current-pos (point)))
          ;; non-list check could be here too. errors may be out of seq.
          ;; quoted check cannot be elsewhere, since quotes skipped.
-         (if (looking-back "'")
+         (if (looking-back "'" (1- (point)))
              ;; Eg cust-print.el uses ' as a comment syntax.
-             (elint-warning "Skipping quoted form `'%.20s...'"
+             (elint-warning "Skipping quoted form `%c%.20s...'" ?\'
                           (read (current-buffer)))
            (condition-case nil
                (setq tops (cons
@@ -381,7 +383,7 @@ Returns the forms."
                            tops))
              (end-of-file
               (goto-char elint-current-pos)
-              (error "Missing ')' in top form: %s"
+              (error "Missing `)' in top form: %s"
                      (buffer-substring elint-current-pos
                                        (line-end-position))))))))
       (nreverse tops))))
@@ -464,6 +466,9 @@ Return nil if there are no more forms, t otherwise."
        (add-to-list 'elint-features name)
        ;; cl loads cl-macs in an opaque manner.
        ;; Since cl-macs requires cl, we can just process cl-macs.
+        ;; FIXME: AFAIK, `cl' now behaves properly and does not need any
+        ;; special treatment any more.  Can someone who understands this
+        ;; code confirm?  --Stef
        (and (eq name 'cl) (not elint-doing-cl)
             ;; We need cl if elint-form is to be able to expand cl macros.
             (require 'cl)
@@ -515,7 +520,7 @@ Return nil if there are no more forms, t otherwise."
              ;;;       (with-syntax-table emacs-lisp-mode-syntax-table
              ;;;         (elint-update-env))
              ;;;       (setq env (elint-env-add-env env elint-buffer-env))))
-             ;;(message "Elint processed (require '%s)" name))
+             ;;(message "%s" (format "Elint processed (require '%s)" name))
          (error "%s.el not found in load-path" libname)))
     (error
      (message "Can't get variables from require'd library %s: %s"
@@ -708,14 +713,8 @@ Returns `unknown' if we couldn't find arguments."
 (defun elint-find-args-in-code (code)
   "Extract the arguments from CODE.
 CODE can be a lambda expression, a macro, or byte-compiled code."
-  (cond
-   ((byte-code-function-p code)
-    (aref code 0))
-   ((and (listp code) (eq (car code) 'lambda))
-    (car (cdr code)))
-   ((and (listp code) (eq (car code) 'macro))
-    (elint-find-args-in-code (cdr code)))
-   (t 'unknown)))
+  (let ((args (help-function-arglist code)))
+    (if (listp args) args 'unknown)))
 
 ;;;
 ;;; Functions to check some special forms
@@ -983,7 +982,7 @@ Does basic handling of `featurep' tests."
                                                    (line-beginning-position))))
                               0)       ; unknown position
                             type
-                            (apply 'format string args))))
+                            (apply #'format-message string args))))
 
 (defun elint-error (string &rest args)
   "Report a linting error.
@@ -1098,7 +1097,7 @@ optional prefix argument REINIT is non-nil."
 ;; This includes all the built-in and dumped things with documentation.
 (defun elint-scan-doc-file ()
   "Scan the DOC file for function and variables.
-Marks the function wih their arguments, and returns a list of variables."
+Marks the function with their arguments, and returns a list of variables."
   ;; Cribbed from help-fns.el.
   (let ((docbuf " *DOC*")
        vars sym args)
@@ -1144,8 +1143,8 @@ Marks the function wih their arguments, and returns a list of variables."
 (defun elint-find-builtins ()
   "Return a list of all built-in functions."
   (let (subrs)
-    (mapatoms (lambda (s) (and (fboundp s) (subrp (symbol-function s))
-                              (setq subrs (cons s subrs)))))
+    (mapatoms (lambda (s) (and (subrp (symbol-function s))
+                          (push s subrs))))
     subrs))
 
 (defun elint-find-builtin-args (&optional list)