summaryrefslogtreecommitdiff
path: root/lisp/ls-lisp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ls-lisp.el')
-rw-r--r--lisp/ls-lisp.el42
1 files changed, 41 insertions, 1 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index b368efbbc95..2f723ca8ac8 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -1,4 +1,4 @@
-;;; ls-lisp.el --- emulate insert-directory completely in Emacs Lisp
+;;; ls-lisp.el --- emulate insert-directory completely in Emacs Lisp -*- lexical-binding: t -*-
;; Copyright (C) 1992, 1994, 2000-2017 Free Software Foundation, Inc.
@@ -60,6 +60,8 @@
;;; Code:
+
+
(defgroup ls-lisp nil
"Emulate the ls program completely in Emacs Lisp."
:version "21.1"
@@ -477,6 +479,37 @@ not contain `d', so that a full listing is expected."
(message "%s: doesn't exist or is inaccessible" file)
(ding) (sit-for 2))))) ; to show user the message!
+
+(declare-function eshell-extended-glob "em-glob" (glob))
+(declare-function dired-read-dir-and-switches "dired" (str))
+(declare-function dired-goto-next-file "dired" ())
+
+(defun ls-lisp--dired (orig-fun dir-or-list &optional switches)
+ (interactive (dired-read-dir-and-switches ""))
+ (require 'em-glob)
+ (if (consp dir-or-list)
+ (funcall orig-fun dir-or-list switches)
+ (let ((dir-wildcard (insert-directory-wildcard-in-dir-p
+ (expand-file-name dir-or-list))))
+ (if (not dir-wildcard)
+ (funcall orig-fun dir-or-list switches)
+ (let* ((default-directory (car dir-wildcard))
+ (files (eshell-extended-glob (cdr dir-wildcard)))
+ (dir (car dir-wildcard)))
+ (if files
+ (let ((inhibit-read-only t)
+ (buf
+ (apply orig-fun (nconc (list dir) files) (and switches (list switches)))))
+ (with-current-buffer buf
+ (save-excursion
+ (goto-char (point-min))
+ (dired-goto-next-file)
+ (forward-line 0)
+ (insert " wildcard " (cdr dir-wildcard) "\n"))))
+ (user-error "No files matching regexp")))))))
+
+(advice-add 'dired :around #'ls-lisp--dired)
+
(defun ls-lisp-sanitize (file-alist)
"Sanitize the elements in FILE-ALIST.
Fixes any elements in the alist for directory entries whose file
@@ -866,6 +899,13 @@ All ls time options, namely c, t and u, are handled."
file-size)
(format " %6s" (file-size-human-readable file-size))))
+(defun ls-lisp-unload-function ()
+ "Unload ls-lisp library."
+ (advice-remove 'insert-directory #'ls-lisp--insert-directory)
+ (advice-remove 'dired #'ls-lisp--dired)
+ ;; Continue standard unloading.
+ nil)
+
(provide 'ls-lisp)
;;; ls-lisp.el ends here