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
62 views

Change minibuffer color when NOT in minibuffer AND minibuffer active

I frequently click on another application when I'm doing something in the minibuffer, and then I've forgotten I was in the minibuffer when I come back to emacs. I would like to highlight the ...
  • 169
0 votes
0 answers
11 views

How to install and configure clojure-refactor package with use-package instead of the classic imperative installation?

I am trying to install and configure this Emacs package called clojure-refactor. The official documentation uses the classic imperative installation with package-install. M-x package-install clj-...
1 vote
0 answers
52 views

Can I somehow hook a variable? [duplicate]

So a function is called when the variable value is changed? add-hook seems to only accept functions.
  • 266
0 votes
0 answers
21 views

Rainbow-delimiters with hooks

It seems that rainbow-delimiters does not work with hooks. For instance I have got (add-to-list 'auto-mode-alist '("\\.sty\\'" . latex-mode)) (require 'rainbow-delimiters) (add-hook 'tex-...
  • 65
0 votes
1 answer
26 views

Setting hook without calling external function

I am changing the default value for fill-column, then hook it for prog-mode. Would be neat to have a way that I can have a single function to do this. Currently add-hook requires a call to an ...
  • 15
0 votes
2 answers
37 views

How to enable markdown-mode every time I invoke Emacs Anywhere?

I am using a cool software called Emacs Anywhere. Usually, I invoke this software to write on Stack Overflow and on GitHub. Both websites use markdown. Hence, almost every time I invoke Emacs Anywhere,...
0 votes
1 answer
22 views

highlight-changes-mode: clear displayed changes after saving

I currently use this mode like so : (global-highlight-changes-mode t) (setq highlight-changes-visibility-initial-state nil); initially hide ;; toggle visibility (global-set-key (kbd "<f2> =&...
  • 129
0 votes
2 answers
24 views

How to add a hook to save things on kill-ring (or clipboard ring) before a frame is deleted?

Context: I have been using an interesting software called Emacs Anywhere. It helps me bring emacs keybindings for stuff like this (editing text for a question on Stack Exchange). Overall, the software ...
0 votes
1 answer
83 views

How to disable `tree-sitter-hl-mode` for `org-mode`/`markdown-mode` code blocks?

My tree-sitter setting is ;; Tree-sitter highlight ;; Base framework, syntax highlighting. (use-package tree-sitter :diminish (tree-sitter-mode) :hook ((after-init . global-tree-sitter-mode) ...
1 vote
1 answer
54 views

Incremental search line highlight

When running incremental search by pressing C-s repeatedly (isearch-repeat-forward) is there a way to highlight, in addition to the matching string, the line where that string is found? I would like ...
0 votes
0 answers
30 views

How to change this Paredit configuration on the init file from the classic imperative installation to a declarative approach via use-package?

When I first installed Paredit, I used to install things via the classic M-x and package-install. Then, I inserted the following configuration: (autoload 'enable-paredit-mode "paredit" "...
0 votes
1 answer
52 views

The latest Emacs initialization hook

I am currently running Emacs as a desktop with EXWM. And I am trying to run some apps on startup to see them in a EXWM's systemtray: (defun run-auto-start () (start-process-shell-command "...
0 votes
1 answer
29 views

Can't set indentation to 4 spaces because hook is not called

I'm trying to set the indentation in C++ files to be 4 spaces. To achieve this I have the following config: (setq-default indent-tabs-mode nil) (setq-default tab-width 4) (defun init-c-cpp () (setq ...
  • 103
0 votes
0 answers
18 views

Rewriting paths for bazel

The Bazel build tool has some features that interact poorly with emacs. When you build a C/C++ project for sandboxing purposes it makes a crazy hierarchy of symlinks, and uses them when invoking GCC. ...
0 votes
1 answer
39 views

How to set a specific background color for a certain string in text?

I would like to highlight each occurence of some word e.g. "covid" in a text when the file is loaded. It will be in org files but even global scope for all files is not a problem. So, I can ...
  • 35
1 vote
2 answers
72 views

Debugging a hook function

I have this code: (add-hook 'org-mode-hook (lambda () (when (string-match "notes\\.org$" buffer-file-name) (face-remap-add-relative 'default :background "yellow"))))...
  • 35
0 votes
0 answers
14 views

How do I view the entire call chain from a command?

I am facing weird issues from editing Kotlin code with LSP enabled with lsp-mode, in Spacemacs. Everytime I evil-yank and evil-mc-paste a line by yy followed by p, an empty line is pasted instead. The ...
0 votes
1 answer
29 views

context-menu-functions changing

Running emacs 28.1 whenever I use a mode derived from text-moe or prog-mode the value of context-menu-function is replaced. What is doing this and how can I stop it? The default is (context-menu-undo ...
  • 319
0 votes
1 answer
36 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 ...
0 votes
0 answers
25 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-...
  • 191
1 vote
0 answers
74 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 ...
0 votes
1 answer
408 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 ...
  • 131
2 votes
1 answer
44 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-...
3 votes
2 answers
288 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: ...
  • 1,069
0 votes
0 answers
37 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-...
  • 69
1 vote
1 answer
247 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 ...
0 votes
2 answers
161 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?
  • 288
1 vote
1 answer
49 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,...
  • 316
1 vote
2 answers
77 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 ...
0 votes
0 answers
29 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 ...
0 votes
1 answer
31 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, ...
  • 178
1 vote
0 answers
18 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-...
  • 111
0 votes
1 answer
45 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 ...
4 votes
2 answers
114 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-...
  • 41
6 votes
1 answer
371 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 ...
  • 552
-1 votes
1 answer
54 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 ...
  • 99
3 votes
1 answer
33 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?...
  • 1,068
0 votes
1 answer
35 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 ...
1 vote
2 answers
57 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 ...
  • 173
1 vote
1 answer
117 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,...
0 votes
1 answer
28 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,...
  • 101
1 vote
0 answers
20 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 ...
0 votes
1 answer
70 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 ~/...
  • 111
4 votes
1 answer
57 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 ...
  • 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 ...
  • 415
1 vote
1 answer
170 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, ...
  • 13
0 votes
0 answers
29 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 ...
  • 103
1 vote
1 answer
77 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 ...
0 votes
0 answers
59 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.
  • 630
1 vote
0 answers
68 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 ...

1
2 3 4 5
8