2

I'm a newbie to eshell and I want to find the list function(s) which "find ./" calls. For the ls command I can use

which ls

which conveniently tells me where eshell/ls is, and links to the underlying function. On the other hand

which find

returns

find is an alias for `cl-find` in `cl.el`

but as far as I can see, there is no cl-find in cl.el, and clicking the link only takes me to the top of the cl.el file. How can I find the code which is evaluated by the find command? Is there any kind of convenient, general way of seeing the functions which get called by an eshell command?

1

cl-seq.el contains cl-find. The cl.el library contains a dolist with a bunch of names and a defalias for the list -- one of the entries is find: (dolist (fun '(. . . find-if-not find-if find nsubstitute-if-not . . .)) (let ((new (if (consp fun) (prog1 (cdr fun) (setq fun (car fun))) (intern (format "cl-%s" fun))))) (defalias fun new)))

Here are two examples to illustrate whether the eshell library is working behind the scenes running elisp code when a user types either find or which at the command prompt in an *eshell* buffer. To experiment with these examples it is necessary to first ensure the eshell and cl libraries are loaded:

(progn
  (require 'eshell)
  (require 'cl))

The first example tests the find command and the code being evaluated will return nil because there is no built-in elisp function that is specially called by default when a user types find in an *eshell* buffer at the command prompt:

(eshell-invoke-directly
  '(eshell-commands
    (progn
      (run-hooks (quote eshell-pre-command-hook))
      (catch
        (quote top-level)
          (progn
            (eshell-trap-errors
              (eshell-named-command "find"))))
      (run-hooks (quote eshell-post-command-hook)))))

The second example tests the which command and the code being evaluated will return t because there is a built-in elisp function that is specially called by default when a user types which in an *eshell* buffer at the command prompt:

(eshell-invoke-directly
  '(eshell-commands
    (progn
      (run-hooks (quote eshell-pre-command-hook))
      (catch
        (quote top-level)
          (progn
            (eshell-trap-errors
              (eshell-named-command "which"))))
      (run-hooks (quote eshell-post-command-hook)))))

The following is a list of some built-in elisp functions that are called when a user types just the suffix (i.e., the word after the forward-slash of the name of the function) at the command prompt in an *eshell* buffer -- this list was obtained using describe-function and the tab completion buffer:

eshell/.
eshell/addpath
eshell/agrep
eshell/alias
eshell/basename
eshell/cat
eshell/cd
eshell/clear
eshell/clear-scrollback
eshell/cp
eshell/date
eshell/define
eshell/diff
eshell/dirname
eshell/dirs
eshell/du
eshell/echo
eshell/egrep
eshell/env
eshell/eshell-debug
eshell/exit
eshell/export
eshell/fgrep
eshell/glimpse
eshell/grep
eshell/history
eshell/info
eshell/jobs
eshell/kill
eshell/listify
eshell/ln
eshell/locate
eshell/ls
eshell/make
eshell/man
eshell/mkdir
eshell/mv
eshell/occur
eshell/popd
eshell/printnl
eshell/pushd
eshell/pwd
eshell/rm
eshell/rmdir
eshell/setq
eshell/source
eshell/time
eshell/umask
eshell/unset
eshell/wait
eshell/which
eshell/whoami

See also the variable eshell-complex-commands, whose default value is '("ls") -- the doc-string for said variable is as follows:

  "A list of commands names or functions, that determine complexity.
That is, if a command is defined by a function named eshell/NAME,
and NAME is part of this list, it is invoked as a complex command.
Complex commands are always correct, but run much slower.  If a
command works fine without being part of this list, then it doesn't
need to be.

If an entry is a function, it will be called with the name, and should
return non-nil if the command is complex."
  • Thanks @lawlist for a great answer - I've yet to fully explore the examples, but I'm still confused by one thing. When I attempt to stop inside cl-find, by using debug-on-entry and run "find ./" in eshell, the cl-find function does not appear to be called - yet the expected result of find is returned. How can I work out whats going on here? – Mark May 18 '16 at 9:32
  • When you call find ./ in an *eshell* buffer at the command prompt, cl-find is not being used. There is no special elisp function that is triggered, and this is why the first test returns nil in the above example. When you call which in an *eshell* buffer at the command prompt, you are not running the native which command -- instead, you are actually running an elisp function called eshell/which and that is what returns the information about cl-find because find is an alias and eshell/which thinks you want to inquire about an elisp function called find. – lawlist May 18 '16 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.