reddit / emacs

Redefining eshell built-in causes the external to become default

MitchellMarquez42 · 2022-11-27 02:37
Hello wizards, I've got a weird one today. I'm trying to write a small package which re-defines `eshell/cat`. I'm doing this with (defun eshell/cat (&rest args) "doc string" (do-various-things-to args)) Before loading this file, `which cat` returns "eshell/cat is a byte-compiled Lisp function in 'em-unix.el'." But after loading the file, `which cat` returns "/usr/bin/cat". Now I can manually invoke my new function with `eshell/cat`, but it _should_ be callable as just `cat`. Everything I've seen online indicates that defining `eshell/<cmd>` exposes `<cmd>` as an eshell command, as does the built-in Info manual. This issue occurs whenever I start eshell _and then_ load the file. When I load the file first, eshell's init sequence clobbers it and restores the definition from `em-unix.el`. What is the correct way to do this? EDIT: I ended up just defining a function called `eshell/dat` and aliasing that to Cat. Will keep poking this problem and hopefully update again.
gopar · 2022-11-28 20:45
Do you have anything else in that file? Sounds right to me that it should work. One thing you can try is define that new cmd in eshell (open up eshell without loading file and paste the definition in the prompt) if it works as expected then something else might be going on in the file. Otherwise also look at some eshell vars about preferring external vs lisp define cmds (sorry can't remember what they are called and not with computer)