reddit / emacs

hook whenever a buffer with a given name is created

mmiri-ifuru 路 2022-05-07 12:59
Hi, General problem: I'm trying to create a hook which fires every time a buffer with a certain name is created. Is it a good idea to add it to `buffer-list-update-hook`? Specifically: The buffer is created by `imenu-list` (an awesome-sauce package for those who work with deep-nested org files), and I'd like to hide the modeline for this buffer. Adding a hook to `imenu-list-major-mode-hook` does not seem to do the trick. Any ideas how this could be done? Cheers!
arthurno1 路 2022-05-07 14:46
I don't think hook is what you want here. In your case it is probably better to [advice](https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html) the [get-buffer-create](https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffers.html) which is a primitive called when a buffer is created. It is a function implemented in C so you will need native compiler to advice it, if I am not wrong. I am not 100% here. You can also check [liist of standard hooks](https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Hooks.html), but the only thing I see is find-file hook. It will work though only if you call find-file function. However 馃榾; you probably have some minor/major mode for that buffer, or you are doing this in some function, so you can probably hook your code to hide mode-line elsewhere. Add a hook to major/minor mode that gets called and check the name of the buffer, and hide mode-line when match.
No-Command-791 路 2022-05-07 15:53
Are you using the `hide-mode-line` package? `hide-mode-line-mode` in `imenu-list-major-mode-hook` works for me.
Walheimat 路 2022-05-07 16:53
Looks like the package uses a `defcustom` for its modeline format. Maybe `(setq imenu-list-mode-line-format nil)` is all you want?
mmiri-ifuru 路 2022-05-07 22:28
Thank you for the advice(!) ! I have read about advising emacs functions, but always found it too intimidating to really start exploring the possibilities it affords.
mmiri-ifuru 路 2022-05-07 22:28
I am not using that package. I didn't know it existed!
mmiri-ifuru 路 2022-05-07 22:29
Thanks very much! That did, indeed do the trick.