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
2
votes
1answer
153 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
139 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 ...
4
votes
1answer
500 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
46 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
263 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
1k 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
67 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-...
1
vote
1answer
535 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
339 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
106 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
96 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
606 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, ...
2
votes
1answer
298 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 '...
5
votes
1answer
1k 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
48 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
72 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
577 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
166 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
296 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. ...
7
votes
2answers
130 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
53 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
93 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
192 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
59 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
27 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
212 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
295 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 ...
0
votes
1answer
156 views

Is there a Magit hook for post checkout?

Unfortunately, the vc-mode in my mode-line is not being updated when checking out a branch, it still points to the older branch. revert all open buffers fixes than but I can't find a hook to attach ...
1
vote
1answer
107 views

Issue with add-hook for web-mode and js2-mode when using ranger

I wanna add some hooks to web-mode and js2-mode, but it doesn't go well. Here is what I am doing. I wanna to add header line for web-mode and js2-mode cuz they are derived from fundamental-mode. And ...
0
votes
0answers
71 views

recenter *xref* buffer on next-error

I have a next-error-hook to recenter the next-error-last-buffer, so if the buffer is displayed, it will recenter to the line of the error I just jumped to: (defun jpk/next-error-hook () (let ((win (...
1
vote
1answer
72 views

How to write a hook to transform each image reference on export?

This question https://emacs.stackexchange.com/a/27065/13217 explains perfectly how to embed base64 image inside of an HTML exported document, and it works great. I wonder now how could I automate ...
3
votes
1answer
273 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....
2
votes
2answers
80 views

How to hook selection changed

I want to create a minor mode that translates selected text. So I want to call a function when selection is changed. How can I detect the change of selection?
0
votes
0answers
142 views

Using hooks to organize configuration

Up to this point, I used to have a separate configuration for each major mode, e.g. init.org.el, init.c++.el etc. I would invoke Emacs using an one of the aliases like these: alias emacs-org='emacs -...
0
votes
1answer
251 views

Adding new syntax highlighting for some major modes does not work

My question is similar to this one and that one: I would like to add highlighting of some characters that are not highlighted in some programming modes, like python-mode and fortran-mode. So, ...
1
vote
1answer
387 views

Dedicated compile hook on compilation finish

I use the compilation-finish-functions hook to perform some actions once compilation finishes. However, unexpectedly to me the hook is also triggered when rgrep completes. I can't seem to find a ...
4
votes
1answer
237 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
0answers
172 views

How can the ace-window hotkey be set to work in sr-speedbar?

I have configured the M-p key to trigger ace-window, but when I navigate to the sr-speedbar window it stops working and I have to use C-x o to move out. Is there some mode hook I have to use to ensure ...
0
votes
1answer
311 views

Run command after each type/insert in particular buffer

I'm implementing a (optional, de-activable) real-time syntax checker. Each time the user types/deletes anything, I want to run my spell-checking funtion : I tried (add-hook 'post-self-insert-hook '...
1
vote
1answer
122 views

Hook that fires any time ANY file is opened?

Is there a hook that gets called any time a file is opened, not a buffer but an actual file?
1
vote
1answer
107 views

Hiding mode-line in speedbar buffer

I would like to hide the mode-line completely in a speedbar buffer. Calling (setq mode-line-format nil) in the buffer works temporarily, but I would like to make this setting permanent. Adding a hook ...
1
vote
0answers
40 views

Running emacsclient causes some flashing effect to happen on other frames

I picked up this code from: Is there any way to run a hook function only once? (setq myGraphicModeHash (make-hash-table :test 'equal :size 2)) (puthash "gui" t myGraphicModeHash) (puthash "term" t ...
1
vote
1answer
111 views

ido-find-file: typing “//” triggers loading of tramp

When using M-x``ido-find-file and typing "//" via keyboard in the minibuffer, some hook or function is triggered which starts loading the tramp package. Which tramp function is triggered and how to ...
1
vote
1answer
349 views

Is there a mode-hook when you switch to a buffer in Eshell mode

For my function, that I have created, I'm looking for an Eshell mode hook. I'm aware of the following hook: (add-hook 'eshell-mode-hook 'my-function-for-eshell). But what when I'm in a other ...
4
votes
1answer
133 views

how to read messages which appear after `C-x C-c`?

When I exit emacs via C-x C-c (save-buffers-kill-terminal) it prints a message in minibuffer. I can't read the message because the frame gets destroyed too fast. I'd like to read the message(s), how ...
1
vote
1answer
266 views

How to debug c-mode-common-hook that doesn't fire

I'm using prelude mode, and in a file .emacs.d/personal/old-settings.el I have, amongst other things: (global-set-key (kbd "C-c C-c") 'comment-region) (add-hook 'c-mode-common-hook (lambda() ...
3
votes
1answer
104 views

Variable assignment for programming modes not working

I want to set the variable truncate-lines to t in order to have truncated lines, but only in programming modes. So, following this thread, I put the following code in my configuration file: (defun my-...
0
votes
1answer
146 views

Save and restore variable

I am working on Spacemacs which gives you the ability toggle between Emacs "holy-mode" and Vim "evil-mode". However the evil-escape minor mode is still enabled. I am trying to find some way to disable ...
1
vote
1answer
307 views

How to clock-out current org-task before exit from Emacs?

How to clock-out current org-task before exit from Emacs? I tried (add-hook 'kill-emacs-hook #'org-clock-out) But if there is no current active tasks, Emacs says "No active clock" instead of exit. ...
0
votes
0answers
107 views

Do something before window configuration change

AFAIK, window-configuration-change-hook applies after a configuration change, and there is no corresponding window-before-configuration-change-hook. What's the best way to detect window ...