Commit d5a7df8c authored by Mattias Engdegård's avatar Mattias Engdegård

Use directory-files-no-dot-files-regexp wherever possible

Suggested by Paul Eggert.

* lisp/files.el (directory-files-no-dot-files-regexp):
Clarify semantics and purpose.
* lisp/dired.el (dired-re-no-dot):
Define as obsolete alias of directory-files-no-dot-files-regexp.
(dired-delete-file):
* lisp/gnus/gnus-util.el (gnus-delete-directory):
* lisp/net/ange-ftp.el (ange-ftp-delete-directory):
* lisp/obsolete/vc-arch.el (vc-arch-trim-revlib):
* lisp/org/ob-core.el (org-babel-remove-temporary-directory):
* lisp/vc/vc-rcs.el (vc-rcs-unregister):
Use directory-files-no-dot-files-regexp.
parent 7839390f
Pipeline #5276 passed with stage
in 74 minutes and 54 seconds
......@@ -3235,8 +3235,8 @@ Any other value means to ask for each directory."
(const :tag "Confirm for each top directory only" top))
:group 'dired)
;; Match anything but `.' and `..'.
(defvar dired-re-no-dot (rx (or (not ".") "...")))
(define-obsolete-variable-alias 'dired-re-no-dot
'directory-files-no-dot-files-regexp "28.1")
;; Delete file, possibly delete a directory and all its files.
;; This function is useful outside of dired. One could change its name
......@@ -3258,7 +3258,9 @@ TRASH non-nil means to trash the file instead of deleting, provided
;; but more efficient
(if (not (eq t (car (file-attributes file))))
(delete-file file trash)
(let* ((empty-dir-p (null (directory-files file t dired-re-no-dot))))
(let* ((empty-dir-p (null (directory-files
file t
directory-files-no-dot-files-regexp))))
(if (and recursive (not empty-dir-p))
(unless (eq recursive 'always)
(let ((prompt
......
......@@ -5754,7 +5754,10 @@ If called interactively, then PARENTS is non-nil."
(defconst directory-files-no-dot-files-regexp
"[^.]\\|\\.\\.\\."
"Regexp matching any file name except \".\" and \"..\".")
"Regexp matching any file name except \".\" and \"..\".
More precisely, it matches parts of any nonempty string except those two.
It is useful as the PATTERN argument to `directory-files' and
`directory-files-and-attributes'.")
(defun files--force (no-such fn &rest args)
"Use NO-SUCH to affect behavior of function FN applied to list ARGS.
......
......@@ -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 (rx (or (not ".") "..."))))
directory t directory-files-no-dot-files-regexp))
file dir)
(while files
(setq file (pop files))
......
......@@ -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 (rx (or (not ".") "..."))))
(let ((dirs (directory-files dir t directory-files-no-dot-files-regexp))
files file)
(while dirs
(if (file-directory-p (setq file (car dirs)))
......
......@@ -4169,8 +4169,7 @@ directory, so that Emacs will know its current contents."
(if (file-directory-p file)
(ange-ftp-delete-directory file recursive trash)
(delete-file file trash)))
;; We do not want to delete "." and "..".
(directory-files dir 'full (rx (or (not ".") "...")))))
(directory-files dir 'full directory-files-no-dot-files-regexp)))
(if parsed
(let* ((host (nth 0 parsed))
(user (nth 1 parsed))
......
......@@ -597,20 +597,21 @@ 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 (rx (or (not ".") "..."))))
(let* ((archives (directory-files rl-dir 'full
directory-files-no-dot-files-regexp))
(categories
(apply 'append
(mapcar (lambda (dir)
(when (file-directory-p dir)
(directory-files dir 'full
(rx (or (not ".") "...")))))
(directory-files
dir 'full directory-files-no-dot-files-regexp)))
archives)))
(branches
(apply 'append
(mapcar (lambda (dir)
(when (file-directory-p dir)
(directory-files dir 'full
(rx (or (not ".") "...")))))
(directory-files
dir 'full directory-files-no-dot-files-regexp)))
categories)))
(versions
(apply 'append
......
......@@ -3053,9 +3053,8 @@ of `org-babel-temporary-directory'."
(if (eq t (car (file-attributes file)))
(delete-directory file)
(delete-file file)))
;; We do not want to delete "." and "..".
(directory-files org-babel-temporary-directory 'full
(rx (or (not ".") "..."))))
directory-files-no-dot-files-regexp))
(delete-directory org-babel-temporary-directory))
(error
(message "Failed to remove temporary Org-babel directory %s"
......
......@@ -312,7 +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 (rx (or (not ".") "..."))))
(not (directory-files dir nil directory-files-no-dot-files-regexp))
(yes-or-no-p (format "Directory %s is empty; remove it? " dir))
(delete-directory dir)))))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment