diff options
Diffstat (limited to 'lisp/ls-lisp.el')
| -rw-r--r-- | lisp/ls-lisp.el | 42 |
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 @@ | |||
| 1 | ;;; ls-lisp.el --- emulate insert-directory completely in Emacs Lisp | 1 | ;;; ls-lisp.el --- emulate insert-directory completely in Emacs Lisp -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 1994, 2000-2017 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1992, 1994, 2000-2017 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -60,6 +60,8 @@ | |||
| 60 | 60 | ||
| 61 | ;;; Code: | 61 | ;;; Code: |
| 62 | 62 | ||
| 63 | |||
| 64 | |||
| 63 | (defgroup ls-lisp nil | 65 | (defgroup ls-lisp nil |
| 64 | "Emulate the ls program completely in Emacs Lisp." | 66 | "Emulate the ls program completely in Emacs Lisp." |
| 65 | :version "21.1" | 67 | :version "21.1" |
| @@ -477,6 +479,37 @@ not contain `d', so that a full listing is expected." | |||
| 477 | (message "%s: doesn't exist or is inaccessible" file) | 479 | (message "%s: doesn't exist or is inaccessible" file) |
| 478 | (ding) (sit-for 2))))) ; to show user the message! | 480 | (ding) (sit-for 2))))) ; to show user the message! |
| 479 | 481 | ||
| 482 | |||
| 483 | (declare-function eshell-extended-glob "em-glob" (glob)) | ||
| 484 | (declare-function dired-read-dir-and-switches "dired" (str)) | ||
| 485 | (declare-function dired-goto-next-file "dired" ()) | ||
| 486 | |||
| 487 | (defun ls-lisp--dired (orig-fun dir-or-list &optional switches) | ||
| 488 | (interactive (dired-read-dir-and-switches "")) | ||
| 489 | (require 'em-glob) | ||
| 490 | (if (consp dir-or-list) | ||
| 491 | (funcall orig-fun dir-or-list switches) | ||
| 492 | (let ((dir-wildcard (insert-directory-wildcard-in-dir-p | ||
| 493 | (expand-file-name dir-or-list)))) | ||
| 494 | (if (not dir-wildcard) | ||
| 495 | (funcall orig-fun dir-or-list switches) | ||
| 496 | (let* ((default-directory (car dir-wildcard)) | ||
| 497 | (files (eshell-extended-glob (cdr dir-wildcard))) | ||
| 498 | (dir (car dir-wildcard))) | ||
| 499 | (if files | ||
| 500 | (let ((inhibit-read-only t) | ||
| 501 | (buf | ||
| 502 | (apply orig-fun (nconc (list dir) files) (and switches (list switches))))) | ||
| 503 | (with-current-buffer buf | ||
| 504 | (save-excursion | ||
| 505 | (goto-char (point-min)) | ||
| 506 | (dired-goto-next-file) | ||
| 507 | (forward-line 0) | ||
| 508 | (insert " wildcard " (cdr dir-wildcard) "\n")))) | ||
| 509 | (user-error "No files matching regexp"))))))) | ||
| 510 | |||
| 511 | (advice-add 'dired :around #'ls-lisp--dired) | ||
| 512 | |||
| 480 | (defun ls-lisp-sanitize (file-alist) | 513 | (defun ls-lisp-sanitize (file-alist) |
| 481 | "Sanitize the elements in FILE-ALIST. | 514 | "Sanitize the elements in FILE-ALIST. |
| 482 | Fixes any elements in the alist for directory entries whose file | 515 | 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." | |||
| 866 | file-size) | 899 | file-size) |
| 867 | (format " %6s" (file-size-human-readable file-size)))) | 900 | (format " %6s" (file-size-human-readable file-size)))) |
| 868 | 901 | ||
| 902 | (defun ls-lisp-unload-function () | ||
| 903 | "Unload ls-lisp library." | ||
| 904 | (advice-remove 'insert-directory #'ls-lisp--insert-directory) | ||
| 905 | (advice-remove 'dired #'ls-lisp--dired) | ||
| 906 | ;; Continue standard unloading. | ||
| 907 | nil) | ||
| 908 | |||
| 869 | (provide 'ls-lisp) | 909 | (provide 'ls-lisp) |
| 870 | 910 | ||
| 871 | ;;; ls-lisp.el ends here | 911 | ;;; ls-lisp.el ends here |