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.

60 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
0answers
88 views

Get task duration from old timestamps

Assuming I have a task where I store a timestamp for every taskchange I do: * DONE Extremely important dummy task :categorywhatevs: - State "DONE" from "IN PROGRESS" [2015-06-08 Mo 14:...
4
votes
1answer
297 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 ...
4
votes
0answers
2k views

When using emacsclient, how can I open the file in the active buffer?

When I open a file with emacsclient without invoking -c, Emacs visits the file in a new buffer in the background while leaving my current window configuration in place. I'd like to change this, e.g. ...
3
votes
0answers
52 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
0answers
142 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 "...
3
votes
0answers
76 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?
2
votes
0answers
31 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 ...
2
votes
0answers
295 views

Faces not set immediately after load-theme

I'm trying to set the faces of highlight-indent-guides automatically whenever a new theme is loaded by making small adjustments to the background color of the default face. I have everything working ...
2
votes
0answers
389 views

How to make ansi-term output read only?

When using ansi-term in line mode emacs lets you edit the buffer arbitrarily, not just after the last prompt. I'm trying to make it read only so I stop fudging with command output. The problem is all ...
2
votes
0answers
273 views

Expand LOGBOOK on 2nd Tab press? (hook for 2nd org-cycle?)

In org-mode.. I store lots of state-change messages and timing info in the LOGBOOK drawer. Most of the time, I don't look into the LOGBOOK drawer, but once in a while when following up on a pending ...
1
vote
0answers
23 views

olivetti misbehaving on save, in org buffers

I'm getting this very strange behavior while using olivetti: when calling save-buffer the display goes back to the left margin, as if olivetti has stopped working. If I call olivetti-mode, it shows ...
1
vote
0answers
120 views

`lsp` does not start on python-mode-hook

I am using lsp under Python.lsp does not start when a Python file is opened, I have to do M-x lsp for each file I open. Also when I switch from find-file to another file I have to do M-x lsp all over ...
1
vote
1answer
29 views

How to distinguish a scroll from a change of buffer in a function called from ‘window-scroll-functions’?

I've written a function that recenters the point each time it makes a long jump and I added it to the hook window-scroll-functions. The length of the jump is determined by comparing the return value ...
1
vote
0answers
32 views

find-file-hook when visiting file literally

I'm trying to hook into find-file-literally to turn off some global minor modes when visiting a file literally (which I usually do for large files). However, it does not appear that find-file-hook is ...
1
vote
0answers
103 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 ...
1
vote
0answers
35 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 ...
1
vote
0answers
129 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
0answers
356 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
70 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 ...
1
vote
0answers
65 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 ...
1
vote
0answers
50 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 ...
1
vote
0answers
268 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)) (...
1
vote
0answers
51 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
0answers
33 views

ESS hooks breaking buffers not associated with files

This is a weird one, for me: I use both ESS (for R programming) and gist.el for (surprise!) interacting with github gists. Except, now I have a problem: every time I try to view a gist locally, ESS's ...
1
vote
1answer
630 views

Read first line of file when opening to rename buffer

I want to add a hook that reads the first line of the file/buffer when it opens. I want to do this so that I can rename the buffer that opens notes from simplenote. But, how do I read the first line?...
0
votes
0answers
19 views

How to delay execution of code after handling command line argument but also running it in batch mode?

According to ELisp manual, the emacs-startup-hook is run, once, just after handling the command line arguments. In batch mode, Emacs does not run this hook. Is there a standard way of delaying code ...
0
votes
0answers
19 views

How to run clean-up code once magit has completed a re-base operation?

My emacs customisation has grown some considerable hairballs while I've been writing helpers to update commits. The idea being that when I re-base I can tag all the commits that need updating and work ...
0
votes
0answers
21 views

How do I disable recentf-cleanup on exit?

How do I disable recentf-cleanup on exit? Setting (setq recentf-auto-cleanup 'never) is not enough.
0
votes
1answer
16 views

What is the mode for org's LOGBOOK editing window and how can one be created if it doesn't already exist?

I want to wrap the LOGBOOK editing window at column width I'm yet to decide. From another answer here I see need to set something along the lines of (add-hook 'some-logbook-mode-hook #'auto-fill-mode) ...
0
votes
0answers
29 views

Mark considered active after kill-ring-save even though it’s not

I’m having a small issue with a minor mode I’m writing. I’m using mark-active within pre-command-hook and post-command-hook in order to know whether a command just enabled/disabled the mark/region (I’...
0
votes
0answers
17 views

Change company-backends for tramp buffers

How do I change the company backends for remote buffers? Tramp doesn't seem to provide any useful hooks ... Related: Using different theme on tramp buffers (and buffer-related themes in general)?
0
votes
0answers
13 views

I would like to couple two autoloaded functions, while using use-package

I would like to couple elm-format-on-save-mode and elm-preview-main, so that when I save a file it gets formatted and compiled, and the generated html get's previewed. (use-package elm-mode :config ...
0
votes
0answers
13 views

How to run my own hook that accumulates the result of each call?

I would like to define my own hook, where the result of each caller is collected (when the hook is run). Is there a way to do this? Currently I pass in a function to the hook, that function can be run ...
0
votes
0answers
19 views

Better hook for a function activating a mode when there is only one window

As @drew asked me to do here I'm asking one question per problem I'm trying to enable/disable visual-fill-column when there is one window/multiple windows. (defun my-visual-fill-one-window () (...
0
votes
1answer
50 views

Is post-command-hook or idle timer better for doing something when the user becomes idle?

Let's say I want to write a mode which updates the display (e.g. adds some annotation) when the user edits the buffer or just moves around. What is the recommended way to implement this? Using post-...
0
votes
0answers
9 views

Flyspell overwrites C, C. ; modifying local-set-key after flyspell-mode-hook fails to change behavior

Flyspell sets the keys C-. and C-,. I prefer to have other binds living on these keys. I would have assumed locally setting keys in flyspell-mode-hook would have fixed this: (add-hook 'flyspell-...
0
votes
0answers
89 views

importmagic for python

I have the following in my .emacs.d/init.el, along the lines of what is suggested here: (require 'importmagic) (add-hook 'python-mode-hook 'importmagic-mode) (define-key importmagic-mode-map (kbd &...
0
votes
0answers
31 views

Changing global-whitespace-mode options locally to a particular buffer

I want to customize the behavior of global-whitespace-mode on a per-major-mode basis, and also define some interactive commands that change what's being highlighted on a per-buffer basis. global-...
0
votes
0answers
30 views

What is the hook for Slime Eval minibuffer?

I have installed Slime and Paredit (M-x package-install paredit) and I have configured it in my ~/.emacs too like this: (setq inferior-lisp-program "/usr/local/bin/sbcl") (add-hook 'eval-...
0
votes
0answers
28 views

How to test if flycheck is enabled?

For some of my JavaScript projects I use Flycheck with the javascript-eslint checker to highlight problems. This works great. I disabled many of js2-mode's checks so that they don't overlap with ...
0
votes
0answers
108 views

enabling olivetti by default for all text files

I want to have all text files (esp. org files) display with olivetti mode. I have the fo;llowing in my config: (add-hook 'text-mode-hook (lambda () (setq bidi-paragraph-...
0
votes
0answers
81 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 ...
0
votes
0answers
116 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 ...
0
votes
2answers
181 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
0answers
73 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
30 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
0answers
48 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 ...
0
votes
1answer
170 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
0answers
269 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 '...
0
votes
1answer
159 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 ...