Questions tagged [hooks]

Hooks are an important mechanism for customizing Emacs. A hook is a Lisp variable which holds a list of functions, to be called on some well-defined occasion.

Filter by
Sorted by
Tagged with
24
votes
3answers
6k views

Proper way to enable minor mode

I have foo-mode and would enable bar-minor-mode for it. So which way is more common and preferable? A (add-hook 'foo-mode-hook 'bar-minor-mode) B (add-hook 'foo-mode-hook (lambda () ...
4
votes
1answer
448 views

Is there a hook I can use to run my function when point moves?

I'd like to add some navigation context to the modeline. I can figure out where I am just fine and give the name of my function, but I don't know how to run this every time point moves. post-command-...
12
votes
1answer
3k views

Execute external script upon save when in a certain mode?

When I'm in org-mode, I want Emacs to execute a bash script I wrote whenever I hit C-x s to save. The script automatically syncs the file I am saving to my Raspberry Pi. It expects the file name as ...
2
votes
2answers
3k views

How to disable global Linum mode for certain mode?

in my init.el file I have the following: (global-linum-mode 1) (add-hook 'term-mode-hook (lambda () (linum-mode))) However, when I enter ansi-term-mode linum mode is still on. I have also tried (...
7
votes
1answer
604 views

Is there a universal 'after-theme-load' hook?

I would like to set several face variables for use with any theme in my personal init-file. Is there a hook I could use to insure it is theme independent?
6
votes
3answers
668 views

how to unbind a mode hook without restarting

I had set up a custom hook for a mode, but I now realize that I want to use the mode without my changes and without my hook. So, I want the mode to behave as if I never set the hook in the first place,...
2
votes
2answers
72 views

How to load personal prolog.el only if system's one is outdated?

I need to use a version of prolog.el not older than 1.25, so I defined the function maybe-reload-prolog-el: (defun maybe-reload-prolog-el () (when (version< prolog-mode-version "1.25") (add-...
23
votes
1answer
1k views

What is the difference between ' and #' in front of a symbol?

I'm a little new to Emacs. When looking at some of the configurations, I found there are two types command in "add-hook". (add-hook 'LaTeX-mode-hook #'LaTeX-math-mode) and (add-hook 'LaTeX-mode-...
14
votes
2answers
7k views

Run command when opening a file of a specific filetype

I'm trying to get a lisp script to run some commands for me when I open a file of a specific filetype. I know that I'm working in the correct init file because if I remove the theme from it, emacs has ...
9
votes
5answers
1k views

How to enter view-only mode when browsing Emacs source code from help?

When I browse Emacs help for functions via C-h f, I often want to peek into the Elisp/C implementation. I want to enter view-mode automatically when I access source code this way to avoid unnecessary ...
7
votes
2answers
721 views

Hook that indicates when the cursor has been moved by scrolling

Inspired by this question: Let Emacs move the cursor off-screen, I am considering writing a minor mode that will keep the cursor in a fixed position that is not affected by scrolling operations. I ...
5
votes
1answer
677 views

Run hook on new buffer

I am trying to create something like uniquely, which renames the buffer to the full path within the projectile project. I have the code working, however, I can't seem to figure out how to get it to ...
14
votes
3answers
2k views

Is there any way to run a hook function only once?

The context I'm using the after-make-frame-functions hook to load properly the themes in an emacs client/server configuration. Specifically this is the code snippet that I use to make that (based in ...
8
votes
2answers
1k views

Disable hl-line-mode only for eshell and ansi-term

I have global-hl-line-mode setup in my init file: (use-package hl-line :init (global-hl-line-mode 1)) Is it possible to disable it when I am in eshell and ansi-term? I tried adding a hook like ...
4
votes
1answer
292 views

Is there a way to detect change of monitor in Emacs / Elisp?

tl;dr I'm looking for way to detect when an Emacs frame has been moved from one monitor to another in a multi-monitor setup. I have code in my ~/.emacs which sets the default font size for all ...
3
votes
2answers
389 views

Emacs server init when called without file

Whenever I use emacsclient, I tend to use it without a file argument. This is because my emacs file finder is generally better than my shell file finder. Unfortunately, when emacsclient is not given ...
2
votes
1answer
102 views

How to automatically remove a hook provided by a minor mode after disabling that mode?

I want to write a minor which evaluates some code in the buffer after saving a file. I activate after-save-hook for this mode: (add-hook 'my-minor-mode-name-hook #'(lambda () (add-hook 'after-save-...
9
votes
1answer
2k views

What's the difference between after-init-hook and emacs-startup-hook

Seems there are several hooks about actions on Emacs initialization. However I'm not sure what their differences are, and a brief Googling yields little information. Is it like emacs-startup-hook is ...
3
votes
1answer
968 views

Run code right after compilation

As I understand, Emacs doesn't really support multi-threading. Because of this I've chosen to run some operation (it can take a while) with compile function. This is asynchronous and all in all it ...
8
votes
1answer
136 views

Quitting Emacs and re-enabeling touchpad

I have the below elisp code in my emacs config which disables my touchpad, so it won't annoy me when writing. ;; disable touchpad when on emacs (defun turn-off-mouse (&optional frame) (...
2
votes
1answer
426 views

how to disable minor mode (enabled using prog-mode-hook) for a particular major mode

I've enabled auto-complete-mode mode using prog-mode-hook like so: (add-hook 'prog-mode-hook 'auto-complete-mode), but I want auto-complete-mode to be disabled for python-mode. How can I achieve this ?...
2
votes
1answer
152 views

Buffer-local hook shadowing default value for subsequently loaded libraries

After having a problem with debugging a package I write, I finally tracked down the problem to the following: auto-revert-mode is making kill-buffer-hook buffer-local (which is fine by me). The ...
1
vote
1answer
69 views

Org mode refiling gobbles a newline and absorbs the next heading

I often have this problem in Org mode: I write an item with org-capture, refile it, and days later I see a result like this: *** TODO some task some notes** StackExchange I believe that the problem ...
0
votes
1answer
310 views

Run command after each type/insert in particular buffer

I'm implementing a (optional, de-activable) real-time syntax checker. Each time the user types/deletes anything, I want to run my spell-checking funtion : I tried (add-hook 'post-self-insert-hook '...
0
votes
1answer
211 views

How do I enable a mode, when another mode runs?

All I want to do is enable tern-mode, when I enter js-mode. I know that a hook called js-mode is run when I open a javascript file but for some reason tern-mode is not enabled. In my init.el file I ...