I like to keep my configuration as self-contained as possible, and I'm wondering whether there's a way to manage eshell
aliases in my .emacs
file. Is it possible to set up aliases with a function call kept in my .emacs
rather than a separate file in .emacs.d/eshell/aliases
?
The problem I am ultimately trying to solve is to get ff
when entered in command position in eshell
to reliably behave identically to find-file
. I am assuming that the easiest, most direct way to do this is an eshell alias.
The alias below, with single quotes, exactly as written, does the trick and behaves like find-file
does. I'm just trying to manage my aliases in the same place as the rest of my customization.
alias ff 'find-file $1'
Here are some attempted solutions to the problem that don't work and the steps to reproduce. The fact that they don't Just Work suggests to me that some work is needed to "wire up" a function so that it's usable from eshell
.
Non-Solution 1, eshell/ff
function
$ emacs -q -no-site-file
- within emacs,
C-x b *scratch* C-m
- write wrapper function in scratch buffer.
(defun eshell/ff (&rest args)
(apply #'find-file args))
C-x h M-x eval-region C-m
thenC-g
to deselectC-h f
eshell/ff
to verify that the function exists.M-x eshell C-m
- within
eshell
, typefind-file /etc/hosts
and visit the buffer. Then go back to eshell - within
eshell
, typeff /etc/hosts
. The error message below shows us thateshell
found our definition, but is somehow treating it differently thanfind-file
.
~ $ ff /etc/hosts
Wrong number of arguments: (1 . 2), 0
Non-Solution 2 (defalias 'ff 'find-file)
$ emacs -q -no-site-file
- within emacs,
C-x b *scratch* C-m
- write wrapper function in scratch buffer.
(defalias 'ff 'find-file)
C-x h M-x eval-region C-m
thenC-g
to deselectC-h f
eshell/ff
to verify that the function exists.M-x eshell C-m
- within
eshell
, typefind-file /etc/hosts
as before to verify thatfind-file
still works - within
eshell
, typeff /etc/hosts
. The error message is the same as inNon-Solution 1
.
ff
by itself instead offf /etc/hosts
because now I can't reproduce it either. :/