bug#81556: 32.0.50; [PATCH] Make speedbar user options for hiding directories or files

Protesilaos <[email protected]> Wed, 05 Aug 2026 18:14:21 +0300
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
Thank you for the feedback, Sean!

> Date: Wed,  5 Aug 2026 15:13:54 +0100

> [... 17 lines elided]

>> +*** The user option 'speedbar-file-unshown-regexp' can be set to 
>> 'nil'
>> +This means that all files will be displayed.
> 
> "can be set to nil" isn't the best wording because you can already set
> them to nil, it's just not advisable.

> [... 12 lines elided]

>> +If nil, then all directories are displayed."
> 
> Instead of just appending to the end of the docstring, rewrite the 
> whole
> thing.  For example the first line can be "How to match directories not
> to show in speedbar."
> 
>> @@ -2002,9 +2012,11 @@ (defun speedbar-file-lists (directory)
>>  	    (files nil))
>>  	(while dir
>>  	  (if (not
>> -	       (or (string-match speedbar-file-unshown-regexp (car dir))
>> +	       (or (and (stringp speedbar-file-unshown-regexp)
>> +                        (string-match speedbar-file-unshown-regexp 
>> (car dir)))
>>  		   (member (car dir) vc-directory-exclusion-list)
>> -		   (string-match speedbar-directory-unshown-regexp (car dir))))
>> +                   (and (stringp speedbar-directory-unshown-regexp)
>> +		        (string-match speedbar-directory-unshown-regexp (car 
>> dir)))))
>>  	      (if (file-directory-p (car dir))
>>  		  (setq dirs (cons (car dir) dirs))
>>  		(setq files (cons (car dir) files))))
> 
> This implies that a non-nil, non-string value of the option also means
> to match all files, but that's confusing.  So I suggest just testing
> that the variables are non-nil and if the user passes a non-string
> string-match will signal an error, which seems useful.

I attach a new patch.
0001-Make-speedbar-user-options-for-hiding-directories-or.patch (text/x-diff, 4.6 KB)
From 0f038587edef2c858e5e8c0c835bbf4360a21911 Mon Sep 17 00:00:00 2001
Message-ID: <0f038587edef2c858e5e8c0c835bbf4360a21911.1785942692.git.info@protesilaos.com>
From: Protesilaos <[email protected]>
Date: Wed, 5 Aug 2026 18:11:22 +0300
Subject: [PATCH] Make speedbar user options for hiding directories or files
 show all with nil value

* etc/NEWS: Announce the changes.
* lisp/speedbar.el (speedbar-directory-unshown-regexp)
(speedbar-file-unshown-regexp): Add choice for nil to not hide
anything.
(speedbar-file-lists): Check that the user options
'speedbar-directory-unshown-regexp' and
'speedbar-file-unshown-regexp' are strings before using them.
Raise a user-error if their non-nil value is not a string.
---
 etc/NEWS         |  8 ++++++++
 lisp/speedbar.el | 49 +++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 46 insertions(+), 11 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 3aba7e9db15..38ec8d994ab 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -248,6 +248,14 @@ Markdown files fall back to 'text-mode'.
 
 To install the grammars, use 'M-x markdown-ts-mode-install-parsers'.
 
+** Speedbar
+
+---
+*** A nil value for 'speedbar-directory-unshown-regexp' means "show all"
+
+---
+*** A nil value for 'speedbar-file-unshown-regexp' means "show all"
+
 
 * Incompatible Lisp Changes in Emacs 32.1
 
diff --git a/lisp/speedbar.el b/lisp/speedbar.el
index 08af40a0aca..92d96ef81b0 100644
--- a/lisp/speedbar.el
+++ b/lisp/speedbar.el
@@ -661,12 +661,22 @@ (defcustom speedbar-ignored-directory-expressions
 	       (speedbar-extension-list-to-regex val))))
 
 (defcustom speedbar-directory-unshown-regexp "^\\(\\..*\\)\\'"
-  "Regular expression matching directories not to show in speedbar.
-They should include commonly existing directories which are not
-useful.  It is no longer necessary to include version-control
-directories here; see `vc-directory-exclusion-list'."
+  "Hide matching directories.
+The value can either be nil or a regular expression:
+
+- The nil value means to not hide any directory.
+
+- The regular expression means to hide the matching directories.  Note
+  that it is no longer necessary to include version-control directories
+  here; see `vc-directory-exclusion-list'.
+
+The default value is a regular expression.  It hides all directories
+whose name starts with a dot."
   :group 'speedbar
-  :type 'regexp)
+  :type '(choice
+          (regexp :tag "Hide matches of regular expression")
+          (const :tag "Do not hide anything" nil))
+  :version "32.1")
 
 (defcustom speedbar-file-unshown-regexp
   (let ((nstr "") (noext completion-ignored-extensions))
@@ -676,10 +686,20 @@ (defcustom speedbar-file-unshown-regexp
 	    noext (cdr noext)))
     ;;               backup      refdir      lockfile
     (concat nstr "\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
-  "Regexp matching files we don't want displayed in a speedbar buffer.
-It is generated from the variable `completion-ignored-extensions'."
+  "Hide matching files.
+The value can either be nil or a regular expression:
+
+- The nil value means to not hide any file.
+
+- The regular expression means to hide the matching files.
+
+The default value is a regular expression.  It is generated from the
+variable `completion-ignored-extensions'."
   :group 'speedbar
-  :type 'regexp)
+  :type '(choice
+          (regexp :tag "Hide matches of regular expression")
+          (const :tag "Do not hide anything" nil))
+  :version "32.1")
 
 (defvar speedbar-file-regexp nil
   "Regular expression matching files we know how to expand.
@@ -1999,12 +2019,19 @@ (defun speedbar-file-lists (directory)
       (let ((default-directory directory)
 	    (dir (directory-files directory nil))
 	    (dirs nil)
-	    (files nil))
+	    (files nil)
+            (hide-p (lambda (name user-option)
+                      (let ((value (symbol-value user-option)))
+                        (or (and value
+                                 (not (stringp value))
+                                 (user-error "The `%s' must either be a string or nil" user-option))
+                            (and value
+                                 (string-match value name)))))))
 	(while dir
 	  (if (not
-	       (or (string-match speedbar-file-unshown-regexp (car dir))
+	       (or (funcall hide-p (car dir) 'speedbar-file-unshown-regexp)
 		   (member (car dir) vc-directory-exclusion-list)
-		   (string-match speedbar-directory-unshown-regexp (car dir))))
+                   (funcall hide-p (car dir) 'speedbar-directory-unshown-regexp)))
 	      (if (file-directory-p (car dir))
 		  (setq dirs (cons (car dir) dirs))
 		(setq files (cons (car dir) files))))
-- 
2.47.3