emacs-diffs
[Top][All Lists]
Advanced

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

emacs-27 4acdd7f: Fix edge case errors in filename-matching regexps


From: Mattias Engdegård
Subject: emacs-27 4acdd7f: Fix edge case errors in filename-matching regexps
Date: Tue, 14 Apr 2020 06:40:18 -0400 (EDT)

branch: emacs-27
commit 4acdd7fe58ae9f94102afeca67b0383141d597da
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Fix edge case errors in filename-matching regexps
    
    These changes fix actual or latent bugs in regexps that match
    file names, such as PATTERN arguments to 'directory-files'.  See
    https://lists.gnu.org/archive/html/emacs-devel/2020-04/msg00265.html
    
    * admin/authors.el (authors-obsolete-files-regexps)
    (authors-renamed-files-regexps):
    * lisp/auth-source-pass.el (auth-source-pass-entries):
    * lisp/calendar/todo-mode.el (todo-show, todo-find-filtered-items-file)
    (todo-filter-items, todo-reset-nondiary-marker, todo-reset-done-string)
    (todo-reset-comment-string, todo-reset-highlight-item):
    * lisp/cedet/semantic/db-ebrowse.el (semanticdb-load-ebrowse-caches):
    * lisp/cedet/semantic/texi.el (semantic-texi-associated-files):
    * lisp/cedet/srecode/map.el (srecode-map-update-map):
    * lisp/dired.el (dired-re-no-dot):
    * lisp/emacs-lisp/autoload.el (update-directory-autoloads):
    * lisp/emacs-lisp/shadow.el (load-path-shadows-find):
    * lisp/files.el (auto-mode-alist, directory-files-no-dot-files-regexp):
    * lisp/finder.el (finder-compile-keywords):
    * lisp/generic-x.el (inetd-conf-generic-mode, named-boot-generic-mode)
    (resolve-conf-generic-mode, etc-modules-conf-generic-mode):
    * lisp/gnus/gnus-agent.el (gnus-agent-read-agentview)
    (gnus-agent-regenerate-group, gnus-agent-update-files-total-fetched-for):
    * lisp/gnus/gnus-cache.el (gnus-cache-articles-in-group):
    * lisp/gnus/gnus-score.el (gnus-score-search-global-directories):
    * lisp/gnus/gnus-util.el (gnus-delete-directory):
    * lisp/gnus/gnus-uu.el (gnus-uu-dir-files):
    * lisp/gnus/nndraft.el (nndraft-request-group):
    * lisp/gnus/nnmh.el (nnmh-request-group, nnmh-request-create-group):
    (nnmh-request-delete-group, nnmh-active-number, nnmh-update-gnus-unreads):
    * lisp/gnus/nnspool.el (nnspool-request-group):
    * lisp/gnus/spam-stat.el (spam-stat-process-directory)
    (spam-stat-test-directory):
    * lisp/help-fns.el (help-fns--first-release):
    * lisp/help.el (view-emacs-news):
    * lisp/international/quail.el (quail-update-leim-list-file):
    * lisp/international/titdic-cnv.el (batch-titdic-convert):
    * lisp/mail/mspools.el (mspools-set-vm-spool-files)
    (mspools-get-spool-files):
    * lisp/mail/rmail.el (rmail-secondary-file-regexp)
    (rmail-speedbar-match-folder-regexp):
    * lisp/net/ange-ftp.el (ange-ftp-delete-directory):
    * lisp/net/tramp.el (tramp-use-absolute-autoload-file-names):
    * lisp/obsolete/gulp.el (gulp-send-requests):
    * lisp/obsolete/vc-arch.el (vc-arch-trim-revlib):
    * lisp/org/ob-core.el (org-babel-remove-temporary-directory):
    * lisp/progmodes/ebnf2ps.el (ebnf-file-suffix-regexp, ebnf-style-database):
    * lisp/progmodes/executable.el (executable-command-find-posix-p):
    * lisp/startup.el (command-line):
    * lisp/textmodes/refer.el (refer-get-bib-files):
    * lisp/url/url-about.el (url-probe-protocols):
    * lisp/vc/vc-rcs.el (vc-rcs-register, vc-rcs-unregister):
    * test/lisp/net/tramp-archive-tests.el
    (tramp-archive-test19-directory-files-and-attributes):
    * test/lisp/net/tramp-tests.el 
(tramp-test19-directory-files-and-attributes):
    Replace ^ and $ with \` and \', respectively.
    Use (rx (or (not ".") "...")), translated into "[^.]\\|\\.\\.\\.",
    to match anything but "." and "..", instead of several incorrect
    regexps.
---
 admin/authors.el                     |  8 ++++----
 lisp/auth-source-pass.el             |  2 +-
 lisp/calendar/todo-mode.el           | 14 +++++++-------
 lisp/cedet/semantic/db-ebrowse.el    |  4 +++-
 lisp/cedet/semantic/texi.el          |  2 +-
 lisp/cedet/srecode/map.el            |  2 +-
 lisp/dired.el                        |  2 +-
 lisp/emacs-lisp/autoload.el          |  2 +-
 lisp/emacs-lisp/shadow.el            |  3 ++-
 lisp/files.el                        |  6 +++---
 lisp/finder.el                       |  2 +-
 lisp/generic-x.el                    |  8 ++++----
 lisp/gnus/gnus-agent.el              |  7 ++++---
 lisp/gnus/gnus-cache.el              |  2 +-
 lisp/gnus/gnus-score.el              |  2 +-
 lisp/gnus/gnus-util.el               |  2 +-
 lisp/gnus/gnus-uu.el                 |  2 +-
 lisp/gnus/nndraft.el                 |  2 +-
 lisp/gnus/nnmh.el                    | 10 +++++-----
 lisp/gnus/nnspool.el                 |  2 +-
 lisp/gnus/spam-stat.el               |  4 ++--
 lisp/help-fns.el                     |  2 +-
 lisp/help.el                         |  2 +-
 lisp/international/quail.el          |  2 +-
 lisp/international/titdic-cnv.el     |  2 +-
 lisp/mail/mspools.el                 |  4 ++--
 lisp/mail/rmail.el                   |  5 +++--
 lisp/net/ange-ftp.el                 |  3 +--
 lisp/net/tramp.el                    |  2 +-
 lisp/obsolete/gulp.el                |  2 +-
 lisp/obsolete/vc-arch.el             |  8 +++++---
 lisp/org/ob-core.el                  |  2 +-
 lisp/progmodes/ebnf2ps.el            |  4 ++--
 lisp/progmodes/executable.el         |  2 +-
 lisp/startup.el                      |  4 ++--
 lisp/textmodes/refer.el              |  2 +-
 lisp/url/url-about.el                |  2 +-
 lisp/vc/vc-rcs.el                    |  5 ++---
 test/lisp/net/tramp-archive-tests.el |  2 +-
 test/lisp/net/tramp-tests.el         |  2 +-
 40 files changed, 75 insertions(+), 70 deletions(-)

diff --git a/admin/authors.el b/admin/authors.el
index dc42bc7..6cf7b95 100644
--- a/admin/authors.el
+++ b/admin/authors.el
@@ -278,7 +278,7 @@ If REALNAME is nil, ignore that author.")
 
 
 (defvar authors-obsolete-files-regexps
-  '(".*loaddefs.el$"                   ; not obsolete, but auto-generated
+  '(".*loaddefs\\.el$"                 ; not obsolete, but auto-generated
     "\\.\\(bzr\\|cvs\\|git\\)ignore$"          ; obsolete or uninteresting
     "\\.arch-inventory$"
     "ChangeLog\\(\\.[0-9]+\\)?\\'"
@@ -288,9 +288,9 @@ If REALNAME is nil, ignore that author.")
     "\\`\\(indent\\|automated\\)\\'" "indent/" "mod-test/"
     "-resources/"
     "unidata/.*\\.txt\\'"
-    "BidiCharacterTest.txt"
+    "BidiCharacterTest\\.txt"
     ;; TODO lib/? Matches other things?
-    "build-aux/" "m4/" "Emacs.xcodeproj" "mapfiles" "\\.map\\'"
+    "build-aux/" "m4/" "Emacs\\.xcodeproj" "mapfiles" "\\.map\\'"
     "preferences\\.\\(nib\\|gorm\\)"
     ;; Generated files that have since been removed.
     "\\(refcard\\(-de\\|-pl\\)?\\|calccard\\|dired-ref\\|orgcard\\|\
@@ -1183,7 +1183,7 @@ 
ediff\\|emerge\\|log-edit\\|log-view\\|pcvs\\|smerge-mode\\|vc\\)\\.el\\'"
     ("\\`org-\\(ascii\\|beamer\\|html\\|icalendar\\|jsinfo\\|latex\
 \\|odt\\|publish\\)\\.el\\'" "ox-\\1.el")
     ;; From test/ to test/automated/.
-    ("comint-testsuite.el" "automated/\\&")
+    ("comint-testsuite\\.el" "automated/\\&")
     ("\\`\\(bytecomp\\|font-parse\\|icalendar\\|occur\\|newsticker\\)\
 -testsuite\\.el" "\\1-tests.el")
     ("automated/flymake/warnpred/\\(Makefile\\|test\\.\\(?:c\\|pl\\)\\)\\'"
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index e2a6bfe..ba66d0b 100644
--- a/lisp/auth-source-pass.el
+++ b/lisp/auth-source-pass.el
@@ -190,7 +190,7 @@ CONTENTS is the contents of a password-store formatted 
file."
   (let ((store-dir (expand-file-name auth-source-pass-filename)))
     (mapcar
      (lambda (file) (file-name-sans-extension (file-relative-name file 
store-dir)))
-     (directory-files-recursively store-dir "\\.gpg$"))))
+     (directory-files-recursively store-dir "\\.gpg\\'"))))
 
 (defun auth-source-pass--find-match (host user port)
   "Return password-store entry data matching HOST, USER and PORT.
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el
index 6d8fe9c..a49f428 100644
--- a/lisp/calendar/todo-mode.el
+++ b/lisp/calendar/todo-mode.el
@@ -707,7 +707,7 @@ and done items are always shown on visiting a category."
                                    shortf todo-show-first)))
                     (when (eq todo-show-first 'regexp)
                       (let ((rxfiles (directory-files todo-directory t
-                                                      ".*\\.todr$" t)))
+                                                      "\\.todr\\'" t)))
                         (when (and rxfiles (> (length rxfiles) 1))
                           (let ((rxf (mapcar #'todo-short-file-name rxfiles)))
                             (setq fi-file (todo-absolute-file-name
@@ -4054,7 +4054,7 @@ regexp items."
 (defun todo-find-filtered-items-file ()
   "Choose a filtered items file and visit it."
   (interactive)
-  (let ((files (directory-files todo-directory t "\\.tod[rty]$" t))
+  (let ((files (directory-files todo-directory t "\\.tod[rty]\\'" t))
        falist file)
     (dolist (f files)
       (let ((sf-name (todo-short-file-name f))
@@ -4187,7 +4187,7 @@ multifile commands for further details."
                                (regexp ".todr")))))
         (multi (> (length flist) 1))
         (rxfiles (when regexp
-                   (directory-files todo-directory t ".*\\.todr$" t)))
+                   (directory-files todo-directory t "\\.todr\\'" t)))
         (file-exists (or (file-exists-p fname) rxfiles))
         bufname)
     (cond ((and top new (natnump new))
@@ -6154,7 +6154,7 @@ the empty string (i.e., no time string)."
   "The :set function for user option `todo-nondiary-marker'."
   (let* ((oldvalue (symbol-value symbol))
         (files (append todo-files todo-archives
-                       (directory-files todo-directory t "\\.tod[rty]$" t))))
+                       (directory-files todo-directory t "\\.tod[rty]\\'" t))))
     (custom-set-default symbol value)
     ;; Need to reset these to get font-locking right.
     (setq todo-nondiary-start (nth 0 todo-nondiary-marker)
@@ -6207,7 +6207,7 @@ the empty string (i.e., no time string)."
   "The :set function for user option `todo-done-string'."
   (let ((oldvalue (symbol-value symbol))
        (files (append todo-files todo-archives
-                      (directory-files todo-directory t "\\.todr$" t))))
+                      (directory-files todo-directory t "\\.todr\\'" t))))
     (custom-set-default symbol value)
     ;; Need to reset this to get font-locking right.
     (setq todo-done-string-start
@@ -6236,7 +6236,7 @@ the empty string (i.e., no time string)."
   "The :set function for user option `todo-comment-string'."
   (let ((oldvalue (symbol-value symbol))
        (files (append todo-files todo-archives
-                      (directory-files todo-directory t "\\.todr$" t))))
+                      (directory-files todo-directory t "\\.todr\\'" t))))
     (custom-set-default symbol value)
     (when (not (equal value oldvalue))
       (dolist (f files)
@@ -6262,7 +6262,7 @@ the empty string (i.e., no time string)."
   "The :set function for user option `todo-highlight-item'."
   (let ((oldvalue (symbol-value symbol))
        (files (append todo-files todo-archives
-                      (directory-files todo-directory t "\\.tod[rty]$" t))))
+                      (directory-files todo-directory t "\\.tod[rty]\\'" t))))
     (custom-set-default symbol value)
     (when (not (equal value oldvalue))
       (dolist (f files)
diff --git a/lisp/cedet/semantic/db-ebrowse.el 
b/lisp/cedet/semantic/db-ebrowse.el
index 55e755d..a3219af 100644
--- a/lisp/cedet/semantic/db-ebrowse.el
+++ b/lisp/cedet/semantic/db-ebrowse.el
@@ -181,7 +181,9 @@ is specified by `semanticdb-default-save-directory'."
   "Load all semanticdb controlled EBROWSE caches."
   (interactive)
   (let ((f (directory-files semanticdb-default-save-directory
-                           t (concat semanticdb-ebrowse-default-file-name 
"-load.el$") t)))
+                           t (concat semanticdb-ebrowse-default-file-name
+                                      "-load\\.el\\'")
+                            t)))
     (while f
       (load (car f) nil t)
       (setq f (cdr f)))
diff --git a/lisp/cedet/semantic/texi.el b/lisp/cedet/semantic/texi.el
index 760cb19..8e8d362 100644
--- a/lisp/cedet/semantic/texi.el
+++ b/lisp/cedet/semantic/texi.el
@@ -495,7 +495,7 @@ that start with that symbol."
               (setq tabs (cdr tabs)))
             r))
          (t
-          (directory-files default-directory nil "\\.texi$"))
+          (directory-files default-directory nil "\\.texi\\'"))
          )))
 
 ;; Turns out this might not be useful.
diff --git a/lisp/cedet/srecode/map.el b/lisp/cedet/srecode/map.el
index 784ebff..dc94920 100644
--- a/lisp/cedet/srecode/map.el
+++ b/lisp/cedet/srecode/map.el
@@ -327,7 +327,7 @@ if that file is NEW, otherwise assume the mode has not 
changed."
     ;; 4) - Find new files and add them to the map.
     (dolist (dir srecode-map-load-path)
       (when (file-exists-p dir)
-       (dolist (f (directory-files dir t "\\.srt$"))
+       (dolist (f (directory-files dir t "\\.srt\\'"))
          (when (and (not (backup-file-name-p f))
                     (not (auto-save-file-name-p f))
                     (file-readable-p f))
diff --git a/lisp/dired.el b/lisp/dired.el
index 689ad1f..f2d478e 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3171,7 +3171,7 @@ Any other value means to ask for each directory."
   :group 'dired)
 
 ;; Match anything but `.' and `..'.
-(defvar dired-re-no-dot "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
+(defvar dired-re-no-dot (rx (or (not ".") "...")))
 
 ;; Delete file, possibly delete a directory and all its files.
 ;; This function is useful outside of dired.  One could change its name
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el
index 785e350..dc7461d 100644
--- a/lisp/emacs-lisp/autoload.el
+++ b/lisp/emacs-lisp/autoload.el
@@ -1047,7 +1047,7 @@ write its autoloads into the specified file instead."
                        ;; what is the suffix for the underlying OS.
                       (unless (string-match "\\.\\(elc\\|so\\|dll\\)" suf)
                          (push suf tmp)))
-                     (concat "^[^=.].*" (regexp-opt tmp t) "\\'")))
+                     (concat "\\`[^=.].*" (regexp-opt tmp t) "\\'")))
         (files (apply #'nconc
                       (mapcar (lambda (dir)
                                 (directory-files (expand-file-name dir)
diff --git a/lisp/emacs-lisp/shadow.el b/lisp/emacs-lisp/shadow.el
index f0a4870..4ff129e 100644
--- a/lisp/emacs-lisp/shadow.el
+++ b/lisp/emacs-lisp/shadow.el
@@ -99,7 +99,8 @@ See the documentation for `list-load-path-shadows' for 
further information."
        (setq true-names (append true-names (list dir)))
        (setq dir (directory-file-name (or pp ".")))
        (setq curr-files (if (file-accessible-directory-p dir)
-                            (directory-files dir nil ".\\.elc?\\(\\.gz\\)?$" 
t)))
+                            (directory-files dir nil
+                                              "\\.elc?\\(?:\\.gz\\)?\\'" t)))
        (and curr-files
             (not noninteractive)
             (message "Checking %d files in %s..." (length curr-files) dir))
diff --git a/lisp/files.el b/lisp/files.el
index 01da2a9..3e4ad7c 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2671,7 +2671,7 @@ since only a single case-insensitive search through the 
alist is made."
      ("\\.pas\\'" . pascal-mode)
      ("\\.\\(dpr\\|DPR\\)\\'" . delphi-mode)
      ("\\.ad[abs]\\'" . ada-mode)
-     ("\\.ad[bs].dg\\'" . ada-mode)
+     ("\\.ad[bs]\\.dg\\'" . ada-mode)
      ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode)
      ("Imakefile\\'" . makefile-imake-mode)
      ("Makeppfile\\(?:\\.mk\\)?\\'" . makefile-makepp-mode) ; Put this before 
.mk
@@ -2822,7 +2822,7 @@ 
ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|CBR\\|7Z\\)\\'" . archive-mo
      ("\\.properties\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-javaprop-mode)
      ("\\.toml\\'" . conf-toml-mode)
      ("\\.desktop\\'" . conf-desktop-mode)
-     ("/\\.redshift.conf\\'" . conf-windows-mode)
+     ("/\\.redshift\\.conf\\'" . conf-windows-mode)
      
("\\`/etc/\\(?:DIR_COLORS\\|ethers\\|.?fstab\\|.*hosts\\|lesskey\\|login\\.?de\\(?:fs\\|vperm\\)\\|magic\\|mtab\\|pam\\.d/.*\\|permissions\\(?:\\.d/.+\\)?\\|protocols\\|rpc\\|services\\)\\'"
 . conf-space-mode)
      
("\\`/etc/\\(?:acpid?/.+\\|aliases\\(?:\\.d/.+\\)?\\|default/.+\\|group-?\\|hosts\\..+\\|inittab\\|ksysguarddrc\\|opera6rc\\|passwd-?\\|shadow-?\\|sysconfig/.+\\)\\'"
 . conf-mode)
      ;; ChangeLog.old etc.  Other change-log-mode entries are above;
@@ -5754,7 +5754,7 @@ If called interactively, then PARENTS is non-nil."
   (write-region "" nil filename nil 0))
 
 (defconst directory-files-no-dot-files-regexp
-  "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"
+  "[^.]\\|\\.\\.\\."
   "Regexp matching any file name except \".\" and \"..\".")
 
 (defun files--force (no-such fn &rest args)
diff --git a/lisp/finder.el b/lisp/finder.el
index 96359b0..71f8ac7 100644
--- a/lisp/finder.el
+++ b/lisp/finder.el
@@ -188,7 +188,7 @@ from; the default is `load-path'."
   ;; Allow compressed files also.
   (setq package--builtins nil)
   (setq finder-keywords-hash (make-hash-table :test 'eq))
-  (let* ((el-file-regexp "^\\([^=].*\\)\\.el\\(\\.\\(gz\\|Z\\)\\)?$")
+  (let* ((el-file-regexp "\\`\\([^=].*\\)\\.el\\(\\.\\(gz\\|Z\\)\\)?\\'")
          (file-count 0)
          (files (cl-loop for d in (or dirs load-path)
                          when (file-exists-p (directory-file-name d))
diff --git a/lisp/generic-x.el b/lisp/generic-x.el
index d49193c..cd24f49 100644
--- a/lisp/generic-x.el
+++ b/lisp/generic-x.el
@@ -1430,7 +1430,7 @@ like an INI file.  You can add this hook to 
`find-file-hook'."
     "nowait"
     "internal")
   '(("^\\([-A-Za-z0-9_]+\\)" 1 font-lock-type-face))
-  '("/etc/inetd.conf\\'")
+  '("/etc/inetd\\.conf\\'")
   (list
    (function
     (lambda ()
@@ -1630,7 +1630,7 @@ like an INI file.  You can add this hook to 
`find-file-hook'."
      (2 font-lock-variable-name-face)
      (3 font-lock-constant-face)))
   ;; List of additional automode-alist expressions
-  '("/etc/named.boot\\'")
+  '("/etc/named\\.boot\\'")
   ;; List of set up functions to call
   nil))
 
@@ -1667,7 +1667,7 @@ like an INI file.  You can add this hook to 
`find-file-hook'."
   ;; List of additional font-lock-expressions
   nil
   ;; List of additional auto-mode-alist expressions
-  '("/etc/resolv[e]?.conf\\'")
+  '("/etc/resolve?\\.conf\\'")
   ;; List of set up functions to call
   nil))
 
@@ -1803,7 +1803,7 @@ like an INI file.  You can add this hook to 
`find-file-hook'."
   ;; List of additional font-lock-expressions
   nil
   ;; List of additional automode-alist expressions
-  '("/etc/modules.conf" "/etc/conf.modules")
+  '("/etc/modules\\.conf" "/etc/conf\\.modules")
   ;; List of set up functions to call
   nil))
 
diff --git a/lisp/gnus/gnus-agent.el b/lisp/gnus/gnus-agent.el
index 9f22b7df..cf705ae 100644
--- a/lisp/gnus/gnus-agent.el
+++ b/lisp/gnus/gnus-agent.el
@@ -2074,7 +2074,7 @@ doesn't exist, to valid the overview buffer."
                  (file-attributes (directory-files-and-attributes
                                    (gnus-agent-article-name
                                     "" gnus-agent-read-agentview)
-                                   nil "^[0-9]+$" t)))
+                                   nil "\\`[0-9]+\\'" t)))
             (while file-attributes
               (let ((fa (pop file-attributes)))
                 (unless (file-attribute-type (cdr fa))
@@ -3850,7 +3850,8 @@ If REREAD is not nil, downloaded articles are marked as 
unread."
                           (sort (delq nil (mapcar (lambda (name)
                                                     (and (not 
(file-directory-p (nnheader-concat dir name)))
                                                          (string-to-number 
name)))
-                                                  (directory-files dir nil 
"^[0-9]+$" t)))
+                                                  (directory-files
+                                                    dir nil "\\`[0-9]+\\'" t)))
                                 '>)
                         (progn (gnus-make-directory dir) nil)))
            nov-arts
@@ -4110,7 +4111,7 @@ agent has fetched."
                 (setq delta sum))
             (let ((sum (- (nth 2 entry)))
                   (info (directory-files-and-attributes
-                         path nil "^-?[0-9]+$" t))
+                         path nil "\\`-?[0-9]+\\'" t))
                   file)
               (while (setq file (pop info))
                 (cl-incf sum (float (or (file-attribute-size (cdr file)) 0))))
diff --git a/lisp/gnus/gnus-cache.el b/lisp/gnus/gnus-cache.el
index 8b9acfe..02a8ea7 100644
--- a/lisp/gnus/gnus-cache.el
+++ b/lisp/gnus/gnus-cache.el
@@ -501,7 +501,7 @@ Returns the list of articles removed."
     (when (file-exists-p dir)
       (setq articles
            (sort (mapcar (lambda (name) (string-to-number name))
-                         (directory-files dir nil "^[0-9]+$" t))
+                         (directory-files dir nil "\\`[0-9]+\\'" t))
                  '<))
       ;; Update the cache active file, just to synch more.
       (if articles
diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el
index 41b63e2..46b70ea 100644
--- a/lisp/gnus/gnus-score.el
+++ b/lisp/gnus/gnus-score.el
@@ -2981,7 +2981,7 @@ The list is determined from the variable 
`gnus-score-file-alist'."
       (if (file-directory-p (car files))
          (setq out (nconc (directory-files
                            (car files) t
-                           (concat (gnus-score-file-regexp) "$"))))
+                           (concat (gnus-score-file-regexp) "\\'"))))
        (push (car files) out))
       (setq files (cdr files)))
     (setq gnus-internal-global-score-files out)))
diff --git a/lisp/gnus/gnus-util.el b/lisp/gnus/gnus-util.el
index 23c62b4..3429d65 100644
--- a/lisp/gnus/gnus-util.el
+++ b/lisp/gnus/gnus-util.el
@@ -768,7 +768,7 @@ nil.  See also `gnus-bind-print-variables'."
 If there's no subdirectory, delete DIRECTORY as well."
   (when (file-directory-p directory)
     (let ((files (directory-files
-                 directory t "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
+                 directory t (rx (or (not ".") "..."))))
          file dir)
       (while files
        (setq file (pop files))
diff --git a/lisp/gnus/gnus-uu.el b/lisp/gnus/gnus-uu.el
index d40ba9c..5902f2b 100644
--- a/lisp/gnus/gnus-uu.el
+++ b/lisp/gnus/gnus-uu.el
@@ -1674,7 +1674,7 @@ Gnus might fail to display all of it.")
     did-unpack))
 
 (defun gnus-uu-dir-files (dir)
-  (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
+  (let ((dirs (directory-files dir t (rx (or (not ".") "..."))))
        files file)
     (while dirs
       (if (file-directory-p (setq file (car dirs)))
diff --git a/lisp/gnus/nndraft.el b/lisp/gnus/nndraft.el
index 3ee86a6..a1337e8 100644
--- a/lisp/gnus/nndraft.el
+++ b/lisp/gnus/nndraft.el
@@ -219,7 +219,7 @@ are generated if and only if they are also in 
`message-draft-headers'."
       (nnheader-re-read-dir pathname)
       (setq dir (mapcar (lambda (name) (string-to-number (substring name 1)))
                        (ignore-errors (directory-files
-                                       pathname nil "^#[0-9]+#$" t))))
+                                       pathname nil "\\`#[0-9]+#\\'" t))))
       (dolist (n dir)
        (unless (file-exists-p
                 (setq file (expand-file-name (int-to-string n) pathname)))
diff --git a/lisp/gnus/nnmh.el b/lisp/gnus/nnmh.el
index c075f29..8e7f056 100644
--- a/lisp/gnus/nnmh.el
+++ b/lisp/gnus/nnmh.el
@@ -172,7 +172,7 @@ as unread by Gnus.")
        (setq dir
              (sort
               (mapcar 'string-to-number
-                      (directory-files pathname nil "^[0-9]+$" t))
+                      (directory-files pathname nil "\\`[0-9]+\\'" t))
               '<))
        (cond
         (dir
@@ -360,7 +360,7 @@ as unread by Gnus.")
       (nnmh-possibly-change-directory group server)
       (let ((articles (mapcar 'string-to-number
                              (directory-files
-                              nnmh-current-directory nil "^[0-9]+$"))))
+                              nnmh-current-directory nil "\\`[0-9]+\\'"))))
        (when articles
          (setcar active (apply 'min articles))
          (setcdr active (apply 'max articles))))))
@@ -371,7 +371,7 @@ as unread by Gnus.")
   ;; Delete all articles in GROUP.
   (if (not force)
       ()                               ; Don't delete the articles.
-    (let ((articles (directory-files nnmh-current-directory t "^[0-9]+$")))
+    (let ((articles (directory-files nnmh-current-directory t "\\`[0-9]+\\'")))
       (while articles
        (when (file-writable-p (car articles))
          (nnheader-message 5 "Deleting article %s in %s..."
@@ -485,7 +485,7 @@ as unread by Gnus.")
       ;; Find the highest number in the group.
       (let ((files (sort
                    (mapcar 'string-to-number
-                           (directory-files dir nil "^[0-9]+$"))
+                           (directory-files dir nil "\\`[0-9]+\\'"))
                    '>)))
        (when files
          (setcdr active (car files)))))
@@ -509,7 +509,7 @@ as unread by Gnus.")
   (let* ((dir nnmh-current-directory)
         (files (sort (mapcar 'string-to-number
                              (directory-files nnmh-current-directory
-                                              nil "^[0-9]+$" t))
+                                              nil "\\`[0-9]+\\'" t))
                      '<))
         (nnmh-file (concat dir ".nnmh-articles"))
         new articles)
diff --git a/lisp/gnus/nnspool.el b/lisp/gnus/nnspool.el
index da13a56..33b68fa 100644
--- a/lisp/gnus/nnspool.el
+++ b/lisp/gnus/nnspool.el
@@ -260,7 +260,7 @@ there.")
            t)
        ;; Yes, completely empty spool directories *are* possible.
        ;; Fix by Sudish Joseph <address@hidden>
-       (when (setq dir (directory-files pathname nil "^[0-9]+$" t))
+       (when (setq dir (directory-files pathname nil "\\`[0-9]+\\'" t))
          (setq dir (sort (mapcar 'string-to-number dir) '<)))
        (if dir
            (nnheader-insert
diff --git a/lisp/gnus/spam-stat.el b/lisp/gnus/spam-stat.el
index 2e03608..3da45a2 100644
--- a/lisp/gnus/spam-stat.el
+++ b/lisp/gnus/spam-stat.el
@@ -557,7 +557,7 @@ check the variable `spam-stat-score-data'."
 
 (defun spam-stat-process-directory (dir func)
   "Process all the regular files in directory DIR using function FUNC."
-  (let* ((files (directory-files dir t "^[^.]"))
+  (let* ((files (directory-files dir t "\\`[^.]"))
         (max (/ (length files) 100.0))
         (count 0))
     (with-temp-buffer
@@ -601,7 +601,7 @@ If VERBOSE is non-nil display names of files detected as 
spam or
 non-spam in a temporary buffer.  If it is the symbol `ham',
 display non-spam files; otherwise display spam files."
   (interactive "DDirectory: ")
-  (let* ((files (directory-files dir t "^[^.]"))
+  (let* ((files (directory-files dir t "\\`[^.]"))
         display-files
         buffer-score
         (total (length files))
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 1be8e0a..c7d0112 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -623,7 +623,7 @@ FILE is the file where FUNCTION was probably defined."
   ;; of the *packages* in which the function is defined.
   (let* ((name (symbol-name symbol))
          (re (concat "\\_<" (regexp-quote name) "\\_>"))
-         (news (directory-files data-directory t "\\`NEWS.[1-9]"))
+         (news (directory-files data-directory t "\\`NEWS\\.[1-9]"))
          (place nil)
          (first nil))
     (with-temp-buffer
diff --git a/lisp/help.el b/lisp/help.el
index 45cbaad..0f1991e 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -361,7 +361,7 @@ With argument, display info only for the selected version."
                     (setq res (cons (match-string-no-properties 1) res)))))
               (cons "NEWS"
                     (directory-files data-directory nil
-                                     "^NEWS\\.[0-9][-0-9]*$" nil)))
+                                     "\\`NEWS\\.[0-9][-0-9]*\\'" nil)))
              (sort (delete-dups res) #'string>)))
           (current (car all-versions)))
       (setq version (completing-read
diff --git a/lisp/international/quail.el b/lisp/international/quail.el
index 193b1d7..3299cc5 100644
--- a/lisp/international/quail.el
+++ b/lisp/international/quail.el
@@ -3059,7 +3059,7 @@ of each directory."
     (while quail-dirs
       (setq dirname (car quail-dirs))
       (when dirname
-       (setq pkg-list (directory-files dirname 'full "\\.el$"))
+       (setq pkg-list (directory-files dirname 'full "\\.el\\'"))
        (while pkg-list
          (with-temp-buffer
            (insert-file-contents (car pkg-list))
diff --git a/lisp/international/titdic-cnv.el b/lisp/international/titdic-cnv.el
index 2a80d75..4f1bcf2 100644
--- a/lisp/international/titdic-cnv.el
+++ b/lisp/international/titdic-cnv.el
@@ -553,7 +553,7 @@ To get complete usage, invoke \"emacs -batch -f 
batch-titdic-convert -h\"."
        (if (file-directory-p filename)
            (progn
              (message "Converting all tit files in the directory %s" filename)
-             (setq files (directory-files filename t "\\.tit$")))
+             (setq files (directory-files filename t "\\.tit\\'")))
          (setq files (list filename)))
        (while files
          (setq file (expand-file-name (car files)))
diff --git a/lisp/mail/mspools.el b/lisp/mail/mspools.el
index 9c0c3fe..94b0886 100644
--- a/lisp/mail/mspools.el
+++ b/lisp/mail/mspools.el
@@ -223,7 +223,7 @@ your primary spool is.  If this fails, set it to something 
like
            ;; So I create a vm-spool-files entry for each of those mail drops
            (mapcar 'file-name-sans-extension
                    (directory-files mspools-folder-directory nil
-                                    (format "^[^.]+\\.%s" mspools-suffix)))
+                                    (format "\\`[^.]+\\.%s" mspools-suffix)))
            ))
    ))
 
@@ -357,7 +357,7 @@ nil."
     (if (null mspools-folder-directory)
        (error "Set `mspools-folder-directory' to where the spool files are"))
     (setq folders (directory-files mspools-folder-directory nil
-                                  (format "^[^.]+\\.%s$" mspools-suffix)))
+                                  (format "\\`[^.]+\\.%s\\'" mspools-suffix)))
     (setq folders (mapcar 'mspools-size-folder folders))
     (setq folders (delq nil folders))
     (setq mspools-files folders)
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index d798ffa..3feff80 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -474,7 +474,7 @@ the frame where you have the RMAIL buffer displayed."
   :type 'directory
   :group 'rmail-files)
 ;;;###autoload
-(defcustom rmail-secondary-file-regexp (purecopy "\\.xmail$")
+(defcustom rmail-secondary-file-regexp (purecopy "\\.xmail\\'")
   "Regexp for which files are secondary Rmail files."
   :type 'regexp
   :group 'rmail-files)
@@ -4354,7 +4354,8 @@ This has an effect only if a summary buffer exists."
            (font-lock-fontify-region (point-min) (point-max)))))))
 
 ;;; Speedbar support for RMAIL files.
-(defcustom rmail-speedbar-match-folder-regexp "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
+(defcustom rmail-speedbar-match-folder-regexp
+  "\\`[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?\\'"
   "Regexp matching Rmail folder names to be displayed in Speedbar.
 Enabling this permits Speedbar to display your folders for easy
 browsing, and moving of messages."
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el
index 1d45604..92ed98b 100644
--- a/lisp/net/ange-ftp.el
+++ b/lisp/net/ange-ftp.el
@@ -4170,8 +4170,7 @@ directory, so that Emacs will know its current contents."
                   (ange-ftp-delete-directory file recursive trash)
                 (delete-file file trash)))
             ;; We do not want to delete "." and "..".
-            (directory-files
-             dir 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
+            (directory-files dir 'full (rx (or (not ".") "...")))))
        (if parsed
            (let* ((host (nth 0 parsed))
                   (user (nth 1 parsed))
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 0ad65fb..4f3249d 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2458,7 +2458,7 @@ remote file names."
           (regexp-opt
            (mapcar
             #'file-name-sans-extension
-            (directory-files dir nil "^tramp.+\\.elc?$"))
+            (directory-files dir nil "\\`tramp.+\\.elc?\\'"))
            'paren))))
     (mapatoms
      (lambda (atom)
diff --git a/lisp/obsolete/gulp.el b/lisp/obsolete/gulp.el
index 6589ede..08ab388 100644
--- a/lisp/obsolete/gulp.el
+++ b/lisp/obsolete/gulp.el
@@ -94,7 +94,7 @@ is left in the `*gulp*' buffer at the end."
   (interactive "DRequest updates for Lisp directory: \nP")
   (with-current-buffer (get-buffer-create gulp-tmp-buffer)
     (let ((m-p-alist (gulp-create-m-p-alist
-                     (directory-files dir nil "^[^=].*\\.el$" t)
+                     (directory-files dir nil "\\`[^=].*\\.el\\'" t)
                      dir))
          ;; Temporarily inhibit undo in the *gulp* buffer.
          (buffer-undo-list t)
diff --git a/lisp/obsolete/vc-arch.el b/lisp/obsolete/vc-arch.el
index b186a5c..bcdefac 100644
--- a/lisp/obsolete/vc-arch.el
+++ b/lisp/obsolete/vc-arch.el
@@ -597,18 +597,20 @@ CALLBACK expects (ENTRIES &optional MORE-TO-COME); see
     (unless (file-writable-p rl-dir)
       (error "No writable revlib directory found"))
     (message "Revlib at %s" rl-dir)
-    (let* ((archives (directory-files rl-dir 'full "[^.]\\|..."))
+    (let* ((archives (directory-files rl-dir 'full (rx (or (not ".") "..."))))
            (categories
             (apply 'append
                    (mapcar (lambda (dir)
                              (when (file-directory-p dir)
-                               (directory-files dir 'full "[^.]\\|...")))
+                               (directory-files dir 'full
+                                                (rx (or (not ".") "...")))))
                            archives)))
            (branches
             (apply 'append
                    (mapcar (lambda (dir)
                              (when (file-directory-p dir)
-                               (directory-files dir 'full "[^.]\\|...")))
+                               (directory-files dir 'full
+                                                (rx (or (not ".") "...")))))
                            categories)))
            (versions
             (apply 'append
diff --git a/lisp/org/ob-core.el b/lisp/org/ob-core.el
index 651561a..7654c7e 100644
--- a/lisp/org/ob-core.el
+++ b/lisp/org/ob-core.el
@@ -3055,7 +3055,7 @@ of `org-babel-temporary-directory'."
                    (delete-file file)))
                ;; We do not want to delete "." and "..".
                (directory-files org-babel-temporary-directory 'full
-                                "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
+                                 (rx (or (not ".") "..."))))
          (delete-directory org-babel-temporary-directory))
       (error
        (message "Failed to remove temporary Org-babel directory %s"
diff --git a/lisp/progmodes/ebnf2ps.el b/lisp/progmodes/ebnf2ps.el
index d5820bb..640cb57 100644
--- a/lisp/progmodes/ebnf2ps.el
+++ b/lisp/progmodes/ebnf2ps.el
@@ -1898,7 +1898,7 @@ It's only used when `ebnf-syntax' is `iso-ebnf'."
   :group 'ebnf-syntactic)
 
 
-(defcustom ebnf-file-suffix-regexp "\\.[Bb][Nn][Ff]$"
+(defcustom ebnf-file-suffix-regexp "\\.[Bb][Nn][Ff]\\'"
   "Specify file name suffix that contains EBNF.
 
 See `ebnf-eps-directory' command."
@@ -2731,7 +2731,7 @@ Used in functions `ebnf-reset-style', `ebnf-push-style' 
and
       (ebnf-syntax                      . 'ebnf)
       (ebnf-iso-alternative-p           . nil)
       (ebnf-iso-normalize-p             . nil)
-      (ebnf-file-suffix-regexp          . "\\.[Bb][Nn][Ff]$")
+      (ebnf-file-suffix-regexp          . "\\.[Bb][Nn][Ff]\\'")
       (ebnf-eps-prefix                  . "ebnf--")
       (ebnf-eps-header-font             . '(11 Helvetica "Black" "White" bold))
       (ebnf-eps-header                  . nil)
diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el
index b42e6f7..bae2bb6 100644
--- a/lisp/progmodes/executable.el
+++ b/lisp/progmodes/executable.el
@@ -155,7 +155,7 @@ See `compilation-error-regexp-alist'.")
 If PROGRAM is non-nil, use that instead of \"find\"."
   ;;  Pick file to search from location we know
   (let* ((dir (file-truename data-directory))
-         (file (car (directory-files dir nil "^[^.]"))))
+         (file (car (directory-files dir nil "\\`[^.]"))))
     (with-temp-buffer
       (call-process (or program "find")
                     nil
diff --git a/lisp/startup.el b/lisp/startup.el
index 1f545c6..5af264e 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1373,10 +1373,10 @@ please check its value")
         ((not (eq system-type 'windows-nt))
          (concat "~" init-file-user "/.emacs"))
         ;; Else deal with the Windows situation.
-        ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
+        ((directory-files "~" nil "\\`\\.emacs\\(\\.elc?\\)?\\'")
          ;; Prefer .emacs on Windows.
          "~/.emacs")
-        ((directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
+        ((directory-files "~" nil "\\`_emacs\\(\\.elc?\\)?\\'")
          ;; Also support _emacs for compatibility, but warn about it.
          (push `(initialization
                  ,(format-message
diff --git a/lisp/textmodes/refer.el b/lisp/textmodes/refer.el
index 2865b42..8d8223a 100644
--- a/lisp/textmodes/refer.el
+++ b/lisp/textmodes/refer.el
@@ -377,7 +377,7 @@ found on the last `refer-find-entry' or 
`refer-find-next-entry'."
                    dir files)
                (while (setq dir (car dirs))
                  (setq files
-                       (append (directory-files dir t "\\.bib$")
+                       (append (directory-files dir t "\\.bib\\'")
                                files))
                  (setq dirs (cdr dirs)))
                files))
diff --git a/lisp/url/url-about.el b/lisp/url/url-about.el
index fd83ac3..dde47e9 100644
--- a/lisp/url/url-about.el
+++ b/lisp/url/url-about.el
@@ -37,7 +37,7 @@
                          (mapc (lambda (f)
                                  (if (string-match "url-\\(.*\\).el$" f)
                                      (push (match-string 1 f) schemes)))
-                               (directory-files d nil "^url-.*\\.el$")))
+                               (directory-files d nil "\\`url-.*\\.el\\'")))
                        load-path)
                  (put 'url-extension-protocols 'schemes schemes)
                  schemes)))))
diff --git a/lisp/vc/vc-rcs.el b/lisp/vc/vc-rcs.el
index 00796e5..273f37c 100644
--- a/lisp/vc/vc-rcs.el
+++ b/lisp/vc/vc-rcs.el
@@ -247,7 +247,7 @@ to the RCS command."
                 (setq subdir (expand-file-name "RCS"
                                                (file-name-directory file)))))
           (not (directory-files (file-name-directory file)
-                                nil ".*,v$" t))
+                                nil ",v\\'" t))
           (yes-or-no-p "Create RCS subdirectory? ")
           (make-directory subdir))
       (apply #'vc-do-command "*vc*" 0 "ci" file
@@ -312,8 +312,7 @@ whether to remove it."
       (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS")
           ;; check whether RCS dir is empty, i.e. it does not
           ;; contain any files except "." and ".."
-          (not (directory-files dir nil
-                                "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
+          (not (directory-files dir nil (rx (or (not ".") "..."))))
           (yes-or-no-p (format "Directory %s is empty; remove it? " dir))
           (delete-directory dir)))))
 
diff --git a/test/lisp/net/tramp-archive-tests.el 
b/test/lisp/net/tramp-archive-tests.el
index 3229d2b..95e41a3 100644
--- a/test/lisp/net/tramp-archive-tests.el
+++ b/test/lisp/net/tramp-archive-tests.el
@@ -669,7 +669,7 @@ This tests also `access-file', `file-readable-p' and 
`file-regular-p'."
          (setq attr (directory-files-and-attributes tmp-name 'full))
          (dolist (elt attr)
            (should (equal (file-attributes (car elt)) (cdr elt))))
-         (setq attr (directory-files-and-attributes tmp-name nil "^b"))
+         (setq attr (directory-files-and-attributes tmp-name nil "\\`b"))
          (should (equal (mapcar #'car attr) '("bar"))))
 
       ;; Cleanup.
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 47d5176..544bdb5 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -3331,7 +3331,7 @@ They might differ only in time attributes or directory 
size."
               (tramp--test-file-attributes-equal-p
                (file-attributes (car elt)) (cdr elt))))
 
-           (setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
+           (setq attr (directory-files-and-attributes tmp-name2 nil "\\`b"))
            (should (equal (mapcar #'car attr) '("bar" "boz"))))
 
        ;; Cleanup.



reply via email to

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