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
7
votes
1answer
938 views

Is there a universal 'after-theme-load' hook?

I would like to set several face variables for use with any theme in my personal init-file. Is there a hook I could use to insure it is theme independent?
0
votes
1answer
1k views

Changing mode-line face when evil state changes

I'm trying to change the mode-line face box attribute to be the same color as the evil emacs state face, obviously updating it each time the mode changes. I've seen some things about using a post-...
5
votes
1answer
426 views

Is there a way to detect change of monitor in Emacs / Elisp?

tl;dr I'm looking for way to detect when an Emacs frame has been moved from one monitor to another in a multi-monitor setup. I have code in my ~/.emacs which sets the default font size for all ...
0
votes
1answer
289 views

Hippie doesn't use yasnippet and fallback to emmet with emacs-lisp-mode

I use hippie-expand with emmet and yasnippet. (use-package emmet-mode :init (add-hook 'css-mode-hook 'emmet-mode) (add-hook 'sgml-mode-hook 'emmet-mode) :config (unbind-key "<C-return>" ...
0
votes
0answers
197 views

Recommendations for eval on save workflow for projects?

I've started to write a package and excessive use of the interactive eval-* functions has become a pain point for me. After I make a change re-evaluating entire file or package is almost always ...
3
votes
2answers
567 views

save a particular buffer without prompting on emacs exit?

I have a particular buffer that collects statistics from my emacs sessions. I could write the buffer every time I update the statistics, but that's not efficient. I want to auto-write the buffer ...
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?...
1
vote
1answer
280 views

bookmark on kill-buffer-hook

I'm using pdftools when displaying pdfs and it would be nice if emacs could bookmark the pdf with the default filename when I kill that buffer. I've got something like this, but it doesn't work. ;; ...
1
vote
1answer
74 views

how to recover from error in focus-in-hook

I registered a focus-in-hook that generates an error. Now any time I try to execute a command in the minibuffer I get an error and am then unable to execute the load-file that would be required to ...
1
vote
1answer
408 views

run-python does not work if added to python-mode-hook

I would like the Python inferior process to start (if it is not already running) whenever I create a python-mode buffer (for example, by visiting a .py file). Some functions in anaconda-mode etc. ...
0
votes
1answer
747 views

Enable visual-fill-column-mode only in text and programming mode

I am currently using visual-fill-column-mode and visual-line-mode in emacs with the following: (add-hook 'visual-line-mode-hook 'visual-fill-column-mode) (global-visual-line-mode t) (define-key ...
7
votes
2answers
712 views

Prevent folding org files opened by ediff

Folding gets in the way when merging two org files using ediff, so I'm trying to disable all folding in org-mode buffers created by ediff. Non-ediff folding behavior should remain unaffected. ...
7
votes
1answer
252 views

How to abort saving in a before-save-hook function?

If, in a function run from before-save-hook, I want to abort the saving of a file, so that the file is not saved and the user is signaled, how can I do that? Is it possible (without rebinding C-xC-s ...
5
votes
3answers
860 views

Call a function before a specific major mode starts

I have a setup function that I want to run before I use pdb/gud to debug a Python script. I know about gud-mode-hook which runs after the debugger starts (too late) and change-major-mode-hook which, ...
4
votes
1answer
732 views

Is there a hook I can use to run my function when point moves?

I'd like to add some navigation context to the modeline. I can figure out where I am just fine and give the name of my function, but I don't know how to run this every time point moves. post-command-...
1
vote
3answers
176 views

emacs philosophy: add dwim behavior when pressing Enter

I recently added a modification to my Enter keybinding based on an answer (if you can't see it, this is a link) on this SE. It was good and I liked it. So of course... Now I want to add MORE dwim ...
0
votes
1answer
402 views

Force elpy to work only with .py extension files [closed]

Elpy works in every buffer automaticly, however I wan it to work only with python files. The related section of my init.el is: (require 'elpy) (elpy-use-ipython) (setq-default indent-tabs-mode nil) (...
1
vote
1answer
222 views

Calling function from hook not working as expected

I am trying to add a hook which calls shr-render-buffer after loading a file in html-mode. This is what I came up with: (add-hook 'html-mode-hook (lambda () (call-interactively #'shr-render-buffer))) ...
6
votes
1answer
2k views

List hooks that will run after command

Is there a way to lookup which hooks will run when a given command is called? For example, for major modes it is pretty easy to guess that activating python-mode will run python-mode-hook. But ...
1
vote
1answer
82 views

failed compile command runs on exit, prevents exit – how to track down?

I'm on a new system (Amazon Linux 2015.9), and my emacs config seems to not like the stock install (Emacs 24.3.1) or vice-versa. When I do C-x C-c it runs save-buffers-kill-terminal. But this fails, ...
2
votes
2answers
430 views

Emacs Equivalent of Vims's Auto Commands?

I'm currently trying to move from vim to emacs so be gentle with me ;) In Vim, one of my favorite features is auto commands, I'll have one for each project for example: au BufEnter c:/projects/foo/* ...
0
votes
1answer
159 views

Prevent emacs mode from defining keybindings

I am trying to extend evil-like conventions to comint mode so I can use vim-like keybindings from the shell. I also rebound C-c to #'evil-normal-state since that is what I use in vim (it isn't ...
6
votes
3answers
907 views

how to unbind a mode hook without restarting

I had set up a custom hook for a mode, but I now realize that I want to use the mode without my changes and without my hook. So, I want the mode to behave as if I never set the hook in the first place,...
3
votes
1answer
224 views

what is info-mode-hook

I am trying to rebind some keys for info-mode without success. I am not sure whether I am missing something, or whether a special hook is required. I am using the following hook in my init.el: (add-...
3
votes
1answer
182 views

How to prevent whitespace cleanup at point?

I have hooked whitespace-cleanup to before-save-hook and there is a timer to auto save buffer every 5 seconds. When i am typing something, or coding in python, I stop once in a while and buffer ...
1
vote
1answer
40 views

Does something like a auto-function-list exist?

I had the following hook: (add-hook 'image-mode-hook 'imagex-sticky-maximize) imagex-sticky-maximize is a function that maximizes the image to the borders of the window. I prefer to see my images to ...
2
votes
2answers
3k views

How to disable global Linum mode for certain mode?

in my init.el file I have the following: (global-linum-mode 1) (add-hook 'term-mode-hook (lambda () (linum-mode))) However, when I enter ansi-term-mode linum mode is still on. I have also tried (...
3
votes
2answers
128 views

in org-mode, how to move point to next checkbox when it's marked completed?

I work with org-mode checkboxes, marking them as completed as I go. * TODO clean kitchen - [X] sink - [ ] stove - [ ] floors I want org to move point to the next checkbox when when it gets marked - ...
2
votes
1answer
640 views

in org-mode, how to move point to next TODO heading upon DONE state change?

I work with org-mode TODO lists not in org-agenda mode, but within the actual .org files, marking TODO headings DONE as I go. * DONE buy milk * TODO fix car * STARTED call mom I want org to move ...
1
vote
2answers
32 views

When opening “/tmp/foo.html”, don't prompt for Document Title

If I do "ctrl-x ctrl-f /tmp/foo.html" (where /tmp/foo.html doesn't exist), emacs prompts me for "Document Title:" How do I turn off this behavior (which I'm guessing is an html-mode hook of some sort)...
0
votes
1answer
64 views

Why do my js2-mode hooks work on Mac but not Fedora Linux?

I am getting very inconsistent behavior with js-mode and js2-mode hooks and I am not sure why. I have three "hooks": (add-hook 'js2-mode-hook (lambda () (setq mode-name "Zono-mode"))) (add-hook '...
0
votes
3answers
473 views

Why is this function not working properly, when added to a hook?

Situation I would like to have a function, that when called, creates a new file/buffer in a specific directory, indepent of the current directory. But with the same file name as the current file that ...
0
votes
1answer
297 views

How do I enable a mode, when another mode runs?

All I want to do is enable tern-mode, when I enter js-mode. I know that a hook called js-mode is run when I open a javascript file but for some reason tern-mode is not enabled. In my init.el file I ...
8
votes
1answer
160 views

Quitting Emacs and re-enabeling touchpad

I have the below elisp code in my emacs config which disables my touchpad, so it won't annoy me when writing. ;; disable touchpad when on emacs (defun turn-off-mouse (&optional frame) (...
5
votes
4answers
292 views

Is there a standard function that applies a list of predicates to a value until success?

I look for compacting expression like: (let ( (val (complex-expr ...)) ) (or (pred1 val) (pred2 val) ...(predN val))) Instead I like something: (apply-some (complex-expr ...) '(pred1 pred2 ... ...
3
votes
2answers
487 views

Emacs server init when called without file

Whenever I use emacsclient, I tend to use it without a file argument. This is because my emacs file finder is generally better than my shell file finder. Unfortunately, when emacsclient is not given ...
2
votes
1answer
179 views

Buffer-local hook shadowing default value for subsequently loaded libraries

After having a problem with debugging a package I write, I finally tracked down the problem to the following: auto-revert-mode is making kill-buffer-hook buffer-local (which is fine by me). The ...
5
votes
1answer
898 views

How to rebuild agenda buffers when saving an org-mode buffer?

When composing my weekly schedule, it feels somewhat jarring to have to switch to the agenda buffer in the other frame and rebuild, just to see how things align. Adding org-agenda-redo to after-save-...
1
vote
2answers
112 views

Recenter buffer when clickable text is clicked?

TASK 1: If I run C-h f goto-line(or any other function) it will open help buffer with clickable text like this. If I click this text, it will open that file in a new buffer and it will take to that ...
8
votes
1answer
1k views

What is a hook?

Just to clarify... For example, in this doc: A hook is a Lisp variable which holds a list of functions, to be called on some well-defined occasion. (This is called running the hook.) The ...
2
votes
2answers
268 views

Highlighting automatically on file open

I would like to highlight lines with a certain pattern whenever the file is opened. Specifically when Journal.org is opened I want to run commands like M-s h l to highlight a set of patterns and ...
8
votes
2answers
993 views

How to activate semantic-mode for specific major modes only?

I've seen this question a lot. But none of the replies fixed my issue: the minor mode stays on in others modes. So far, I have tried: (use-package stickyfunc-enhance :config ;; (add-to-list '...
1
vote
2answers
2k views

Add hook for specific files

I am looking to create some customized settings for a specific file. I think I want to add a hook for that file, or something that will create a few settings when that file loads. For example, I have ...
1
vote
1answer
324 views

json-mode hook not being run

I have (add-hook 'json-mode 'flymake-json-load) in my .emacs file, but it has no effect. I have to do M-x flymake-json-load whenever I visit a .json file. Why doesn't it work?
3
votes
2answers
240 views

find-file-hook but only if file is selected

This is pretty simple, I'm trying to find (or build) a hook that fires when files are visited and selected (i.e. immediately displayed). Background I'm writing a UI centric entry for find-file-hook, ...
10
votes
1answer
4k views

What's the difference between after-init-hook and emacs-startup-hook

Seems there are several hooks about actions on Emacs initialization. However I'm not sure what their differences are, and a brief Googling yields little information. Is it like emacs-startup-hook is ...
6
votes
2answers
6k views

How to run an `after-save-hook` only when the buffer has been saved manually

This question is inspired by https://emacs.stackexchange.com/a/5947/. Assume that I have a function like (defun do-some-actions () () (..put a copy of the current file in a specific folder...) ) ...
17
votes
1answer
6k views

Remove hooks for specific modes

I want to delete trailing whitespace on save for every mode except org-mode. In my .emacs, I have the following line: (add-hook 'before-save-hook 'delete-trailing-whitespace) I use the use-package ...
4
votes
1answer
111 views

Hook that fires when `*Messages*` is updated

Emacs manual §31.28 says this about before-change-functions and after-change-functions: These hook variables let you arrange to take notice of all changes in all buffers (or in a particular buffer, ...
5
votes
1answer
1k views

Run code right after compilation

As I understand, Emacs doesn't really support multi-threading. Because of this I've chosen to run some operation (it can take a while) with compile function. This is asynchronous and all in all it ...

1
3 4
5
6 7