]> code.delx.au - gnu-emacs/commitdiff
Add new command checkdoc-package-keywords
authorOleh Krehel <ohwoeowho@gmail.com>
Mon, 8 Jun 2015 14:41:00 +0000 (16:41 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Mon, 8 Jun 2015 14:54:51 +0000 (16:54 +0200)
* lisp/emacs-lisp/checkdoc.el (checkdoc-package-keywords-flag): New
  defcustom.
(checkdoc-list-of-strings-p): Add doc.
(checkdoc-current-buffer): When `checkdoc-package-keywords-flag' is
non-nil, call `checkdoc-package-keywords'.
(checkdoc-get-keywords): New defun.
(checkdoc-package-keywords): New command. Warns if the current file
has package.el-style keywords that aren't in `finder-known-keywords'.

* etc/NEWS: Add entry.

etc/NEWS
lisp/emacs-lisp/checkdoc.el

index 51d0a5f4fecfd401929a5e4ce0c6d1499901a3e1..571adadc61c493ed5e0c01390e489bd476404686 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -84,6 +84,11 @@ command line when `initial-buffer-choice' is non-nil.
 \f
 * Changes in Emacs 25.1
 
+** New command `checkdoc-package-keywords' checks if the
+current package keywords are recognized. Set the new option
+`checkdoc-package-keywords-flag' to non-nil to make
+`checkdoc-current-buffer' call this function automatically.
+
 ** New function `checkdoc-file' checks for style errors.
 It's meant for use together with `compile':
 emacs -batch --eval "(checkdoc-file \"subr.el\")"
index 869ae431950f2542d8b20f39add6c1a90e765f5a..b20e4f1e2df8225c993826fa87e12a01c5d2a6a1 100644 (file)
@@ -267,6 +267,11 @@ made in the style guide relating to order."
   :type 'boolean)
 ;;;###autoload(put 'checkdoc-arguments-in-order-flag 'safe-local-variable #'booleanp)
 
+(defcustom checkdoc-package-keywords-flag nil
+  "Non-nil means warn if this file's package keywords are not recognized.
+Currently, all recognized keywords must be on `finder-known-keywords'."
+  :type 'boolean)
+
 (define-obsolete-variable-alias 'checkdoc-style-hooks
   'checkdoc-style-functions "24.3")
 (defvar checkdoc-style-functions nil
@@ -315,6 +320,7 @@ This should be set in an Emacs Lisp file's local variables."
 
 ;;;###autoload
 (defun checkdoc-list-of-strings-p (obj)
+  "Return t when OBJ is a list of strings."
   ;; this is a function so it might be shared by checkdoc-proper-noun-list
   ;; and/or checkdoc-ispell-lisp-words in the future
   (and (listp obj)
@@ -866,6 +872,8 @@ otherwise stop after the first error."
        (checkdoc-start)
        (checkdoc-message-text)
        (checkdoc-rogue-spaces)
+        (when checkdoc-package-keywords-flag
+          (checkdoc-package-keywords))
        (not (called-interactively-p 'interactive))
        (if take-notes (checkdoc-show-diagnostics))
        (message "Checking buffer for style...Done."))))
@@ -2644,6 +2652,37 @@ function called to create the messages."
        (setq checkdoc-pending-errors nil)
        nil)))
 
+(defun checkdoc-get-keywords ()
+  "Return a list of package keywords for the current file."
+  (require 'finder)
+  (save-excursion
+    (goto-char (point-min))
+    (when (re-search-forward "^;; Keywords: \\(.*\\)$" nil t)
+      (split-string (match-string-no-properties 1) ", " t))))
+
+;;;###autoload
+(defun checkdoc-package-keywords ()
+  "Find package keywords that aren't in `finder-known-keywords'."
+  (interactive)
+  (let ((unrecognized-keys
+         (cl-remove-if
+          (lambda (x) (assoc (intern-soft x) finder-known-keywords))
+          (checkdoc-get-keywords))))
+    (if unrecognized-keys
+        (let* ((checkdoc-autofix-flag 'never)
+               (checkdoc-generate-compile-warnings-flag t))
+          (save-excursion
+            (goto-char (point-min))
+            (re-search-forward "^;; Keywords: \\(.*\\)$" nil t)
+            (checkdoc-start-section "checkdoc-package-keywords")
+            (checkdoc-create-error
+             (concat "Unrecognized keywords: "
+                     (mapconcat #'identity unrecognized-keys ", "))
+             (match-beginning 1) (match-end 1)))
+          (checkdoc-show-diagnostics))
+      (when (called-interactively-p 'any)
+        (message "No Package Keyword Errors.")))))
+
 (custom-add-option 'emacs-lisp-mode-hook 'checkdoc-minor-mode)
 
 (provide 'checkdoc)