reddit / emacs

Is there a full list of mode hooks for "interactive I/O" buffers and "non-I/O" buffers?

brightlystar · 2022-08-14 12:51
I am most sure that I am not using correct terms while asking this question because I don't even know what the correct terms are. Maybe you can help as you read my question. I have encountered so many hooks in Emacs for different types buffers. Like ielm-mode-hook, term-mode-hook, text-mode-hook, prog-mode-hook. Sure there must be many more. While disabling or enabling some features using these hooks I am never sure if I have enabled or disabled it on all the hooks. Like I want to add line numbers to any "text non-I/O" buffers. By this mean only buffers where I write text or code but do not run REPL or any interactive tools. Are text-mode-hook and prog-mode-hook enough? Am I missing some other hooks? What if I want to add some function to "interactive I/O" buffers like REPLs, terminals, or other interactive tools? Like if I have line numbers enabled by default but I want to disable them in interactive buffers like this, is it enough to hook that function to term-mode-hook and ielm-mode-hook? Am I missing any other hooks? Is there a full list of hooks somewhere? At least the built-in ones? Is there some categorizing of those hooks like these ones are just for writing text and these ones are for interactive buffers?
ieure · 2022-08-14 17:32
You can get a list of all hooks and their documentation with `C-h d hook$ RET`. See also the [Help section of the manual](https://www.gnu.org/software/emacs/manual/html_node/emacs/Help.html), which covers this and the many other tools for inspecting a running Emacs session. While well-behaved modes for programming languages should all respect `prog-mode-hook`, I don't think there are common hooks like that for other classes of modes (though I could be wrong). Most modes based on interacting with line-based programs derive from `comint-mode`, so `comint-mode-hook` can be used for those, but others don't — things like ERC, SLIME REPLs, etc. Generally, how many hooks you need to use doesn't matter. Put the code to configure your modes into functions (ex: `my/interactive-buffer-setup`), then add those functions to whatever hooks you need to have them applied to the modes you want.