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
4
votes
1answer
454 views

Is there a hook that runs when exiting read-only-mode?

I'd like to set some things (e.g., cursor shape) when in read-only-mode. That part is easy enough with (add-hook 'read-only-mode-hook (lambda() (setq-local cursor-type 'box))) Then ...
0
votes
0answers
61 views

How can I know what command is running when I move the point or select something?

One example: I select something, then the minibuffer give me some response. For example, in markdown-preview-mode I select a paragraph then the minibuffer shows me the paragraph with <p> in each ...
1
vote
1answer
127 views

Making it so that cursor movement after command will deactivate region

I'm overriding double-mouse-1 to do additional stuff on top of its default behavior. To this end, I have a function that (1) does my additional stuff and then (2) calls another function, ora-mark-like-...
1
vote
1answer
56 views

How can I set the global value of a symbol created from a string?

I'm trying to make this little convenience function work: (defun my-make-hook (when procedure) (let ((hook-symbol (intern (concat (substring (symbol-name when) 1)...
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-...
0
votes
1answer
68 views

Adding to kill-buffer-hook results in “setq: Wrong type argument”

Subtract a buffer's (the file's) size from a variable before killing it. Emacs 26. (defvar cumulative-open-bytes '0 ) (defun buffer-settings-calc-bytes () (interactive) (let ((current-open-file-...
4
votes
1answer
135 views

How can I execute a function every time I insert certain characters in the buffer?

I write a lot of text in German and English and I'm getting tired of switching the dictionary of my spell-checker all the time. In true Emacs spirit, I decided to do something about this and dusted ...
6
votes
2answers
1k views

add-to-list vs add-hook?

What is the difference between add-to-list vs add-hook? For example I see in progmodes/make-mode.el: (add-hook 'completion-at-point-functions #'makefile-completions-at-point nil t) ...
2
votes
1answer
109 views

Does git-messenger support showing a commit using Magit?

In this issue in git-messenger's issue tracker it was suggested that it should optionally use magit-commit-mode to show commits in a separate buffer. And that issue was closed as resolved. But it ...
2
votes
0answers
196 views

Faces not set immediately after load-theme

I'm trying to set the faces of highlight-indent-guides automatically whenever a new theme is loaded by making small adjustments to the background color of the default face. I have everything working ...
0
votes
2answers
386 views

How replace auto-complete-mode with company-mode in all major mode using it?

How I can replace auto-complete-mode with company-mode in all major mode using it? i.e. make all modes which activating auto-complete-mode (e.g. c-mode or sh-mode etc), activate company-mode instead ...
3
votes
1answer
145 views

Calling a function when emacs process is killed (MS Windows)

I would like to call a function just before emacs exits. Normally the following can do job: (add-hook 'kill-emacs-hook 'my-function) Unfortunately when I shutdown the system (MS Windows) or ...
2
votes
1answer
105 views

Does magit support interactive git hook?

My git hook would prompt for answer yes/no when do the push. How could I get the prompt and enter my input when using Magit?
7
votes
2answers
545 views

Looking for something like a `first-keypress-in-a-while-hook`

Suppose that I have an Emacs session running, and that I step away from my computer for, say, 20 minutes. Upon returning to my Emacs session, at some point I will press some key while the Emacs ...
2
votes
1answer
281 views

`haskell-mode-hook` is nil?

The haskell-mode-hook customizable variable in haskell-mode has a default value of (haskell-indentation-mode interactive-haskell-mode). Yet, after starting Emacs, its value is nil; the "original ...
3
votes
4answers
342 views

Only enable auto-revert-mode for the current buffer

I use auto-revert-mode and ideally I would like the auto-revert-interval to be very small, e.g. 0.5 seconds or less. But I am concerned about performance problems when I have many buffers open, ...
5
votes
2answers
207 views

Detect if mouse button is held down?

I have some code that runs in a hook that I want to change to only execute only if the left mouse button is not currently held down. I don't see any obvious functions or variables that let me directly ...
2
votes
1answer
288 views

add a rule to syntax-propertize-rules

I have an issue outlined here that I was able to find a partial solution for. The problem involved changing perl-modes syntax table. One of the commenters pointed me to the function syntax-propertize-...
1
vote
1answer
69 views

Detect interactive use of `kill-buffer` in `kill-buffer-hook`

As per title, I want to define a kill buffer hook with the variable kill-buffer-hook and the function should be able to detect when (kill-buffer ) has been called interactively. Is this possible? ...
2
votes
1answer
241 views

Running an external shell command after org export

I'm writing a paper using org-mode, using the LaTeX export function to generate the .tex file I need to submit to the journal. How can I run an external shell command every time I to the C-c C-e l l ...
0
votes
1answer
102 views

different settings for ido-find-file and ido-switch-buffer

I like arbitrary substring matching for buffer completion but I want to disable it when completing file names or directories. The idea is to set ido-enable-prefix to t only when ido-find-file is ...
1
vote
1answer
240 views

Save and load different desktop files based on the mode

I would like to keep distinct desktop files in order to be able resume sessions based on the mode. When I open Emacs it should load the desktop file for the mode it starts with and when I run, say, M-...
1
vote
1answer
56 views

How to defer a remap until the affected keymap has been created?

I wanted to change the behavior of isearch in the minibuffer, making Return both accept a search result (isearch-exit) and submit it (minibuffer-complete-and-exit). This is the behavior I've grown to ...
1
vote
2answers
118 views

How to uppercase all input in elisp?

I want to create a mode which in certain states converts all input to uppercase, regardless of the caps-lock status. But I'm at a loss as to how to go for this, and I'm not sure it could even be done. ...
1
vote
1answer
85 views

How to make *Messages* use visual-line-mode?

I'd like to use visual-line-mode in the *Messages* buffer. I can switch to that buffer and run M-x visual-line-mode, but I want to configure it automatically. I've tried adding this to my init.el, but ...
1
vote
0answers
32 views

ESS hooks breaking buffers not associated with files

This is a weird one, for me: I use both ESS (for R programming) and gist.el for (surprise!) interacting with github gists. Except, now I have a problem: every time I try to view a gist locally, ESS's ...
2
votes
1answer
433 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
170 views

Emacs init file function vs hooks

Is there any differences between the following two ways of invoking a function in the init file. (add-hook `after-init-hook `turn-on-auto-fill) vs (turn-off-auto-fill)
1
vote
1answer
78 views

Hook to insert content into a particular file when visited

I want to insert content from one file anytime a file with a particular name is opened, i have this: (defun insert-foo-bar(filename) (when (string= (file-name-nondirectory filename) "foo") (...
2
votes
1answer
237 views

`server-start` hook?

Is there a hook to execute stuff after I've run emacs --daemon? I'd like to keep load stuff only when running emacs --daemon and not when running emacs. I know it sounds like using square wheels, but ...
3
votes
1answer
52 views

post-command hook for org-cut-subtree

I want to run newline command after whenever I run org-cut-subtree. I tried (add-hook 'after-org-cut-subtree-hook 'newline) (add-hook 'org-cut-subtree-hook 'newline) (add-hook 'org-after-cut-subtree-...
0
votes
1answer
237 views

How to disable a hl-anything in orgmode?

I'm trying to disable hl-anything only when I'm using org-mode or org-agenda-mode but I don't know how to do it. I have tried this: (add-hook 'org-mode-hook (lambda () (hl-...
3
votes
1answer
171 views

How to track user changes in the buffer?

I would like to make a mode that would react to user changing the buffer. One way i know is to use hooks. What hooks, other then post-self-insert-hook, should i use? What changes i am interested in: ...
5
votes
1answer
588 views

(la)tex-mode-hook doesn't work?

I was playing around with my .emacs, and I cannot figure out why the following does not work with .tex files: (add-hook 'tex-mode-hook (lambda () (show-paren-mode t))) On the other hand, the ...
5
votes
1answer
226 views

Make Emacs diff files before asking to save

When I run save-buffers-kill-emacs or projectile-kill-buffers I get asked to save changed buffers. But for me a lot of these buffers do not differ from the file on disk. Can I make Emacs diff the ...
7
votes
1answer
608 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?
0
votes
1answer
816 views

Changing mode-line face when evil state changes

I'm trying to change the mode-line face box attribute to be the same color as the evil emacs state face, obviously updating it each time the mode changes. I've seen some things about using a post-...
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 ...
0
votes
1answer
234 views

Hippie doesn't use yasnippet and fallback to emmet with emacs-lisp-mode

I use hippie-expand with emmet and yasnippet. (use-package emmet-mode :init (add-hook 'css-mode-hook 'emmet-mode) (add-hook 'sgml-mode-hook 'emmet-mode) :config (unbind-key "<C-return>" ...
0
votes
0answers
134 views

Recommendations for eval on save workflow for projects?

I've started to write a package and excessive use of the interactive eval-* functions has become a pain point for me. After I make a change re-evaluating entire file or package is almost always ...
2
votes
2answers
365 views

save a particular buffer without prompting on emacs exit?

I have a particular buffer that collects statistics from my emacs sessions. I could write the buffer every time I update the statistics, but that's not efficient. I want to auto-write the buffer ...
1
vote
0answers
64 views

Do Any Hooks for (Specific) Package Installation Exist?

I have a StumpWM configuration that loads a file contained in the SLIME package installed through Emacs (swank-loader.lisp). However, problems arise when my SLIME package is updated, because the ...
1
vote
1answer
469 views

Read first line of file when opening to rename buffer

I want to add a hook that reads the first line of the file/buffer when it opens. I want to do this so that I can rename the buffer that opens notes from simplenote. But, how do I read the first line?...
1
vote
1answer
219 views

bookmark on kill-buffer-hook

I'm using pdftools when displaying pdfs and it would be nice if emacs could bookmark the pdf with the default filename when I kill that buffer. I've got something like this, but it doesn't work. ;; ...
1
vote
1answer
67 views

how to recover from error in focus-in-hook

I registered a focus-in-hook that generates an error. Now any time I try to execute a command in the minibuffer I get an error and am then unable to execute the load-file that would be required to ...
1
vote
1answer
360 views

run-python does not work if added to python-mode-hook

I would like the Python inferior process to start (if it is not already running) whenever I create a python-mode buffer (for example, by visiting a .py file). Some functions in anaconda-mode etc. ...
0
votes
1answer
545 views

Enable visual-fill-column-mode only in text and programming mode

I am currently using visual-fill-column-mode and visual-line-mode in emacs with the following: (add-hook 'visual-line-mode-hook 'visual-fill-column-mode) (global-visual-line-mode t) (define-key ...
7
votes
2answers
512 views

Prevent folding org files opened by ediff

Folding gets in the way when merging two org files using ediff, so I'm trying to disable all folding in org-mode buffers created by ediff. Non-ediff folding behavior should remain unaffected. ...
6
votes
1answer
179 views

How to abort saving in a before-save-hook function?

If, in a function run from before-save-hook, I want to abort the saving of a file, so that the file is not saved and the user is signaled, how can I do that? Is it possible (without rebinding C-xC-s ...
4
votes
3answers
504 views

Call a function before a specific major mode starts

I have a setup function that I want to run before I use pdb/gud to debug a Python script. I know about gud-mode-hook which runs after the debugger starts (too late) and change-major-mode-hook which, ...