From 792edb24a8d7b617fcc8fbfa62f350fd01552d93 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Tue, 8 Nov 2016 17:42:24 +0000 Subject: [PATCH 2/4] Allow files to be matched case-sensitively in dired-x * lisp/dired-x.el (dired-mark-unmarked-files): Add an argument which controls case folding for matching the regex (Bug#18716). (dired-omit-case-fold): New variable. Defaults to `t' on case-sensitive systems, `nil' otherwise. (dired-mark-omitted, dired-omit-expunge): Use dired-omit-case-fold. * doc/misc/dired-x.texi, etc/NEWS: Document dired-omit-case-fold. --- doc/misc/dired-x.texi | 11 +++++++++++ etc/NEWS | 6 ++++++ lisp/dired-x.el | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/doc/misc/dired-x.texi b/doc/misc/dired-x.texi index db01896..4b5ca6d 100644 --- a/doc/misc/dired-x.texi +++ b/doc/misc/dired-x.texi @@ -369,6 +369,17 @@ Omitting Variables If non-@code{nil}, a list of extensions (strings) to omit from Dired listings. Its format is the same as that of @code{completion-ignored-extensions}. +@vindex dired-omit-case-fold +@item dired-omit-case-fold + +Default: @code{filesystem} + +By default, @code{dired-omit-mode} will match filenames and extensions +case-sensitively on Dired buffers visiting case-sensitive filesystems, +and case-insensitively on case-insensitive filesystems. Set to +@code{nil} to be always case-sensitive, and @code{t} to be always +case-sensitive. + @vindex dired-omit-localp @item dired-omit-localp diff --git a/etc/NEWS b/etc/NEWS index cbce027..33b8a42 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -83,6 +83,12 @@ of curved quotes for 'electric-quote-mode', allowing user to choose the types of quotes to be used. +++ +** The new user variable 'dired-omit-case-fold' allows the +case-sensitivity of dired-omit-mode to be configured. It defaults to +the same sensitivity as that of the filesystem for the corresponding +dired buffer. + ++++ ** Emacs now uses double buffering to reduce flicker when editing and resizing graphical Emacs frames on the X Window System. This support requires the DOUBLE-BUFFER extension, which major X servers have diff --git a/lisp/dired-x.el b/lisp/dired-x.el index 8313905..8f20955 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el @@ -133,6 +133,26 @@ dired-omit-size-limit :type '(choice (const :tag "no maximum" nil) integer) :group 'dired-x) +(defcustom dired-omit-case-fold 'filesystem + "Whether `dired-omit-mode' will use case-folding to match the +regexp of files to omit. When nil, always be case-sensitive; when +t, always be case-insensitive; the default value, 'filesystem, +causes case folding to be used on case-insensitive filesystems +only." + :type '(choice (const :tag "Always case-sensitive" nil) + (const :tag "Always case-insensitive" t) + (const :tag "According to filesystem" filesystem)) + :group 'dired-x + :version "26.1") + +(defun dired-omit-case-fold-p (dir) + "Return t if, according to `dired-omit-case-fold', + `dired-omit-mode' should use case folding to interpret its + regexp in directory DIR." + (if (eq dired-omit-case-fold 'filesystem) + (file-name-case-sensitive-p dir) + dired-omit-case-fold)) + ;; For backward compatibility (define-obsolete-variable-alias 'dired-omit-files-p 'dired-omit-mode "22.1") (define-minor-mode dired-omit-mode @@ -507,7 +527,8 @@ dired-mark-omitted "Mark files matching `dired-omit-files' and `dired-omit-extensions'." (interactive) (let ((dired-omit-mode nil)) (revert-buffer)) ;; Show omitted files - (dired-mark-unmarked-files (dired-omit-regexp) nil nil dired-omit-localp)) + (dired-mark-unmarked-files (dired-omit-regexp) nil nil dired-omit-localp + (dired-omit-case-fold-p dired-directory))) (defcustom dired-omit-extensions (append completion-ignored-extensions @@ -551,7 +572,8 @@ dired-omit-expunge (or (string= omit-re "") (let ((dired-marker-char dired-omit-marker-char)) (when dired-omit-verbose (message "Omitting...")) - (if (dired-mark-unmarked-files omit-re nil nil dired-omit-localp) + (if (dired-mark-unmarked-files omit-re nil nil dired-omit-localp + (dired-omit-case-fold-p dired-directory)) (progn (setq count (dired-do-kill-lines nil @@ -577,12 +599,14 @@ dired-omit-regexp ""))) ;; Returns t if any work was done, nil otherwise. -(defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp) +(defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp case-fold-p) "Mark unmarked files matching REGEXP, displaying MSG. REGEXP is matched against the entire file name. When called interactively, prompt for REGEXP. With prefix argument, unflag all those files. -Optional fourth argument LOCALP is as in `dired-get-filename'." +Optional fourth argument LOCALP is as in `dired-get-filename'. +Optional fifth argument CASE-FOLD-P specifies the value of +`case-fold-search' used for matching REGEXP." (interactive (list (read-regexp "Mark unmarked files matching regexp (default all): " @@ -594,7 +618,10 @@ dired-mark-unmarked-files ;; not already marked (looking-at-p " ") ;; uninteresting - (let ((fn (dired-get-filename localp t))) + (let ((fn (dired-get-filename localp t)) + ;; Match patterns case-insensitively on case-insensitive + ;; systems + (case-fold-search case-fold-p)) (and fn (string-match-p regexp fn)))) msg))) -- 2.7.4