2022 Developer Survey is open! Take survey.

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
0 votes
1 answer
30 views

How can I check if buffer has been modified even after save-buffer

I need to test if the buffer has been modified even if (save-buffer) has been called after the changes. I thought to use add-variable-watcher but I found that buffer-modified-p is a function, not a ...
user avatar
0 votes
0 answers
21 views

Call a function and all relevant hooks inside a function

I have a function consisting of 2 commands. (defun my-function () (interactive) (call-interactively 'run-python) ; <-- Something is not run after this line. (call-...
user avatar
  • 191
0 votes
0 answers
17 views

(evil-normal-state) seems to have no effect as part of org-agenda-mode-hook

I'm attempting to move from Doom Emacs to vanilla Emacs. I've gotten quite used to the keybindings of Doom, so would like to replicate my most used ones in Emacs. I've used evil, evil collection, and ...
user avatar
0 votes
1 answer
46 views

lsp mode problems: not enabled, and clangd include file not found

I am trying to configure lsp-mode with clangd using emacs 28.1 (compiled from source), and encounter two problems that I do not manage to solve: First, `lsp-mode` is not started automatically when I ...
user avatar
  • 121
2 votes
1 answer
31 views

How to insert a flyspell hook on Magit via `use-package` declaration?

I am rewriting my Emacs config file to fully use use-package and organize code. Currently, I have (use-package magit :custom (magit-display-buffer-function #'magit-display-buffer-same-window-...
user avatar
3 votes
2 answers
204 views

Add hooks for a file type based on org-mode

I have associated a file extension with org mode as follows: (add-to-list 'auto-mode-alist '("\\.hy\\'" . org-mode)) I have also created certain hooks for org-mode and text mode as follows: ...
user avatar
0 votes
0 answers
21 views

Hooks with use-package and `ado-mode` not working

I'm trying to apply hooks to ado-mode a mode for working with the propietary software for statirstical analysis stata. However, the following doesn't work. Does anybody know why? (use-package ado-...
user avatar
  • 59
1 vote
1 answer
234 views

Non-blocking prompt for user input

I'm using the org-pomodoro, and I have added a function to the org-pomodoro-started-hook that prompts the user for a reminder for what they should do during the break. However, I don't want to call ...
user avatar
0 votes
2 answers
42 views

What hook should I use for org-roam when there is a creation/renaming of roam node

I wrote a function that will update my roam notes .gitignore. I would like to call this function whenever there is a creation or renaming of roam node. What hook should I be using?
user avatar
  • 288
1 vote
1 answer
34 views

Reload flyspell after changing ispell dictionary

Whenever I ispell-change-dictionary, I have to disable and re-enable flyspell-mode for flyspell to pick up the new dictionary. Is there a way to automate this? It probably involves a post-command-hook,...
user avatar
  • 314
1 vote
2 answers
69 views

How to make the writing of my commit messages faster in Magit?

I am using Magit. After staging some changes, when I press to commit something, Magit opens a buffer like this: # Please enter the commit message for your changes. Lines starting # with '#' will be ...
user avatar
0 votes
0 answers
16 views

Indent Headers in outline-minor-mode

In org mode, we can use the org-indent-mode hook to indent each header level, making a document with an outline more readable. However, with outline-minor-mode, we the org-indent hook doesn't seem to ...
user avatar
0 votes
1 answer
25 views

How to run a custom function after scheduling an entry in org-mode?

Is there an org-mode hook that would allow me to run a custom function after scheduling an entry (i.e. running C-c C-s/org-schedule in an Org buffer)? I've checked https://orgmode.org/worg/doc.html, ...
user avatar
1 vote
0 answers
15 views

How to make the response-mode wrap text in proof general

I'm using proof general and I would like to have the response window wrap text. The default display is a three-window mode. The buffers are called proof-script-buffer proof-goals-buffer and proof-...
user avatar
  • 111
0 votes
1 answer
32 views

parinfer-rust-mode doesn't get enabled automatically with clojure-mode via hook

The problem: upon opening a .clj file, the clojure-mode correctly starts. However, parinfer-rust-mode doesn't, despite being added to a clojure-mode-hook. The setup (everything related to clojure from ...
user avatar
4 votes
2 answers
71 views

How can I enable electric indentation for all modes except some?

I am trying to enable electric-indent-mode for all modes except fundamental-mode, where it is just annoying. In my init file, I have the following: (electric-indent-mode +1) (add-hook 'after-change-...
user avatar
  • 41
5 votes
1 answer
163 views

Is there a "switch to buffer" hook?

I'm running emacs 26.3. I want to run a hook every time I switch to a buffer. However, I have not been able to find any kind of "buffer switch hook". If I want to always run a function when ...
user avatar
  • 522
0 votes
1 answer
29 views

Using after-change-functions for an ansi-term buffer

I'm writing some Elisp that compiles code in watch mode using make-term. When the code compiles/tests pass, the compilation output is only a couple of lines. When there's an error, it can be much ...
user avatar
  • 101
3 votes
1 answer
28 views

How can I do something only if the minibuffer exits normally?

Simply attaching to minibuffer-exit-hook is not enough, because it also runs when the user presses C-g, so the command quits. Is there a way to determine in the hook if the command is exiting normally?...
user avatar
  • 1,058
0 votes
1 answer
33 views

Trying to update emacs from the command line, but add-hook won't fire

I want to update Emacs from the command line so I created the following function to help with this: ;;; update.el -- Update Emacs from the command line (defun update-emacs () "Update Emacs ...
user avatar
1 vote
2 answers
45 views

How to ask for confirmation before killing any new modified buffer?

What's the best way to prompt for confirmation before killing any modified buffer, including new buffers created by evil-buffer-new, which creates a buffer without an associated filename. Modified ...
user avatar
  • 163
1 vote
1 answer
92 views

is it possible to execute a command on specific set of files upon exiting emacs

I use emacs as my editor with mutt. I would like to run a python code on the /tmp/mutt-* files upon exit (that is called email-process, and that is written and works). For instance, in the case of vim,...
user avatar
0 votes
1 answer
24 views

debugging why emacs is autoformatting on save hook

I'm currently facing an issue where I am trying to save a file, but some save hook is triggering an auto formatting the file in a way that I do not want. I am not sure how to debug this issue. Ideally,...
user avatar
  • 101
1 vote
0 answers
17 views

How to ignore mail header in mu4e for visual-fill-column-mode

When setting a mu4e-view-mode-hook to fill columns for easy reading and without having to hard wrap the lines with fill-mode, then it also wraps the mail header, what makes it rather unreadable. Is ...
user avatar
0 votes
1 answer
41 views

How to make csv-align-mode default in tsv-mode?

I'm editing tab separated file with Emacs and csv-mode.el. When the document is open, I can align the columns with M-x csv-align-mode. How to make it automatically aligned when I open the file? Both ~/...
user avatar
  • 111
4 votes
1 answer
44 views

Adding a function call after a builtin runs

I always want to run reposition-window after c-beginning-of-defun. I've tried this: (advice-add 'c-beginning-of-defun :after #'reposition-window) it results in this at execution: Variable binding ...
user avatar
  • 387
1 vote
0 answers
20 views

Making compilation-error-regexp-alist buffer or project local

How can limit the compilation-error-regexp-alist to a subset depending on default-directory or even better (project-current)? My motive is that my compilation-error-regexp-alist contains too many ...
user avatar
  • 415
1 vote
1 answer
110 views

Disabling visual-line-mode only in org-agenda-mode

My emacs configuration has global visual line mode enabled via (global-visual-line-mode 1). I want to disable this mode, but only when in org-agenda-mode. When I do this manually, via M-x org-agenda, ...
user avatar
  • 13
0 votes
0 answers
28 views

Adding two times to the same hook breaks the functionality

I want to add two things to the java-mode-hook, but when I add the second one none of them is installed in the hook: ;;; Java (add-hook 'java-mode-hook (lambda () (set 'compile-command ...
user avatar
  • 103
0 votes
0 answers
37 views

How to delay execution of code after handling command line argument but also running it in batch mode?

According to ELisp manual, the emacs-startup-hook is run, once, just after handling the command line arguments. In batch mode, Emacs does not run this hook. Is there a standard way of delaying code ...
user avatar
  • 581
0 votes
0 answers
20 views

How to run clean-up code once magit has completed a re-base operation?

My emacs customisation has grown some considerable hairballs while I've been writing helpers to update commits. The idea being that when I re-base I can tag all the commits that need updating and work ...
user avatar
  • 4,526
1 vote
1 answer
61 views

How to dynamically replace certain text, by evaluating a function on change in current buffer

I am trying to figure out how to use window-change-functions refer here for official documentation to be able to run a function to replace certain text within the current buffer at every change of the ...
user avatar
0 votes
0 answers
27 views

How do I disable recentf-cleanup on exit?

How do I disable recentf-cleanup on exit? Setting (setq recentf-auto-cleanup 'never) is not enough.
user avatar
  • 620
1 vote
0 answers
59 views

olivetti misbehaving on save, in org buffers

I'm getting this very strange behavior while using olivetti: when calling save-buffer the display goes back to the left margin, as if olivetti has stopped working. If I call olivetti-mode, it shows ...
user avatar
1 vote
1 answer
65 views

How to check if point moved or is on a different line in a buffer since the last user command?

I would like to make a snippet of code that only executes if the point is on a different line in a particular buffer since the last user command. The only way I could think to do it was using the post-...
user avatar
  • 163
4 votes
1 answer
191 views

full screen hook?

Is there a way to add a hook for when emacs goes full screen? I'd like to set slightly different transparency for the frame when in fullscreen but there seems to be no easy way for that. What I would ...
user avatar
  • 51
0 votes
1 answer
36 views

How to pass the buffer being save to after save hook?

This question How to run an `after-save-hook` only when the buffer has been saved manually provides a way to have after-save hook run after pressing Ctrl-x Ctrl-s, in the answer Here's an alternative ...
user avatar
  • 113
2 votes
1 answer
102 views

How to override the :hook section of a use-package declaration

I am attempting to change the :hook section of a use-package declaration that I cannot directly modify. In my case, I want to remove hooks that are getting set, not just add more hooks. Is there a way ...
user avatar
  • 332
0 votes
1 answer
35 views

What is the mode for org's LOGBOOK editing window and how can one be created if it doesn't already exist?

I want to wrap the LOGBOOK editing window at column width I'm yet to decide. From another answer here I see need to set something along the lines of (add-hook 'some-logbook-mode-hook #'auto-fill-mode) ...
user avatar
  • 1,147
0 votes
1 answer
18 views

Do changes made inside a hook persist after the hook has finished evaluation?

Let's say I am setting a variable to a value inside a hook. I'm hooking the hook to the minibuffer-setup-hook so that it runs whenever the minibuffer opens. Will the changes made by the hook persist ...
user avatar
2 votes
0 answers
314 views

`lsp` does not start on python-mode-hook

I am using lsp under Python.lsp does not start when a Python file is opened, I have to do M-x lsp for each file I open. Also when I switch from find-file to another file I have to do M-x lsp all over ...
user avatar
  • 1,112
0 votes
1 answer
88 views

org-roam and persp-mode.el: persp-def-auto-persp has nil (buffer-file-name)

I would like all org-roam buffers to automatically go into a persp-mode.el perspective. org-roam-mode is a global minor mode, so I can't use that as a way to detect whether a new buffer is for org-...
user avatar
1 vote
1 answer
54 views

How to distinguish a scroll from a change of buffer in a function called from ‘window-scroll-functions’?

I've written a function that recenters the point each time it makes a long jump and I added it to the hook window-scroll-functions. The length of the jump is determined by comparing the return value ...
user avatar
  • 1,392
0 votes
1 answer
89 views

Persist variables (and maybe input history) across restarts [duplicate]

Sometimes I wish to persist the value of some variable when I quit emacs. For example, I would like to do this for compile-command. Now, I guess I could find the hook that is run when Emacs quits (...
user avatar
  • 317
0 votes
1 answer
37 views

How to modify text that's yanked?

I copy text from websites and paste/yank into emacs buffers. But this text sometimes has silent hyphens in them. The behaviour when copying and pasting text with soft hyphens in it varies across ...
user avatar
0 votes
1 answer
105 views

Where to place org-agenda-files sexp

I have this (setq org-agenda-files (directory-files-recursively "~/Dropbox/org/journal/" "\\.org$")) but I don't know where to place it in order to make sure that on the event of ...
user avatar
  • 2,717
0 votes
1 answer
255 views

Turn off auto-completion/company while in org-journal

Trying to get org-journal working, but it wants to auto-complete nearly every word I type, then require two space bar hits to advance to type next word. I tried this and it works (add-hook 'org-mode-...
user avatar
  • 2,717
0 votes
2 answers
87 views

Org-mode hook following creation of a new <<<radio target>>>

I want to call org-update-radio-target-regexp as soon as org-mode recognises that a new <<<radio target>>> has been created (which seems to happen as soon as the third ">&...
user avatar
  • 1,775
0 votes
0 answers
14 views

How to run my own hook that accumulates the result of each call?

I would like to define my own hook, where the result of each caller is collected (when the hook is run). Is there a way to do this? Currently I pass in a function to the hook, that function can be run ...
user avatar
  • 7,069
4 votes
1 answer
128 views

How do I focus the Man mode window when it is displayed?

When I open a man page (e.g. M-x man cat) I would like to automatically move my cursor onto the man page. I already know how to achieve this behavior for *Help* and *Apropos*, and I want to get the ...
user avatar
  • 553

1
2 3 4 5
7