[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/relint 350a9e4 7/8: Extend regexp-generating heuristics

From: Mattias Engdegård
Subject: [elpa] externals/relint 350a9e4 7/8: Extend regexp-generating heuristics
Date: Mon, 1 Apr 2019 08:53:38 -0400 (EDT)

branch: externals/relint
commit 350a9e4e90d4747ca8538a3332868b4b7a943ab6
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Extend regexp-generating heuristics
    Recognise more standard regexp-returning functions, several
    standard regexp variables, and look at variable names to determine
    whether they are likely to contain regexps.
 relint.el | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/relint.el b/relint.el
index e6d1586..343112a 100644
--- a/relint.el
+++ b/relint.el
@@ -706,16 +706,29 @@
                  re (format "%s (%s)" name rule-name) file pos path)))))
         (relint--get-list form file pos path)))
-;; List of known regexp-generating functions used in EXPR.
+;; List of regexp-generating functions and variables used in EXPR.
 ;; EXPANDED is a list of expanded functions, to prevent recursion.
 (defun relint--regexp-generators (expr expanded)
    ((symbolp expr)
-    (let ((def (assq expr relint--variables)))
-      (and def (relint--regexp-generators (cdr def) expanded))))
+    (and (not (memq expr '(nil t)))
+         (let ((def (assq expr relint--variables)))
+           (if def
+               (relint--regexp-generators (cdr def) expanded)
+             (and (or (memq expr '(page-delimiter paragraph-separate
+                                   paragraph-start sentence-end))
+                      ;; This is guesswork, but effective.
+                      (string-match-p
+                       (rx (or (seq bos (or "regexp" "regex"))
+                               (or "-regexp" "-regex" "-re"))
+                           eos)
+                       (symbol-name expr)))
+                  (list expr))))))
    ((atom expr) nil)
    ((memq (car expr) '(regexp-quote regexp-opt regexp-opt-charset
-                       rx rx-to-string wildcard-to-regexp))
+                       rx rx-to-string wildcard-to-regexp read-regexp
+                       char-fold-to-regexp find-tag-default-as-regexp
+                       find-tag-default-as-symbol-regexp sentence-end))
     (list (car expr)))
    ((memq (car expr) '(looking-at re-search-forward re-search-backward
                        string-match string-match-p looking-back looking-at-p))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]