all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] allow wildcards in file names of cons arg to `dired'
@ 2010-09-26 18:03 Drew Adams
  2010-09-27  0:24 ` Drew Adams
  0 siblings, 1 reply; 2+ messages in thread
From: Drew Adams @ 2010-09-26 18:03 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1451 bytes --]

You can pass a cons arg to `dired', to have it create a Dired buffer that shows
only the files in the cdr of that cons (and with buffer name the car of the
cons).  Very useful (and hardly documented).

But currently those file names must be literal names - no wildcards.  For
example, try this: (dired '("TTTT" "111.el" "b*.el")), assuming there is a file
111.el and some file(s) matching b*.el (but no file with name "b*.el", i.e. with
a literal `*' in the name).

An error is raised, because `dired' treats `b*.el' as a literal file name
instead of globbing it.  It would be nice to show a Dired buffer named "TTTT"
listing file 111.el and all of the files whose names match b*.el.

See also bug #7027.  It reports only that the error msg shown when a wildcard is
used this way is a bad msg: It should say "b*.el: doesn't exist or is
inaccessible" (just as it does for other non-existent files), but instead it
barfs: "(wrong-type-arg stringp nil)".

But why shouldn't we allow wildcards in the file names of the cons, and not just
in a directory name?  That can be very handy.

Attached are tiny patches for `dired.el' and `ls-lisp.el' that implement this
feature for MS Windows (`ls-lisp.el' defines `insert-directory' on Windows).  

To implement this fully on non-Windows platforms, some changes would no doubt
also be needed to the version of `insert-directory' in `files.el'.  I cannot do
that part, but I hope that someone else can and will.

[-- Attachment #2: dired-2010-09-26.patch --]
[-- Type: application/octet-stream, Size: 1655 bytes --]

diff -cw dired.el dired-patched-2010-09-26.el
*** dired.el	Sun Sep 26 09:57:16 2010
--- dired-patched-2010-09-26.el	Sun Sep 26 10:05:44 2010
***************
*** 935,943 ****
  		(directory-file-name (file-name-directory dir))))
  	  (error "Directory %s inaccessible or nonexistent" dir)
  	;; Else treat it as a wildcard spec
! 	;; unless we have an explicit list of files.
! 	(dired-insert-directory dir dired-actual-switches
! 				file-list (not file-list) t)))))
  
  (defun dired-align-file (beg end)
    "Align the fields of a file to the ones of surrounding lines.
--- 935,941 ----
  		(directory-file-name (file-name-directory dir))))
  	  (error "Directory %s inaccessible or nonexistent" dir)
  	;; Else treat it as a wildcard spec
! 	(dired-insert-directory dir dired-actual-switches file-list t t)))))
  
  (defun dired-align-file (beg end)
    "Align the fields of a file to the ones of surrounding lines.
***************
*** 1065,1071 ****
      (if file-list
  	(dolist (f file-list)
  	  (let ((beg (point)))
! 	    (insert-directory f switches nil nil)
  	    ;; Re-align fields, if necessary.
  	    (dired-align-file beg (point))))
        (insert-directory dir switches wildcard (not wildcard)))
--- 1063,1070 ----
      (if file-list
  	(dolist (f file-list)
  	  (let ((beg (point)))
!             ;; Compute wildcard arg for this file.
! 	    (insert-directory f switches (string-match "[[?*]" f) nil)
  	    ;; Re-align fields, if necessary.
  	    (dired-align-file beg (point))))
        (insert-directory dir switches wildcard (not wildcard)))

Diff finished.  Sun Sep 26 10:19:17 2010

[-- Attachment #3: ls-lisp-2010-09-26.patch --]
[-- Type: application/octet-stream, Size: 1045 bytes --]

diff -cw ls-lisp.el ls-lisp-patched-2010-09-26.el
*** ls-lisp.el	Sun Sep 26 09:58:38 2010
--- ls-lisp-patched-2010-09-26.el	Sun Sep 26 10:00:54 2010
***************
*** 294,300 ****
  regexp*.  FULL-DIRECTORY-P means file is a directory and SWITCHES does
  not contain `d', so that a full listing is expected."
    (if (or wildcard-regexp full-directory-p)
!       (let* ((dir (file-name-as-directory file))
  	     (default-directory dir)	; so that file-attributes works
  	     (file-alist
  	      (directory-files-and-attributes dir nil wildcard-regexp t
--- 294,300 ----
  regexp*.  FULL-DIRECTORY-P means file is a directory and SWITCHES does
  not contain `d', so that a full listing is expected."
    (if (or wildcard-regexp full-directory-p)
!       (let* ((dir (if file (file-name-as-directory file) default-directory))
  	     (default-directory dir)	; so that file-attributes works
  	     (file-alist
  	      (directory-files-and-attributes dir nil wildcard-regexp t

Diff finished.  Sun Sep 26 10:22:04 2010

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH] allow wildcards in file names of cons arg to `dired'
  2010-09-26 18:03 [PATCH] allow wildcards in file names of cons arg to `dired' Drew Adams
@ 2010-09-27  0:24 ` Drew Adams
  0 siblings, 0 replies; 2+ messages in thread
From: Drew Adams @ 2010-09-27  0:24 UTC (permalink / raw)
  To: emacs-devel

See also bug #7112.  To be robust, `ls-insert-directory' should
do nothing (no-op) for a FILE arg of "".




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-27  0:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-26 18:03 [PATCH] allow wildcards in file names of cons arg to `dired' Drew Adams
2010-09-27  0:24 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.