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
0answers
18 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 ...
1
vote
1answer
47 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
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.
1
vote
0answers
22 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
47 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
50 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
17 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
41 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
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
1answer
17 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 ...
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 ...
0
votes
1answer
42 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
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 ...
0
votes
1answer
43 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
32 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
41 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
56 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
47 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
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 ...
3
votes
1answer
69 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
60 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
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
1answer
31 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
88 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
56 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
36 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
30 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-...
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 ...
0
votes
1answer
27 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.
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 ...
1
vote
1answer
117 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 ...
0
votes
1answer
49 views

org-mode-hook is always evaluated

I'd like org-mode to use a particular theme. To this end, I've put the following in my init.el: ;; Setup org-mode theme (defun org_setup() "Setup org-mode" (load-theme 'doom-laserwave) ...
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
1answer
27 views

How do i implement my own hooks in elisp?

What code do i need to implement in order to create a hook which can be set by the user and which is called in my own function?
4
votes
1answer
246 views

How to replace focus-out-hook with after-focus-change-function in emacs 27?

In my old emacs, I have defined the following code. (add-hook 'focus-out-hook (lambda () (save-some-buffers t))) After upgrade to emacs 27, it said focus-out-hook is obsoleted, and the new one is ...
1
vote
1answer
43 views

How to setup ediff to open a new frame with the two comparison buffers

When I issue M-x ediff-buffersI'd like ediff to create a new frame with the two buffers (and close this frame when done with the comparison). How can I customise ediff to do so? I tried (defun leo-...
0
votes
0answers
80 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 ...
2
votes
1answer
235 views

Disable Prettify-Symbols for C-mode

I'm using doom emacs. It enables prettify-symbols in all modes (I think) by default, although I would like to disable it in c-mode. I have placed the following in my config.el file: (add-hook 'c-mode-...
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 ...
1
vote
0answers
102 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
1answer
222 views

Adding a lambda function as hook in use-package

I'm trying to adapt this answer to use-package elegantly. It requires that I hook a lambda function to python-mode. I came up with this solution — which works: (use-package python :hook (python-...
1
vote
2answers
56 views

How to find hook running after last line of code?

I have a repeating habit such as: ** TODO some habit SCHEDULED: <2020-05-22 Fri 08:00 .+1d> :PROPERTIES: :STYLE: habit :CREATED: [2020-05-08 Fri] :LAST_REPEAT: [2020-05-21 Thu 10:07] :END: :...
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. ...

1
2 3 4 5
7