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
39 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
42 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
45 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 ...
0
votes
0answers
29 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
35 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
57 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
12 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
25 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
26 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
44 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
32 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
111 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
54 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
58 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 ...
0
votes
1answer
23 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
41 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
44 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
61 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
22 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 "...
1
vote
1answer
60 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
32 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
72 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) (...
0
votes
0answers
22 views

Haskell-mode-hook help window keeps opening

I installed haskell-mode, but every time I press RET or TAB on a Haskell file it keeps opening that window Any idea on how to deactivate this ?
0
votes
1answer
92 views

Run a function before/after magit runs git

I'd like to run a function before magit runs git, and another one after magit runs git. I see magit-pre-start-git-hook but I don't see any post-finish-git hook. How can I run commands before and after ...
1
vote
2answers
95 views

Run function after specific snippet

I have a workflow that goes like, 1) use a snippet then 2) call a function. What a glorious opportunity to automate! But how? The snippet ipdb inserts import ipdb; ipdb.set_trace(). It has ...
5
votes
1answer
86 views

Why (lambda () (run-hooks 'foo)) instead of just 'foo?

I am studying the following code snippet taken from prelude-c.el: ;; taken from prelude-c.el (defun prelude-makefile-mode-defaults () (whitespace-toggle-options '(tabs)) (setq indent-tabs-mode t)...
1
vote
1answer
66 views

ibuffer-expert not working

I want to make my ibuffer not to be pompted. So it is my config for ibuffer (setq ibuffer-expert t) ;; disable prompt when deleting modified buffer. (add-hook 'ibuffer-hook (lambda () (...
-1
votes
1answer
45 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?
0
votes
0answers
28 views

Alarmbell on saving .py file if linting errors using flake8

I'd like to configure Emacs to play an audible noise when saving my .py files but only if there is a linting error present. I currently have flycheck linting done on the fly and autopep8 settings ...
2
votes
2answers
199 views

Are there hooks for leaving modes?

There seems to be a bug in clojure-mode (mentioned here) because it does things in a mode hook (for paredit-mode) but doesn't undo them when the mode is turned off. I understand that add-hook can ...
1
vote
1answer
157 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
1answer
64 views

Tramp keep losing remote file permissions

I use: Emacs 26.1 on Windows 10 with tramp with plink/pscp to edit perl scripts on a remote Linux server The scripts are executable (permissions 755). When I load and then save them, if short time ...
2
votes
1answer
87 views

How to automatically remove a hook provided by a minor mode after disabling that mode?

I want to write a minor which evaluates some code in the buffer after saving a file. I activate after-save-hook for this mode: (add-hook 'my-minor-mode-name-hook #'(lambda () (add-hook 'after-save-...
1
vote
1answer
26 views

Set prefix key on load of minor mode

I am trying to change the default prefix key C-c @ to C-c for outline-minor-mode: (define-key outline-minor-mode-map (kbd "C-c") (lookup-key outline-minor-mode-map (kbd "C-c @"))) This ...
3
votes
1answer
76 views

Check if current user undoing/redoing?

Is there a way so that the Emacs are able to tell if the current user is undoing/redoing in the current buffer? Here is the task I want to accomplish, I have add a hook to after-change-function, it ...
-1
votes
1answer
27 views

Function that outputs changes made in buffer

Is there any function that would tell me what changes were made to buffer? I know i can use change hooks to detect changes, but i can't find how to get output of changes. More specifically I would ...
2
votes
1answer
97 views

Execute function when (after) window scrolls

I need to execute a function every time a window scrolls. I mean the function to be executed at point "after" the window has been scrolled (with C-v, M-v or with the <down> key). I tried: (add-...
1
vote
1answer
63 views

Hook when line number changes

Is there a hook which runs when the cursor position changes its current line numbers? For a concrete toy problem, can i highlight the current line as yellow when the line number of the current cursor ...
0
votes
1answer
26 views

Hooking on to abbreviation expansion

I don't know exactly how abbrev-mode works, but I suppose certain keys --spaces and stops-- cause an examination of the word before point, and a replacement of it in some cases. My question is how ...
1
vote
1answer
107 views

Which hooks guarantee proper (re)displaying of windows after windows configuration is changed?

I'm writing a simple minor mode (for personal use) which dynamically sets fringes according to current window width. I added a dedicated function to those hooks: window-configuration-change-hook ...
0
votes
1answer
544 views

Adding multiple functions to a hook

I'm looking to add some elisp to my init file that will execute a number of additional functions when I call a particular command. More specifically, when I execute the compile and view command using ...
3
votes
2answers
174 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
78 views

Scrollbar only on selected buffer

I'm using toggle-scroll-bar to show scrollbar on my frame. But is there a way to show scrollbar only on the selected buffer? I think I can use focus-in-hook to detect when a buffer is active, but I ...
1
vote
1answer
563 views

How to set mode hook with lambda using use-package

I'm attempting to set the following hook using use-package, but it's not getting applied. Normal elisp: (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))) Using use-package: (use-package ...
1
vote
2answers
77 views

How to find in which hook(s) a certain function is called?

I'm using the lsp layer on Spacemacs with javascript-backend 'lsp and it activates two modes I don't like: lsp-ui-mode and eldoc. I found lsp-ui-mode inside lsp-mode-hook and added (remove-hook 'lsp-...
4
votes
1answer
96 views

How to suppress a minor mode's key binding in only certain major modes?

Suppose that I use minor mode MIN with a whole bunch of major modes. In one of those major modes, call it MAJ1, MIN's binding for a specific key K is undesirable; I would therefore like to suppress ...
0
votes
1answer
127 views

Unable to initialize org agenda with log on Emacs startup

I have been able to initialize org agenda on Emacs startup with: (add-hook 'emacs-startup-hook 'org-agenda-list) However, now I want to initialize org agenda directly with log mode, and I haven't ...
2
votes
1answer
137 views

Running a function every time a character is inserted

I want to check its properties as soon as a Greek word has been inserted into the buffer. As far as I can see, this requires me to check each time the buffer changes, whether, if a Greek word was ...
1
vote
2answers
126 views

how to add a hook to a custom interactive command

I have a pipeline that opens an emacs client in notmuch-mode when new mail comes in, currently using (notmuch-show "thread:..."). I'd rather use tree view with the most recent message displayed. In ...
3
votes
1answer
441 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 ...