From 7830899f39515bcb4938715ebf58d1ba855deb41 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 13 Sep 2013 10:56:03 -0400 Subject: [PATCH] * 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. --- lisp/ChangeLog | 8 ++++++++ lisp/ls-lisp.el | 23 +++++++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 93156233ee..649e3a3b01 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-09-13 Stefan Monnier + + * 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. + 2013-09-13 Eli Zaretskii * term.el (term-emulate-terminal): Decode the command string diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index 82a78545d6..9ffbd2ccf5 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) -- 2.20.1