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.
409
questions
0
votes
1
answer
51
views
Call different functions based on buffer mode
I annotate my reading with org-remark and pdf-annot. They work with EPUBs and PDFs respectively, and are not interchangeable, with inconvenient consequences.
What I would like to do is to bind a ...
1
vote
1
answer
470
views
How can I turn off Company mode in only some major modes? [duplicate]
I use company when coding. I currently have it set to global. I would like to turn it off for a few major modes.
However, instead of turning it off globally, I only want to deactivate company for 2 or ...
4
votes
1
answer
82
views
Isearch + Dired fast navigation
After seeing this post and one of its comments, I am trying to implement the following convenient search pattern in dired:
Press C-s to start isearch
Type the substring I am looking for
Possibly jump ...
1
vote
1
answer
109
views
How can I save all buffers on auto-save except the ones have specifc mode?
I am using following full-auto-save () (https://www.emacswiki.org/emacs/AutoSave) to save all buffers on Auto-Save.
(defun full-auto-save ()
(interactive)
(save-excursion
(dolist (buf (buffer-...
1
vote
1
answer
114
views
How can I force require-final-newline nil?
I'm doing this from typescript-mode-hook:
(defun disable-final-newline ()
(setq-default mode-require-final-newline nil)
(setq-default require-final-newline nil)
(setq mode-require-final-newline ...
1
vote
1
answer
217
views
What is the difference between these two statements in my init file
I'm new to elisp- what is the difference between:
(add-hook 'js2-mode-hook
(lambda ()
(flyspell-prog-mode)
))
and
(add-hook 'js2-mode-hook 'flyspell-prog-mode)
?
1
vote
1
answer
57
views
How can I apply `bibtex-fill-entry` to the whole buffer?
When I run bibtex-fill-entry it formats the current entry block where the cursor is at. Note that bibtex-fill-entry (C-c C-q) Fill current BibTeX entry. So I have to traverse all the entries to align ...
1
vote
1
answer
825
views
Turn on minor mode rainbow-mode using use-package
I would like to turn on rainbow-mode in elisp and/or lisp modes when I am editing init.el using use-package. I've tried the following:
(use-package rainbow-mode
:demand t
:hook
((text-mode . ...
1
vote
1
answer
119
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 ...
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.
0
votes
0
answers
34
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-...
0
votes
1
answer
28
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 ...
0
votes
2
answers
102
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
133
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> =&...
0
votes
2
answers
98
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 ...
1
vote
1
answer
762
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
92
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 ...
1
vote
0
answers
326
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
455
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
37
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 ...
0
votes
0
answers
165
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
250
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 ...
1
vote
2
answers
152
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"))))...
0
votes
0
answers
29
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
91
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
...
0
votes
1
answer
153
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
103
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-...
2
votes
0
answers
435
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
2k
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 ...
2
votes
1
answer
119
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
914
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:
...
0
votes
1
answer
32
views
How can I run a function when vc-diff finishes?
The diff command can be async, of course. Is there an easy way to run a function when the async or sync diff command finished running and the diff buffer's contents is ready?
I checked, but I saw no ...
0
votes
0
answers
64
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-...
1
vote
1
answer
273
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
709
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?
1
vote
1
answer
144
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,...
1
vote
2
answers
375
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
1
answer
115
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, ...
1
vote
0
answers
38
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-...
0
votes
1
answer
139
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
471
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-...
6
votes
1
answer
1k
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 ...
-1
votes
1
answer
136
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 ...
3
votes
1
answer
75
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?...
0
votes
1
answer
49
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
133
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 ...
1
vote
1
answer
338
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
95
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,...
1
vote
0
answers
59
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
269
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 ~/...