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

Using after-change-functions for an ansi-term buffer

I'm writing some Elisp that compiles code in watch mode using make-term. When the code compiles/tests pass, the compilation output is only a couple of lines. When there's an error, it can be much ...
2
votes
1answer
20 views

How can I do something only if the minibuffer exits normally?

Simply attaching to minibuffer-exit-hook is not enough, because it also runs when the user presses C-g, so the command quits. Is there a way to determine in the hook if the command is exiting normally?...
0
votes
1answer
28 views

Trying to update emacs from the command line, but add-hook won't fire

I want to update Emacs from the command line so I created the following function to help with this: ;;; update.el -- Update Emacs from the command line (defun update-emacs () "Update Emacs ...
1
vote
2answers
36 views

How to ask for confirmation before killing any new modified buffer?

What's the best way to prompt for confirmation before killing any modified buffer, including new buffers created by evil-buffer-new, which creates a buffer without an associated filename. Modified ...
1
vote
1answer
66 views

is it possible to execute a command on specific set of files upon exiting emacs

I use emacs as my editor with mutt. I would like to run a python code on the /tmp/mutt-* files upon exit (that is called email-process, and that is written and works). For instance, in the case of vim,...
0
votes
1answer
19 views

debugging why emacs is autoformatting on save hook

I'm currently facing an issue where I am trying to save a file, but some save hook is triggering an auto formatting the file in a way that I do not want. I am not sure how to debug this issue. Ideally,...
0
votes
0answers
9 views

How to ignore mail header in mu4e for visual-fill-column-mode

When setting a mu4e-view-mode-hook to fill columns for easy reading and without having to hard wrap the lines with fill-mode, then it also wraps the mail header, what makes it rather unreadable. Is ...
0
votes
1answer
15 views

How to make csv-align-mode default in tsv-mode?

I'm editing tab separated file with Emacs and csv-mode.el. When the document is open, I can align the columns with M-x csv-align-mode. How to make it automatically aligned when I open the file? Both ~/...
4
votes
1answer
42 views

Adding a function call after a builtin runs

I always want to run reposition-window after c-beginning-of-defun. I've tried this: (advice-add 'c-beginning-of-defun :after #'reposition-window) it results in this at execution: Variable binding ...
1
vote
0answers
15 views

Making compilation-error-regexp-alist buffer or project local

How can limit the compilation-error-regexp-alist to a subset depending on default-directory or even better (project-current)? My motive is that my compilation-error-regexp-alist contains too many ...
0
votes
1answer
44 views

Disabling visual-line-mode only in org-agenda-mode

My emacs configuration has global visual line mode enabled via (global-visual-line-mode 1). I want to disable this mode, but only when in org-agenda-mode. When I do this manually, via M-x org-agenda, ...
0
votes
0answers
28 views

Adding two times to the same hook breaks the functionality

I want to add two things to the java-mode-hook, but when I add the second one none of them is installed in the hook: ;;; Java (add-hook 'java-mode-hook (lambda () (set 'compile-command ...
0
votes
0answers
29 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
20 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 ...
1
vote
1answer
54 views

How to dynamically replace certain text, by evaluating a function on change in current buffer

I am trying to figure out how to use window-change-functions refer here for official documentation to be able to run a function to replace certain text within the current buffer at every change of the ...
0
votes
0answers
23 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.
1
vote
0answers
41 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
1answer
49 views

How to check if point moved or is on a different line in a buffer since the last user command?

I would like to make a snippet of code that only executes if the point is on a different line in a particular buffer since the last user command. The only way I could think to do it was using the post-...
4
votes
1answer
100 views

full screen hook?

Is there a way to add a hook for when emacs goes full screen? I'd like to set slightly different transparency for the frame when in fullscreen but there seems to be no easy way for that. What I would ...
0
votes
1answer
21 views

How to pass the buffer being save to after save hook?

This question How to run an `after-save-hook` only when the buffer has been saved manually provides a way to have after-save hook run after pressing Ctrl-x Ctrl-s, in the answer Here's an alternative ...
2
votes
1answer
50 views

How to override the :hook section of a use-package declaration

I am attempting to change the :hook section of a use-package declaration that I cannot directly modify. In my case, I want to remove hooks that are getting set, not just add more hooks. Is there a way ...
0
votes
1answer
26 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
19 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
14 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
1answer
18 views

Do changes made inside a hook persist after the hook has finished evaluation?

Let's say I am setting a variable to a value inside a hook. I'm hooking the hook to the minibuffer-setup-hook so that it runs whenever the minibuffer opens. Will the changes made by the hook persist ...
2
votes
0answers
181 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 ...
0
votes
1answer
67 views

org-roam and persp-mode.el: persp-def-auto-persp has nil (buffer-file-name)

I would like all org-roam buffers to automatically go into a persp-mode.el perspective. org-roam-mode is a global minor mode, so I can't use that as a way to detect whether a new buffer is for org-...
1
vote
1answer
41 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 ...
0
votes
1answer
54 views

Persist variables (and maybe input history) across restarts [duplicate]

Sometimes I wish to persist the value of some variable when I quit emacs. For example, I would like to do this for compile-command. Now, I guess I could find the hook that is run when Emacs quits (...
0
votes
1answer
33 views

How to modify text that's yanked?

I copy text from websites and paste/yank into emacs buffers. But this text sometimes has silent hyphens in them. The behaviour when copying and pasting text with soft hyphens in it varies across ...
0
votes
1answer
63 views

Where to place org-agenda-files sexp

I have this (setq org-agenda-files (directory-files-recursively "~/Dropbox/org/journal/" "\\.org$")) but I don't know where to place it in order to make sure that on the event of ...
0
votes
1answer
98 views

Turn off auto-completion/company while in org-journal

Trying to get org-journal working, but it wants to auto-complete nearly every word I type, then require two space bar hits to advance to type next word. I tried this and it works (add-hook 'org-mode-...
0
votes
2answers
57 views

Org-mode hook following creation of a new <<<radio target>>>

I want to call org-update-radio-target-regexp as soon as org-mode recognises that a new <<<radio target>>> has been created (which seems to happen as soon as the third ">&...
0
votes
0answers
14 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 ...
4
votes
1answer
97 views

How do I focus the Man mode window when it is displayed?

When I open a man page (e.g. M-x man cat) I would like to automatically move my cursor onto the man page. I already know how to achieve this behavior for *Help* and *Apropos*, and I want to get the ...
0
votes
2answers
66 views

How do I move the cursor to the *Warnings* buffer whenever there is a new warning?

I want to focus the *Warnings* buffer whenever there is new warning. I tried this: (add-hook 'special-mode-hook (lambda () (when (string= (buffer-name (current-buffer)) ...
0
votes
0answers
23 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 () (...
1
vote
0answers
125 views

Hook for rainbow-delimiters doesn't work

I use the following to setup rainbow-delimiters. (use-package rainbow-delimiters :hook (prog-mode . rainbow-delimiters-mode)) When open a clojure file, the rainbow-delimiters-mode is not enabled. ...
0
votes
1answer
66 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
1answer
44 views

Auctex hook causes an error when set with use-package :hook versus add-hook?

According to the use-package documentation these two are the same: (use-package ace-jump-mode :hook (prog-mode . ace-jump-mode)) (use-package ace-jump-mode :commands ace-jump-mode :init (add-...
0
votes
0answers
106 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
1answer
80 views

Hook to run on completion of exporting org to html

I've defined a custom command with shell-interpreter to rsync files to my VPS... (defun rsync_html () (interactive) (with-shell-interpreter :path "~/org" :interpreter "bash&...
0
votes
1answer
37 views

Running code after org-deadline

I want to run code after adding a deadline, for example to move it forward by one day in case the deadline is early in the day, or by a few hours in case it's on a different time zone. This attempt ...
0
votes
0answers
43 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
46 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-...
1
vote
0answers
34 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 ...
0
votes
1answer
28 views

I need a key binding of: "M-x compile" then in Compile commant type the "Compile command: love2d /home/huseyin/Documents/Programming/Lua/"

I need a key binding of: M-x compile then in compile command type like Compile command: love2d /home/huseyin/Documents/Programming/Lua/ I am tired of doing that again and again.
1
vote
1answer
153 views

start emacs with org-agenda-list AND todo items

Is there any way to start emacs with both weekly agenda and todo list at startup? Similar to Doom Emacs shortcut <SPACE> - o - a - a - n (Agenda and all TODO's). I can't seem to find a way to do ...

1
2 3 4 5
7