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
4
votes
1answer
453 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-...
0
votes
3answers
155 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
311 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
176 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
1k 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
74 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
282 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
140 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
672 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
157 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
138 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
39 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 (...
2
votes
2answers
102 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 - ...
1
vote
1answer
521 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
26 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
60 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
334 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
214 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
136 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
246 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
390 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
152 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 ...
1
vote
1answer
629 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
108 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
886 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
181 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
862 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
898 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
276 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?
2
votes
2answers
179 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, ...
9
votes
1answer
2k 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
4k 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...) ) ...
12
votes
1answer
4k 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
70 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, ...
3
votes
1answer
975 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 ...
0
votes
1answer
41 views

auto-unwiden ediff frame on quit

So in ediff I can press m to widen the frame but if I quit before pressing it again to restore to the original size, then the frame stays that size. I'd like to automate this so that if I forgot to ...
2
votes
1answer
311 views

How to chain after-change-hook functions?

I am trying to convert markdown to html and then use impatient-mode to display it live on browser on the fly. Impatient mode uses after-change-hook to detect changes in html. I am using after-change-...
3
votes
2answers
243 views

Executing a function when opening a file of certain type

I would like that when I open a file of certain type (say *.abc) certain function (say my-function) automatically executes at the opening. Edit. The function is a buffer-dependent function and should ...
7
votes
3answers
144 views

What's a good way to have a hook that runs for every file in a given directory?

What is a good way to assign a function to run when I open any file in a specified directory? Just like a hook but based on the location of a file rather than a major mode. It would be nice if I ...
5
votes
0answers
86 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:...
3
votes
0answers
1k 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
1answer
1k views

Use `.dir-locals.el' to append to `before-save-hook' as a buffer local variable

I want to use .dir-locals.el to append to the before-save-hook in a project for c++ files. Currently I'm using: (add-hook 'c++-mode-hook (lambda () (add-hook 'before-save-hook '...
14
votes
2answers
7k views

Run command when opening a file of a specific filetype

I'm trying to get a lisp script to run some commands for me when I open a file of a specific filetype. I know that I'm working in the correct init file because if I remove the theme from it, emacs has ...
1
vote
1answer
182 views

Is there a hook for a recursive minibuffer setup?

I have this code: (minibuffer-with-setup-hook #'ivy--minibuffer-setup (read-from-minibuffer ;; ... )) It works fine unless the code is called when already in the minibuffer. In that case ...
1
vote
2answers
981 views

mode hooks and eval-after-load

I am trying to set up some keybindings for working with scheme. I have these two mode hooks which contain the bindings I want: (add-hook 'scheme-mode-hook (lambda () (local-set-...
1
vote
1answer
796 views

How can I insert a link from one org file into another?

This is probably simple and I've been trying to develop some lisp skills but I'm completely stumped. What I'm trying to do is insert a link in one file every time a TODO state change occurs (probably ...
3
votes
2answers
520 views

Run a function after control returns to the command loop

Is there a hook that would run as soon as control returns to the user (i.e. to the command loop)? Context: I'd like to register a function to run as soon as all functions in the current sequence of ...
23
votes
1answer
1k views

What is the difference between ' and #' in front of a symbol?

I'm a little new to Emacs. When looking at some of the configurations, I found there are two types command in "add-hook". (add-hook 'LaTeX-mode-hook #'LaTeX-math-mode) and (add-hook 'LaTeX-mode-...
6
votes
3answers
115 views

`query-replace` leaves potential match to be replaced at bottom of window

If I have a long document that I run query-replace (or any other number of commands) in, as I'm saying y or n to replace that match or not, the current potential item to be replaced is always at the ...