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
1
vote
1answer
21 views

How to setup ediff to open a new frame with the two comparison buffers

When I issue M-x ediff-buffersI'd like ediff to create a new frame with the two buffers (and close this frame when done with the comparison). How can I customise ediff to do so? I tried (defun leo-...
0
votes
0answers
34 views

Fit window to pdf upon loading

Question: I'm running auctex and pdf-tools to view pdf's within emacs. My problem is that I'd like to scale the pdf window horizontally after running C-c C-c. So far, I've created a hook to execute ...
1
vote
1answer
70 views

Disable Prettify-Symbols for C-mode

I'm using doom emacs. It enables prettify-symbols in all modes (I think) by default, although I would like to disable it in c-mode. I have placed the following in my config.el file: (add-hook 'c-mode-...
0
votes
0answers
42 views

How to trigger a hydra when entering evil-mode normal state?

I have the following: (use-package evil :hook (after-init . evil-mode) (evil-normal-state-entry . hydra-evil/body)) When leaving the emacs state (with C-z) and entering normal state, all my ...
1
vote
0answers
59 views

elfeed + olivetti modes

I want the elfeed-show-mode to be displayed with the olivetti minor mode olivetti-mode, so I do: (add-hook 'elfeed-show-mode-hook 'olivetti-mode) The problem is that the lines are not truncated ...
0
votes
0answers
14 views

How to format header files on close?

I have the following in my .emacs file. (require 'astyle) (add-hook 'c-mode-hook (lambda () (setq astyle-on-save-mode t))) (add-hook 'c++-mode-hook (lambda () (setq astyle-on-save-mode t))) For files ...
1
vote
1answer
58 views

Adding a lambda function as hook in use-package

I'm trying to adapt this answer to use-package elegantly. It requires that I hook a lambda function to python-mode. I came up with this solution — which works: (use-package python :hook (python-...
1
vote
2answers
49 views

How to find hook running after last line of code?

I have a repeating habit such as: ** TODO some habit SCHEDULED: <2020-05-22 Fri 08:00 .+1d> :PROPERTIES: :STYLE: habit :CREATED: [2020-05-08 Fri] :LAST_REPEAT: [2020-05-21 Thu 10:07] :END: :...
0
votes
2answers
51 views

How to get kill-buffer-hook to detach a screen session prior to kill-buffer?

I keep many screen session running in the backgroud, which I access with M-x eshell-command "screen -r <myscreen>". Before I kill the *screen* buffer, I have to detach the session with C-a d. ...
3
votes
1answer
41 views

Toggling minor modes based on other minor modes

I wrote a function to enable some minor modes when another minor mode is enabled: (defun prose-mode() (display-line-numbers-mode) (variable-pitch-mode)) I added prose-mode as a hook for olivetti-...
1
vote
1answer
14 views

List of hooks inhibited by inhibit-modification-hooks

The documentation of inhibit-modification-hooks states Non-nil means don't run any of the hooks that respond to buffer changes. This affects before-change-functions and after-change-functions, as ...
0
votes
0answers
18 views

Is there a way to undo hook attached to major modes in spacemacs?

In my .spacemacs file I set the following hooks to run: (add-hook 'js-mode-hook 'prettier-js-mode) (add-hook 'web-mode-hook 'prettier-js-mode) I, however, have projects where I don't want these to ...
0
votes
0answers
43 views

Troubleshooting “Match data clobbered by buffer modification hooks”

When running bibtex-reformat I get Match data clobbered by buffer modification hooks. I know according to the post here that one of my change hooks is clobbering the match data. In fact, when I set ...
1
vote
1answer
64 views

Hooks for agenda

I need to run a function every time I run org-agenda. However, I need it to run prior to the agenda. I wasn't able to find any hooks for the agenda command in the documentation. Any guidance is ...
1
vote
1answer
59 views

At what point are file-local and dir-local variables applied to a newly-loaded buffer?

I'm currently attempting to call the function company-org-roam--init-hook from org-mode-hook in order to enable the company-org-roam backend in org-roam buffers. In some of the files in which this ...
0
votes
0answers
35 views

Strange behavior with .txt files in Doom Emacs

In Doom Emacs, I have (add-hook 'text-mode-hook 'visual-line-mode t) in my config.el file. Files with a .txt extension act strangely, though. When the file is first opened, visual-line-mode is ...
0
votes
0answers
29 views

How to find what is creating and killing so many buffers?

A bunch of creating and killing buffers in my setup and I can't track down what is it. Here is my debug code: (add-hook 'kill-buffer-hook (lambda() (message "Killed: %s / %s" major-mode (...
0
votes
1answer
32 views

Auto evaluate org mode source block on file save

For example, whenever I edit my config, I run this block to reload the config: #+begin_src emacs-lisp :tangle no :var data=replace-symlink :results none (org-babel-load-file (locate-user-emacs-file "/...
1
vote
2answers
60 views

Help with function advice: Unknown add-function location ‘asm-calculate-indentation’

I'm trying to modify how asm-mode does its automatic indentation. I thought I would use the following: (defun yasm-calculate-indentation (oldfun) "Add the formatting for a few other keywords I like....
1
vote
1answer
32 views

Auto-refresh magit status only when magit is running

I've seen the post Magit: Auto-refresh “magit-status”, and tarsius recommends the same method from the Magit manual to set magit-after-save-refresh-status to non-nil to the after-save-hook: (add-hook ...
2
votes
0answers
25 views

Adding Emacs SES Mode Grid Lines

Began here using Emacs SES mode for some spreadsheets, but seems by default to lack the grid lines to help locating the cells and its values. Looks like it should be in some sort of hook in my .emacs ...
0
votes
0answers
41 views

add-hook for local-set-key in shell-mode not working

I have been using define-key global-map "\C-x\C-n" 'cmd-clear-and-rerun) for ~ 20 years where cmd-clear-and-rerun is a simple function I wrote long ago (see below). I only use C-xn in term-mode and/...
0
votes
1answer
42 views

mutilpe add-hook merge to one?

On my config i have too many add-hook,Is there any way to merge them and make them more beautiful. (add-hook 'go-mode-hook #'my-go-project-setup) (add-hook 'go-mode-hook #'lsp-deferred) (add-...
0
votes
1answer
37 views

How to save a org buffer everytime the todo state changes?

In both agenda mode or a regular org mode buffer, whenever I change the todo state, I want the buffer to be saved automatically.
1
vote
1answer
781 views

How to hook to functions?

I want to center my screen after calling flyspell-goto-next-error. If you have a "direct" solution please let me know, but I encounter the following issue more often: I'm looking to hook to the ...
0
votes
1answer
20 views

Change font or point colour based on absolute path of the source file

This is a rare occasion when I need it, but I am trying to figure out a way to change colour of font/point based on the path of source file to easily distinguish which file I am editing when I am ...
0
votes
0answers
37 views

Enable prog-mode when minor mode is activated

I created a minor mode for some specific file extension to fontify the syntax and provide correct indentation. 1)The indentation doesn't work for some reason. 2) How to enable prog-mode when the ...
2
votes
2answers
41 views

How do I add text to every new buffer that I create?

Suppose I want to put my name and the date at the top of every new buffer that I create. How would I do that? Furthermore, suppose I want to use the name of the new buffer in the text that I want to ...
1
vote
5answers
334 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 ...
2
votes
1answer
52 views

How to tell Occur to show the line in the top of the buffer

I usually use occur to make an index of the beginning of different things. When I jump to the occurrence, Occur shows the line in the middle of the buffer. How can I instruct occur to show the ...
3
votes
0answers
47 views

Package to detect most common typing mistakes

I'm a decent touch-typist, capping out around 90 WPM, but I know I'd be better if I eliminated some of the more persistent typos that crop up semi-consistently. It occurred to me this morning that ...
1
vote
0answers
99 views

How to disable eldoc when using TRAMP (editing files over SSH)

Eldoc really bogs down the editor when used over SSH with TRAMP. I want to disable it in those cases. What I've tried is this: (defun no-tramp-eldoc () (interactive) (when (string-prefix-p "...
0
votes
1answer
89 views

Write a function that runs another function after adding a hook

I want to run some function f after adding a hook to a mode and after running f remove the hook that I added, returning the result of f if there is one. Here is a non-working version that I hope ...
1
vote
0answers
215 views

use-package org-mode :hook is being ignored

I'm currently running this version of Emacs: GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.7) of 2019-04-11, modified by Debian I'm attempting to use use-package to configure the ...
1
vote
1answer
25 views

visual-line-mode-hook not runnng on mode exit

I would like to have whitespace-newline-mode enabled every time visual-line-mode is enabled, and disabled correspondingly. The documentation on "visual-line-mode-hook" says "Hook run after entering ...
0
votes
0answers
106 views

How to load image using iimage-mode when I first open a markdown file?

I have a file which embeds an image ![](file://tmp.jpg) I have added iimage mode to the markdown mode hook and even added recenter to it (add-hook 'markdown-mode-hook 'iimage-mode) (add-hook '...
1
vote
1answer
32 views

How to set setting for one mode only?

I currently have the hook below for displaying tabs when in text mode: (add-hook 'text-mode-hook (lambda () (standard-display-ascii ?\t "!---"))) I only want that setting to apply in text ...
0
votes
1answer
47 views

Is it possible to make a function local to the buffer?

I want to override the function helm-swoop-pre-input-optimize in man mode using its hook, but not anywhere else. Is there something similar to make-local-variable for functions?
0
votes
1answer
58 views

set fill-column in org-capture notes

I'm trying to customize the fill-column value for org-add-note when adding notes to an Org TODO (e.g., C-c C-z). I have tried to add the following to the org-add-note function (this seems reasonable ...
1
vote
1answer
308 views

Why after-init-hook is not invoked? (workaround is emacs-startup-hook)

short story: The theme just did not show up automatically at emacs start, when it is invoked by an after-init-hook. However, with emacs-startup-hook it worked as expected: (use-package heaven-and-...
2
votes
1answer
132 views

How do I make file paths clickable/navigable in Shell as described in the documentation?

For the life of me, I cannot get this functionality to work: https://wikemacs.org/wiki/Shell#Make_file_paths_clickable I've run (add-hook 'shell-mode-hook 'compilation-shell-minor-mode) in my .emacs ...
1
vote
2answers
78 views

How to increase a magic number in a file buffer on each save

I want to change a magic number (or a time stamp) in a file buffer on each save. The position of the magic number in the buffer can be given through a regex with a keyword or similar. Is there any ...
1
vote
1answer
39 views

window-configuration-change-hook false positives from desktop-mode

I'm trying to use window-configuration-change-hook in a package to perform some action when a buffer becomes visible for the first time. It works, however when starting Emacs, desktop-mode calls ...
0
votes
1answer
71 views

after-change-functions global value gets set to nil sometimes

I'm facing a strange issue and I don't know how to debug it. In the middle of work after-change-functions just gets set to nil. I use doom-modeline and it installs hooks to after-change-functions to ...
1
vote
1answer
70 views

How do I clear a global variable that also is buffer-local?

I called add-hook multiple times because I had a few typos in the hook function, and now there are a bunch of broken copies of it in the hook. I want to do (setq after-save-hook nil), but after doing ...
0
votes
1answer
116 views

Updating pyenv when switching to a Python buffer

I use pyenv to maintain my python versions and virtualenvs. I really like the way you can create a local .python-version for each project, pointing to the version I need. I use pyenv-mode which allows ...
0
votes
1answer
38 views

Trouble adding post-self-insert-hook in define-minor-mode

I am trying to write a minor mode that upon visiting a word, it manipulate it. There is a list of words which is parsed from a file. Here is the problem: (define-minor-mode auto-gls-mode "...
2
votes
1answer
141 views

delete-trailing-whitespace on save while always preserving location of cursor

I have the following before save hook defined which deletes all trailing whitespace and converts tabs to spaces (except in makefile mode since makefiles need tabs to work). This works great, however, ...
0
votes
2answers
39 views

How to automatically enable a mode for only one specfic type of buffer?

I user dired to browse file, and I would like to use hl-line-mode which highlights the currents line, but I only want it to be enabled automatically when using dired
1
vote
1answer
168 views

Cannot run a file-local after-save-hook with arguments

I have been trying to make auto-save compilation rules for my org files. I have tested the following functions in the interpreter: (defun async-shell-command-no-window (command) (interactive) (...

1
2 3 4 5 6