Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

4
votes
1answer
70 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
28 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 () (...
0
votes
1answer
22 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
15 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
68 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 ...
0
votes
0answers
17 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
35 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 ...
1
vote
1answer
33 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
14 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
64 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
22 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
79 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
43 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
20 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
52 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
136 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 ...
1
vote
0answers
32 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
54 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
189 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
40 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
53 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
56 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
59 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
91 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 ...
2
votes
1answer
217 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 ...
1
vote
0answers
31 views

Org-mode :results file hook to launch file

My scenario python code creating a wav file last line of code returns the written file name org-mode src block with the option :results file The result block correctly links to the audio file, and I ...
3
votes
1answer
151 views

Hook with quoted lambda as an argument

I been reading a blog post from Chris Wanstrath from 2010 where he write about coffee-mode. He proposed there this functions hook: (defun coffee-custom () "coffee-mode-hook" ;; Emacs key binding ...
2
votes
1answer
408 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
2answers
54 views

Best hook to keep my regexp highlighted

I need to have non-ASCII chars highlighted in my latex-mode buffers. So I added this lines in my .emacs: (add-hook 'LaTeX-mode-hook '(lambda () (highlight-regexp "[^[:ascii:]]" 'custom-...
0
votes
0answers
24 views

Timing interactive command invocation

Is there a clean way to take action after each interactive command with the duration of the command as its argument? My requirements are: defadvising every call-interactive is too much, because I use ...
1
vote
1answer
260 views

Spacemacs trigger holy mode in major mode

I'm using Spacemacs for clojure development and have gotten used to the vim commands mostly. However, when I start up a Repl I would like to only use holy mode with insert mode. Does anyone know how/...
2
votes
1answer
116 views

Delete auto-save file when killing Emacs without saving buffer

When I have unsaved buffers and I kill Emacs with save-buffers-kill-terminal (C-x C-c) I'm asked whether to save each buffer. Is it possible to delete a buffer's auto-save data when I answer n? I had ...
0
votes
1answer
71 views

Load custom highlighting after colorscheme change

I am a Vim user and i recently decided to try Emacs Spacemacs, i have a problem setting up custom highlighting, i set some lines like the following in my .spacemacs (i guess it's the same problem in ...
1
vote
1answer
38 views

Is it possible to have a global prettify-symbols-alist that other modes add to?

Is it possible to have a global prettify-symbols-alist that other modes add to? A lot of major modes override prettify-symbols-alist instead of pushing into it. One solution I thought of is to push ...
0
votes
2answers
223 views

Buffer-local after-save-hook?

I'd like to register an after-save-hook that is only active in certain buffers that I specify. For example, assume there are 3 functions currently registered in my after-save-hook: hook-01, hook-02, ...
1
vote
1answer
120 views

Delete trailing whitespace when saving, except certain modes

How can I delete-trailing-whitespace when saving, except for certain modes? With this attempt, whitespace is deleted for all modes, including fundamental-mode, which I'm trying to avoid. (add-hook '...
3
votes
1answer
479 views

How to avail of `:hook` using use-package?

I've wrote this, and it works: (use-package web-mode :ensure t :mode (("\\.php$" . web-mode) ("\\.html$" . web-mode)) :preface (defun dg/web-mode-hook()) :config (add-hook 'web-...
0
votes
1answer
38 views

Weird reformatting, cannot tell what is responsible

In my code I have bindings for two reformatters that are supposed to be applied upon saving relevant code: (add-hook 'tuareg-mode-hook (lambda () (add-hook 'before-save-hook 'ocp-indent-buffer ...
2
votes
1answer
55 views

How to avoid accidentally writing temporary source-block-edit-buffers to file

When doing literate programming in org-mode, I frequently use C-c '[aka M-x org-edit-special] to enter the source-block-edit-buffer, so that I have appropriate yasnippets etc. I then accidentally ...
2
votes
2answers
198 views

How to run a 'prog-mode-hook' after more specific hooks?

I'm running into an order of initialization issue with hooks. prog-mode-hook enables fci-mode rust-mode-hook sets the fci-rule-column to 99. on initial display the fill column shows at 80 (it's ...
2
votes
2answers
76 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 ...
1
vote
2answers
150 views

Disable minor mode when in another minor mode

I'm running a distribution of spacemacs and am currently working in clojure's cider debugger, and an issue I've run into is that several of the cider--debug-mode keybindings are shadowed by evil-mode. ...
6
votes
2answers
81 views

Is there a hook that runs for all read only buffers

I want to enable show-trailing-whitespace for editable file and disable show-trailing-whitespace for read only files. I've tried (defun my/read-only-whitespace () (setq-local show-trailing-...
1
vote
1answer
42 views

Run function after changing buffers with helm-list-buffers

helm-list-buffers brings up a list of buffers to select. I'd like to run a function after buffer selection. What's the method to do this?
2
votes
1answer
63 views

is there a hook that is run before a window is deleted

I want to do some custom stuff before a window is deleted? window-configuration-change-hook seems to be invoked after a window is deleted.
1
vote
0answers
103 views

How to get customizations added to `ess-mode-hook` to run in Aquamacs ESS

In Aquamacs 3.3, ESS 16.04, I can't get customizations added to ess-mode-hook to run. Here's a simple example. (defun my-ess-hook () (setq ess-default-style 'DEFAULT) (setq ess-indent-level 2)) (...
2
votes
0answers
43 views

Hook variable for horizontal scrolling

There is the hook variable window-scroll-functions for functions to be called before redisplay after vertical scrolling. Is there a similar variable for horizontal scrolling?
0
votes
0answers
24 views

Call a function every time a specific piece of text is inserted

I'm wondering whether there is an already existing mechanism of executing a function every time a specific piece of text is inserted. For example, I would like to call company-bibtex whenever I enter ...
0
votes
1answer
126 views

focus-in-hook and buffer-file-name

I have the following in my init file (defun message-buffer-file-name-or-nothing () "Mode line proxy." (if buffer-file-name (message "[%s] %s" (format-time-string "%H:%M:%S") ...
0
votes
1answer
188 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 ...