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
0answers
12 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 ...
0
votes
1answer
114 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
2answers
41 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. ...
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
1answer
76 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 ...
0
votes
1answer
47 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
47 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: :...
5
votes
2answers
609 views

Different themes in different modes

I would like to do the following: load some theme when working on a particular kind of source file (say, Haskell), but elsewhere use a different "default" theme. I naively imagine that this is ...
3
votes
1answer
38 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
16 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
32 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 ...
0
votes
1answer
56 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 ...
2
votes
1answer
2k views

automatic latex-preview-pane with auctex and or-mode latex export

To enable automatic latex-preview-pane-mode with AUCTex I bound it to a hook: (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode) This works. When I open a *.tex file, then latex-preview-pane-mode ...
1
vote
1answer
43 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
19 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
25 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 "/...
4
votes
1answer
259 views

(How) can I emulate {eshell,comint}-output-filter-functions in term?

What I want to do from inside a term shell is have a function called when there is new output or a certain regexp (e.g. a prompt) appears in in a term's output. The callback function should then be ...
0
votes
1answer
886 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-...
0
votes
1answer
341 views

add-hook evil-insert-state-entry-hook is not calling the function

Update: It worked properly somehow after disabling and enabling nyan-mode. BUT there is no evidence indicating any relationship between them. Because I can't reproduce this problem after it was ...
1
vote
2answers
37 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
30 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
22 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
1answer
35 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
0answers
35 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
39 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
31 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
605 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 ...
1
vote
3answers
224 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
116 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, ...
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 ...
0
votes
0answers
35 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 ...
-1
votes
1answer
49 views

How to run function after specific buffer has been saved

If i want to run function when buffer "k" is saved, is there a better way to do this, then just using add hook and checking buffers name in function?
2
votes
2answers
75 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-...
2
votes
2answers
196 views

Change post-self-insert-hook only in one mode

I have written a functionality that inserts the word end at end of blocks in a lua major mode. How i do it is to check if a space character has been typed, if yes is the word before the space for ...
2
votes
1answer
49 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
46 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 ...
3
votes
1answer
408 views

How do I attach a custom function to process org-mode babel shell output?

I have a a function (defun display-ansi-colors () (interactive) (let ((inhibit-read-only t)) (ansi-color-apply-on-region (point-min) (point-max)))) that I got from here: http://stackoverflow....
1
vote
0answers
87 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 "...
1
vote
0answers
190 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
21 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 ...
5
votes
2answers
442 views

In org mode, how can I make a post-capture hook run only for certain capture templates?

I have several capture templates. With one of them, I want an Elisp function to transform the contents before saving it. I know of org-capture-prepare-finalize-hook, but this will run for every ...
1
vote
1answer
274 views

how to hook tern and web mode on certain files

I would like for tern to work only on React related files and Tern to only activate when working on React files with Web Mode turned on. Currently, I have tern generally set up with Web Mode, but the ...
0
votes
0answers
84 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
31 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
48 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
270 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
116 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
2 3 4 5 6