3

For my function, that I have created, I'm looking for an Eshell mode hook.

I'm aware of the following hook:

(add-hook 'eshell-mode-hook 'my-function-for-eshell).

But what when I'm in a other buffer and want to switch back to the existing buffer with Eshell mode, I want to run that function? But I found all the hooks only will be triggered, when you create a new buffer with an Eshell mode.

To be clear, I run Evil normal mode when I do switch buffers with a keybinding in normal mode. The my-function-for-eshell brings me back in Evil insert mode, when I go back to Eshell.

1 Answer 1

4

There is no hook specifically for switching buffers, but you can use the buffer-list-update-hook. Switching buffers re-orders the buffer list and triggers this hook, so you could use that to run a command that checks the major-mode of the current buffer and takes some action if it is eshell.

3
  • It might add a large overhead because Eshell is a tiny part of my workflow, and I switch buffers a lot. But better than nothing, thanks for that!
    – ReneFroger
    Commented Jun 23, 2017 at 20:52
  • 1
    How about your own command to switch to your eshell buffer and run whatever additional commands you need?
    – glucas
    Commented Jun 24, 2017 at 0:53
  • Not possible, because when I split my window, my Eshell window lies adjacent. I have a default keybinding where I can navigate to all windows. When I want to Eshell window, I need another keybinding then in order to call my own command. But thanks for the suggestion, a good idea anyway.
    – ReneFroger
    Commented Jun 24, 2017 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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