summaryrefslogtreecommitdiff
path: root/lisp/ls-lisp.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2013-09-13 10:56:03 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2013-09-13 10:56:03 -0400
commit7830899f39515bcb4938715ebf58d1ba855deb41 (patch)
treeb552f8044c183e01de30ba617dd8decca73292eb /lisp/ls-lisp.el
parent84387cd2595e0e99bb6976fe1e160156b5291611 (diff)
downloademacs-7830899f39515bcb4938715ebf58d1ba855deb41.tar.gz
* lisp/ls-lisp.el: Use advice-add.
(original-insert-directory): Remove. (ls-lisp--insert-directory): Rename from insert-directory; add `orig-fun' argument. (insert-directory): Advise.
Diffstat (limited to 'lisp/ls-lisp.el')
-rw-r--r--lisp/ls-lisp.el23
1 files changed, 7 insertions, 16 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 82a78545d62..9ffbd2ccf56 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -198,9 +198,6 @@ to fail to line up, e.g. if month names are not all of the same length."
:type 'boolean
:group 'ls-lisp)
-(defvar original-insert-directory nil
- "This holds the original function definition of `insert-directory'.")
-
(defvar ls-lisp-uid-d-fmt "-%d"
"Format to display integer UIDs.")
(defvar ls-lisp-uid-s-fmt "-%s"
@@ -213,15 +210,10 @@ to fail to line up, e.g. if month names are not all of the same length."
"Format to display integer file sizes.")
(defvar ls-lisp-filesize-f-fmt "%.0f"
"Format to display float file sizes.")
-
-;; Remember the original insert-directory function
-(or (featurep 'ls-lisp) ; FJW: unless this file is being reloaded!
- (setq original-insert-directory (symbol-function 'insert-directory)))
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun insert-directory (file switches &optional wildcard full-directory-p)
+(defun ls-lisp--insert-directory (orig-fun file switches &optional wildcard full-directory-p)
"Insert directory listing for FILE, formatted according to SWITCHES.
Leaves point after the inserted text.
SWITCHES may be a string of options, or a list of strings.
@@ -231,12 +223,10 @@ switches do not contain `d', so that a full listing is expected.
This version of the function comes from `ls-lisp.el'.
If the value of `ls-lisp-use-insert-directory-program' is non-nil then
-it works exactly like the version from `files.el' and runs a directory
-listing program whose name is in the variable
-`insert-directory-program'; if also WILDCARD is non-nil then it runs
-the shell specified by `shell-file-name'. If the value of
-`ls-lisp-use-insert-directory-program' is nil then it runs a Lisp
-emulation.
+this advice just delegates the work to ORIG-FUN (the normal `insert-directory'
+function from `files.el').
+But if the value of `ls-lisp-use-insert-directory-program' is nil
+then it runs a Lisp emulation.
The Lisp emulation does not run any external programs or shells. It
supports ordinary shell wildcards if `ls-lisp-support-shell-wildcards'
@@ -245,7 +235,7 @@ to match file names. It does not support all `ls' switches -- those
that work are: A a B C c F G g h i n R r S s t U u X. The l switch
is assumed to be always present and cannot be turned off."
(if ls-lisp-use-insert-directory-program
- (funcall original-insert-directory
+ (funcall orig-fun
file switches wildcard full-directory-p)
;; We need the directory in order to find the right handler.
(let ((handler (find-file-name-handler (expand-file-name file)
@@ -305,6 +295,7 @@ is assumed to be always present and cannot be turned off."
(replace-match "total used in directory")
(end-of-line)
(insert " available " available)))))))))
+(advice-add 'insert-directory :around #'ls-lisp--insert-directory)
(defun ls-lisp-insert-directory
(file switches time-index wildcard-regexp full-directory-p)