Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

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
1 answer
21 views

Can cape be disabled on a mode basis?

I love using cape in text mode, but I cannot figure out how to stop it from activating in programming modes. Is it possible to either only enable it in certain modes or to disable it in specific modes?...
J. Mini's user avatar
  • 165
1 vote
2 answers
63 views

Toggle minor modes in all current and future buffers derived from specific major mode

I am new to elisp. That's why I'd be glad if some of you could help me out. What I want to achieve I want to enable hl-line-mode and display-line-number-mode in all current and future buffers derived ...
user avatar
0 votes
2 answers
64 views

before-save-hook not working with use-package and custom mode

I wrote a little derived mode for the kage shader language, it's derived from go-mode (syntax is the same). I also like to use gofmt, but it's just not loading the hook. Here's the mode: (define-...
Tom's user avatar
  • 45
1 vote
1 answer
32 views

Run functions/hooks automatically when a specific FILE is opened

I'd like to run a function/set of functions when I open a specific file. Just like file type hooks, but for a specific file. For instance, when I open foo.bar, I'd like some functions to run. Maybe ...
Peter Petigru's user avatar
0 votes
1 answer
44 views

Configure compile command to take buffer-file-name as its source file argument

I am in the way of automating my compilation process with, what is an unexplored but an omnipotent command compile. I expect it to decide upon the compiler using the filename extension & also, ...
Saravana's user avatar
  • 2,071
0 votes
0 answers
18 views

How to put 'viper-change-state-to-emacs function on some hook

I am using viper-mode, which is vi emulator and can be switched to the original emacs mode with viper-change-state-to-emacs, when I edit program files. But, sometimes I want to create some special ...
20 Abbeyroad's user avatar
0 votes
1 answer
32 views

Precomposing all commands in a keymap with a function using a variable in another command

I'm working on a plugin that allows avy to act from a distance and immediately return to its starting position, which mostly works. However, there is a problem in that an action, such as the deletion ...
Alexander Praehauser's user avatar
0 votes
1 answer
35 views

company-mode: static sources overwrites LSP

I had a short experience with emacs a few years ago (spacemacs), and now I want to get back to it seriously. Within literally 3 days, I built my own config that turned regular emacs into a full-...
A.J.'s user avatar
  • 1
0 votes
1 answer
30 views

Placing a hook after each character insertion

I'd like to define a minor mode in which, when I write something, point is not moved and the characters are instead inserted after point. I thought that would be easy: just add a hook after insert-...
Alexander Praehauser's user avatar
0 votes
1 answer
52 views

Macros expanding to addhook

I have the following configuration lines in my init.el file regarding a specific mode: (add-hook 'pdf-view-mode-hook (lambda () (local-set-key (kbd "SPC h") #'evil-window-left))) (add-hook '...
Peter Petigru's user avatar
0 votes
0 answers
20 views

Branch descriptions in the magit references buffer

It would be convenient (for my workflow) to have the "references" (y) buffer display branch descriptions (as in git-branch --edit-description) instead of the latest commits titles. Is there ...
Yury Kudryashov's user avatar
0 votes
0 answers
30 views

Unable to install packages due to run-hooks error

I'm getting a strange error when installing packages using package-install. I haven't really updated anything in my configs but package installation suddenly stopped working. Any pointers or ...
iwakura1ain's user avatar
1 vote
0 answers
69 views

How to run a function when a variable is accessed/read in Emacs Lisp?

I'm trying to find a way to run a function whenever a specific variable is accessed or read in Emacs Lisp. I want to know which functions are using this variable, but I don't know them beforehand. I'm ...
HappyFace's user avatar
  • 830
0 votes
1 answer
120 views

`completion-at-point-functions` and filesystem path completion

I want to use filesystem path completion in programming modes and their derivatives. To do so, I attempted to add the following code to my init.el: (add-hook 'prog-mode-hook (lambda () ...
Alex's user avatar
  • 155
0 votes
0 answers
34 views

How do I pass a variable from a calling buffer to a called buffer?

The process of tangling in org involves, according to https://orgmode.org/manual/Extracting-Source-Code.html, a calling buffer and a called buffer, each of which have their own hooks: org-babel-pre-...
shintuku's user avatar
  • 121
1 vote
1 answer
62 views

running emacs as daemon halts if adding read-only-mode to prog-mode-hook

I want to have "read-only-mode" enabled in all programming buffers, including the starting buffer "scratch". If I add the line (add-hook 'prog-mode-hook 'read-only-mode) Running ...
Akari's user avatar
  • 43
0 votes
1 answer
71 views

Why does the execution of latex/hide-show-all with hooks not work?

I'm using AUCTeX, CDlatex and latex-extra to write LaTeX-files. When I access a file I'd want the contents of its sections to be hidden by default using the latex-extra1 command latex/hide-show-all, ...
Alexander Praehauser's user avatar
1 vote
1 answer
37 views

Return a list of functions with a given property or creating a group of functions

I am a copy editor and I make an intensive use of custom "predicates" when I perform replacements in LaTeX code. I use, among others, this technique: ;; predicate (defun omit-comments (beg ...
Gabriele's user avatar
  • 1,618
0 votes
1 answer
35 views

Cannot get rid of isearch overlays

The following code (defun nordlow/isearch-previous-symbol-at-point () (interactive) (cond ((eq last-command 'nordlow/isearch-previous-symbol-at-point) (isearch-repeat-backward)) ;avoid ...
Nordlöw's user avatar
  • 507
0 votes
0 answers
88 views

how to turn off python formatting in emacs

I have a python program that I edit in emacs. However, sometimes when I save it, it gets re-indented, and in doing so, messes up the indentation of sections, where I have some code and then some ...
Christopher Clark's user avatar
1 vote
1 answer
123 views

Add parsing of latex-style .el file to LaTeX-hook using AUCTeX

I did some online research (e.g. here) but couldn't figure out how to solve the following problem so far (of course, I might have overlooked something since the whole emacs community is new to me). ...
lukeflo's user avatar
  • 195
1 vote
1 answer
59 views

Use 'mapcar' to build a hooks list; "wrong-type-argument listp lambda"

How can I write a mapping (e.g. a mapcar expression) to build the list for a use-package :hook clause? I'm attempting to build the list in this :hook expression: (use-package eglot :hook ( (...
bignose's user avatar
  • 639
0 votes
0 answers
22 views

Parse elfeed's entry cl-struct

I'm trying to display notifications using elfeed's hook and alert. This works: (add-hook 'elfeed-new-entry-hook (lambda (entry) (alert (prin1-to-string (elfeed-entry-content ...
Daniel Krajnik's user avatar
0 votes
1 answer
42 views

Calling git commit from shell-command results in incorrect log message

I implemented the following to git commit after a file is saved. It works, I think, but the commit message, rather than being empty, is the literal value ''. This is the case whether or not I have any ...
user2567544's user avatar
0 votes
0 answers
53 views

Getting error in hook: Symbol’s function definition is void: \(setf\ ekg-note-tags\)

I'm writing a pre-save hook for ekg (emacs knowledge graph), and getting an error I don't know how to figure out. The error is triples--with-transaction: Symbol’s function definition is void: \(setf\ ...
GaryO's user avatar
  • 496
0 votes
1 answer
39 views

Turn off show-trailing-whitespace in Echo Area

When I run (setq-default show-trailing-whitespace t) on startup, the Echo Area is affected. I can usually turn this off with hooks, e.g. (add-hook 'minibuffer-setup-hook (lambda () (setq show-...
faulty_ram_sticks's user avatar
0 votes
1 answer
34 views

Third-party function overrides my customized variable and my mode hook

In the spacemace python layer, the following function overrides my customizations for the variable company-minimum-prefix-length python layer (defun python/post-init-company () ;; backend specific ...
degen872's user avatar
0 votes
1 answer
30 views

set the correct major mode for script files based on interpreter

I want to make a function that will set the correct major mode based on the interpreter used for a script. I don't want to include extensions in my scripts (because that can be annoying if making cli ...
Hackerman's user avatar
0 votes
0 answers
39 views

How to turn on `read-only-mode` when running a command in `comint` buffers and turn off it when the command is finished?

I'd like to prevent all user inputs when a command is running in comint-like buffers (created by shell, run-python etc.) by enabling read-only-mode when I hit enter to run the command and disabling it ...
Saddle Point's user avatar
0 votes
1 answer
48 views

Tide mode: how do I get it to stop running tide-format-before-save?

I'm at my utter wit's end with this hell-plugin lmao. I've tried (remove-hook 'before-save-hook 'tide-format-before-save t), and it doesn't work. How do I remove tide-format-before-save from the ...
Alexis Purslane's user avatar
0 votes
0 answers
31 views

Emacs is generating HTML file when opening markdown files

I don't know what is happening and how to debug this. I moved my Emacs config from Fedora to Xubuntu 22.04 (that use older version of GNU Emacs) and now each time I open markdown file (only once per ...
jcubic's user avatar
  • 743
0 votes
1 answer
441 views

How to fix lsp-mode for Elisp?

I have this set in my init file: ;; build dependency tree for function (use-package lsp-mode :ensure t :hook ((clojure-mode . lsp) (clojurescript-mode . lsp) (prog-mode . ...
Pedro Delfino's user avatar
1 vote
1 answer
58 views

How to proper install and configure js2-mode via use-package declaration?

I am trying to install this package called js2-mode. This is part of my effort to follow this tutorial. Package documentation and tutorial are using classic installation via package-install as follows:...
Pedro Delfino's user avatar
0 votes
0 answers
58 views

Highlighting entries with specific keywords in Elfeed

To avoid missing on important news, I am trying to highlight Elfeed entries containing specific words in their titles: (add-hook 'elfeed-new-entry-hook (elfeed-make-tagger :entry-title '("...
Carapuce's user avatar
1 vote
2 answers
108 views

How to enable `fill-paragraph` command to be executed every time ChatGPT replies via gptel package?

I have been using this cool Emacs package called gptel. However, it is annoying for me how lengthy the ChatGPT answers look on the screen. When I want to improve readability, I keep executing the fill-...
Pedro Delfino's user avatar
2 votes
1 answer
63 views

Automatically add a newline when dragging text from Firefox into Emacs

One of my workflows is drag lines from Firefox to Emacs (X). What I'm trying to accomplish is putting a new line after dragging every line. I've tried zillions of combination but I can't find the ...
Javier Ortega's user avatar
0 votes
0 answers
34 views

Polymode in org-edit-special

I use (add-hook 'python-mode-hook 'poly-python-sql-mode) where poly-python-sql-mode is a special polymode that correctly highlights SQL queries that are used within strings in a Python file. When this ...
guibor's user avatar
  • 121
0 votes
1 answer
61 views

frame hook load theme causes frame to crash after creation

I have attempted to change my emacs theme. I am using the emacs daemon and I have attempted to create a hook to change the theme on frame creation. However when this hook is active the frame crashes ...
Progamer's user avatar
1 vote
1 answer
50 views

How to set display margins for markdown-mode buffers?

Is there a way to set the display margins for markdown-mode buffers? I've read https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Margins.html and various suggested solutions but ...
jth's user avatar
  • 111
1 vote
1 answer
50 views

Calling org-indent-mode from org-mode hook causes infinite recursion?

I have the following code in my emacs init files, and it is causing an infinite recursion, which eventually bottoms out and throws an error. (defun robs-org-mode-hook () (org-indent-mode) ...) (...
Rob N's user avatar
  • 649
0 votes
1 answer
47 views

Using major mode dependent functions

I have a function (tika-outlhg-regexp) that sets custom outline headings based on major mode. I activate this with major-mode hooks. Is there some other way? (defun tika-addhook-hgptn () (add-hook '...
Dilna's user avatar
  • 1
0 votes
1 answer
159 views

Using hooks in minor modes

I have introduced the following hook function inside a minor mode. The intention is to activate the minor mode for a number of major modes. I would also need to activate outline-minor-mode once tika-...
Dilna's user avatar
  • 1
0 votes
0 answers
27 views

Move point from a hook in EMMS playlist doesn't work

I want to move point with the current played song in an EMMS playlist. I tried it with this code: (defun tvd-emms-follow-playing-song() (interactive) (message (format "%s" emms-playlist-...
Tom's user avatar
  • 45
2 votes
0 answers
64 views

Disable fill-column-indicator Only in Minibuffer

My code (custom-set-variables '(global-display-fill-column-indicator-mode t) '(minibuffer-mode-hook `(,@minibuffer-mode-hook ,(lambda () (...
shynur's user avatar
  • 5,318
0 votes
1 answer
50 views

Changing the definitions of outline-minor-mode headings

I would like to change the pattern for heading in outline-minor-mode. Have came up with the following implementation for emacs-lisp-mode that uses a minor-mode called taxocask-minor-mode. (defvar ...
Dilna's user avatar
  • 1
0 votes
0 answers
61 views

How to wait for buffers to load?

I'm trying to create a hook for ein package that will clean up split windows and focus on the rendered buffer. The package provides one hook (called ein:ipynb-mode-hook), but running functions below ...
Daniel Krajnik's user avatar
0 votes
1 answer
57 views

Hook resulting in a Wrong type argument error?

I am trying to do two things for Elfeed Summary: Automatically update the feeds when starting Elfeed Summary. Automatically hide the feeds without unread articles when starting Elfeed Summary. ...
Carapuce's user avatar
0 votes
1 answer
99 views

How to get a minibuffer state indicator for Evil's `evil-want-minibuffer`?

For regular buffers, Evil has a state indicator in the mode line. But when using Evil in the minibuffer (by setting evil-want-minibuffer to t), there's no state indicator besides the cursor. Viper had ...
mtraceur's user avatar
  • 356
0 votes
1 answer
64 views

How to update statistics cookies on file save?

For some reason, I can't get either of these to work. I'm trying to update the statistics cookies on TODO's automatically when the file saves. (add-hook 'after-save-hook 'org-update-statistics-cookies)...
innocentios's user avatar
0 votes
1 answer
79 views

How to never auto-save large files — or, how to run a function whenever any buffer starts — or, how to abort loading a minor mode in one of its hooks

I want to tell Emacs to never auto-save files bigger than ~1MB. I know how to turn off auto-save-mode when the file size is above a certain limit, but not how to make that function run automatically ...
Zorgoth's user avatar
  • 840

1
2 3 4 5
9