]> git.eshelyaron.com Git - emacs.git/commitdiff
Use 'regexp-opt' in 'dired-omit-regexp'
authorSpencer Baugh <sbaugh@catern.com>
Sat, 16 Mar 2024 17:11:24 +0000 (17:11 +0000)
committerEshel Yaron <me@eshelyaron.com>
Sun, 24 Mar 2024 14:21:19 +0000 (15:21 +0100)
In my benchmarking, for large dired buffers, using 'regexp-opt'
provides around a 3x speedup in omitting.

'regexp-opt' takes around 5 milliseconds, so to avoid slowing
down omitting in small dired buffers we cache the return value.

Since omitting is now 3x faster, increase 'dired-omit-size-limit'
by 3x.  Also, document 'dired-omit-size-limit' better.

* doc/misc/dired-x.texi (Omitting Variables): Document
'dired-omit-size-limit'.
* etc/NEWS: Announce increase of 'dired-omit-size-limit'.
* lisp/dired-x.el (dired-omit--extension-regexp-cache): Add.
(dired-omit-regexp): Use 'regexp-opt'.  (Bug#69775)
(dired-omit-size-limit): Increase and improve docs.

(cherry picked from commit abc2d39e0102f8bb554d89da3c0ffe57188220ff)

doc/misc/dired-x.texi
etc/NEWS
lisp/dired-x.el

index 4cad016a0f67de7a7003e6af34b9781727bb32fd..726b6653d0d42f919f00bb88f1990e4414b75d12 100644 (file)
@@ -346,6 +346,15 @@ only match against the non-directory part of the file name.  Set it to
 match the file name relative to the buffer's top-level directory.
 @end defvar
 
+@defvar dired-omit-size-limit
+If non-@code{nil}, @code{dired-omit-mode} will be effectively disabled
+in directories whose listing has size (in bytes) larger than the value
+of this option.  Since omitting can be slow for very large directories,
+this avoids having to wait before seeing the directory.  This variable
+is ignored when @code{dired-omit-mode} is called interactively, such as
+by @code{C-x M-o}, so you can still enable omitting in the directory
+after the initial display.
+
 @cindex omitting additional files
 @defvar dired-omit-marker-char
 Temporary marker used by Dired to implement omitting.  Should never be used
index db20afce856e8b341528d5589f5b1598a249baf5..78ef5eca33c69d82589c794ffe6432842cdce2b3 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -708,6 +708,12 @@ marked or clicked on files according to the OS conventions.  For
 example, on systems supporting XDG, this runs 'xdg-open' on the
 files.
 
+*** The default value of 'dired-omit-size-limit' was increased.
+After performance improvements to omitting in large directories, the new
+default value is 300k, up from 100k.  This means 'dired-omit-mode' will
+omit files in directories whose directory listing is up to 300 kilobytes
+in size.
+
 +++
 *** 'dired-listing-switches' handles connection-local values if exist.
 This allows to customize different switches for different remote machines.
index 62fdd916e69fabf53a806481035ff7808361d6b0..753d3054d2f55c1ab66c2dc4af83ba9619433859 100644 (file)
@@ -77,12 +77,17 @@ files not writable by you are visited read-only."
                 (other :tag "non-writable only" if-file-read-only))
   :group 'dired-x)
 
-(defcustom dired-omit-size-limit 100000
-  "Maximum size for the \"omitting\" feature.
+(defcustom dired-omit-size-limit 300000
+  "Maximum buffer size for `dired-omit-mode'.
+
+Omitting will be disabled if the directory listing exceeds this size in
+bytes.  This variable is ignored when `dired-omit-mode' is called
+interactively.
+
 If nil, there is no maximum size."
   :type '(choice (const :tag "no maximum" nil) integer)
   :group 'dired-x
-  :version "29.1")
+  :version "30.1")
 
 (defcustom dired-omit-case-fold 'filesystem
   "Determine whether \"omitting\" patterns are case-sensitive.
@@ -506,14 +511,23 @@ status message."
                                       (re-search-forward dired-re-mark nil t))))
         count)))
 
+(defvar dired-omit--extension-regexp-cache
+  nil
+  "A cache of `regexp-opt' applied to `dired-omit-extensions'.
+
+This is a cons whose car is a list of strings and whose cdr is a
+regexp produced by `regexp-opt'.")
+
 (defun dired-omit-regexp ()
+  (unless (equal dired-omit-extensions (car dired-omit--extension-regexp-cache))
+    (setq dired-omit--extension-regexp-cache
+          (cons dired-omit-extensions (regexp-opt dired-omit-extensions))))
   (concat (if dired-omit-files (concat "\\(" dired-omit-files "\\)") "")
           (if (and dired-omit-files dired-omit-extensions) "\\|" "")
           (if dired-omit-extensions
               (concat ".";; a non-extension part should exist
-                      "\\("
-                      (mapconcat 'regexp-quote dired-omit-extensions "\\|")
-                      "\\)$")
+                      (cdr dired-omit--extension-regexp-cache)
+                      "$")
             "")))
 
 ;; Returns t if any work was done, nil otherwise.