A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

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
1
vote
1answer
199 views

How automatically load a mode with another mode (web-mode with zencoding-mode)?

I have web-mode (which is awesome, by the way). The following line: (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode)) every time when a .html file is loaded, web-mode will be enabled. But ...
0
votes
0answers
91 views

Finding proper hook for a major mode

So this is some elisp code I have in my init.el file: (defun complete-dollar () (interactive) (insert "$$") (backward-char 1)) (defun my-latex-keys () "Modify keymaps by latex-mode" (...
0
votes
1answer
124 views

Tie a minor-mode to a particular major mode

I'm writing an extension to a major mode (coq-mode) that adds extra features, plus a few keybindings. To makes it easy to disable or redefine these keybindings, I packaged them in a keymap. That ...
4
votes
1answer
306 views

How to approximate pre-self-insert-hook (which doesn't exist)?

Q: how does one approximate the functionality of the non-existent pre-self-insert-hook? This question is inspired by the curiosity that is the combination of abbrev-mode and self-insert-command. The ...
1
vote
2answers
318 views

Smart minor mode toggle depending on major mode

I use several minor modes, which are enabled globally by default: whitespace-mode linum-mode fci-mode I'm finding them very helpful when editing code sources and text files, however I does not want ...
5
votes
1answer
679 views

Run hook on new buffer

I am trying to create something like uniquely, which renames the buffer to the full path within the projectile project. I have the code working, however, I can't seem to figure out how to get it to ...
5
votes
1answer
561 views

How to deal with 'add-hook' in .emacs when it's reloaded more than once?

I have some add-hook functions in my .emacs similar to below, Send a notification when a pomodoro is completed: (add-hook 'org-pomodoro-finished-hook (lambda () (message "Pomodoro finished") ...
1
vote
1answer
118 views

Why is cperl-mode-hook running twice?

I am using cperl-mode to edit Perl scripts. According to the Emacs wiki ( link ) one could use defalias to use cperl-mode instead of perl-mode. Here is an example: $ emacs -Q -l init.el test.pl & ...
2
votes
1answer
88 views

How to access the original buffer when running M-x compile and friends?

For example, take any buffer. Maybe one named my-file. I want to run M-x compile in it and have access to the my-file buffer in compilation-finish-functions. You'd think think might work: (setq ...
2
votes
0answers
319 views

How to make ansi-term output read only?

When using ansi-term in line mode emacs lets you edit the buffer arbitrarily, not just after the last prompt. I'm trying to make it read only so I stop fudging with command output. The problem is all ...
8
votes
2answers
1k views

Disable hl-line-mode only for eshell and ansi-term

I have global-hl-line-mode setup in my init file: (use-package hl-line :init (global-hl-line-mode 1)) Is it possible to disable it when I am in eshell and ansi-term? I tried adding a hook like ...
2
votes
0answers
212 views

Expand LOGBOOK on 2nd Tab press? (hook for 2nd org-cycle?)

In org-mode.. I store lots of state-change messages and timing info in the LOGBOOK drawer. Most of the time, I don't look into the LOGBOOK drawer, but once in a while when following up on a pending ...
2
votes
2answers
284 views

Persist hideshow folds between sessions?

I use hideshow (hs-mode) in almost all languages. Most of the time, i keep function header lines visible but the body hidden like this, function func(arg1, arg2){...} So, every time I open the file, ...
5
votes
2answers
322 views

Using different theme on tramp buffers (and buffer-related themes in general)?

Is it possible to configure emacs so it uses different theme for tramp buffers than for defaults? Say, I use twilight by default, but while editing sth via ssh I'd like to switch to pastels-on-dark... ...
3
votes
1answer
705 views

Set variables based on path without using directory-local variables

I want to set variables, in particular, compile-command and tabbing related variables based on the path of the file I'm editing. In my .vimrc I use the following to do this. autocmd BufRead,...
4
votes
2answers
719 views

Does autoload load all functions in the file or just the one specified?

I have developed some private extensions to some major modes, and I would like to load those extensions only when the given major mode is actually used by the user. The extensions consists of a set of ...
1
vote
1answer
32 views

Signal a buffer was evaluated in an inferior process?

I am aware that this is a bit of training wheels, and that I should just trust Emacs and my keystrokes. But I think part of it is just that there's a context switch involved and I have too long of ...
3
votes
2answers
452 views

How to remove individual sources from auto-complete's ac-sources in a specific major-mode

auto-complete automatically adds a number of sources to ac-sources: (ac-source-features ac-source-functions ac-source-variables ac-source-symbols) And I set up auto-complete default ac-sources like ...
1
vote
1answer
534 views

“Marker does not point anywhere” error when using (message)

I'm running into the error "Marker does not point anywhere" when I try to print a message both in after-change-functions and buffer-list-update-hook. Curiously if only one hook or the other is active ...
1
vote
1answer
576 views

doc-view-mode-hook?

Whenever I open a pdf in emacs, I'd like to increase the font size. I thought I would just place (doc-view-enlarge) in a 'doc-view-mode-hook. However, I can't find such a hook. Yet this source ...
3
votes
1answer
1k views

latex-mode-hook or LaTeX-mode-hook?

When I did some clean up of my Emacs init file, I discovered that I had used both (add-hook 'LaTeX-mode-hook ...) and (add-hook 'latex-mode-hook ...) What is the difference between LaTeX-mode-...
1
vote
1answer
105 views

Why don't insert-in-front-hooks run?

Open a scratch buffer, paste the following an evaluate it: (insert (propertize "hello" 'insert-in-front-hooks (list (lambda (&rest unused) (message "test"))))) Typing ...
5
votes
3answers
639 views

Turn a non prog-mode derived major-mode into a prog-mode derived major-mode

erlang-mode is not a derived prog-mode. Is there any way to make it part of the prog-mode-hook ?
3
votes
3answers
501 views

Rename scratch buffer and ask confirmation to kill non-file buffers created by user

I tend to use often non-file buffers kinda like post-it-notes and it is way too easy to kill them inadvertently, as there is no confirmation to kill. Even if you enforce the habit of writing only in ...
0
votes
1answer
135 views

Setting fill-column for reStructuredText mode

I can't set fill-column in reStructuredText mode hook: (add-hook 'rst-mode-hook (lambda() (setq auto-fill-mode 1) (set-fill-column 60))) While the auto-fill-mode works, the default ...
0
votes
1answer
556 views

post-command-hook and prefix argument

I have a non-interactive function F to do post processing after each command. F is buffer locally hooked to post-command-hook. Whenever F is hooked the prefix argument is eaten and the next command ...
1
vote
1answer
138 views

Simulating before-minibuffer-hook

I need a function to execute before the minibuffer is entered, not after (minibuffer-setup-hook style). Is there any way I can achieve this effect with advice or other emacs systems? I would like to ...
6
votes
2answers
206 views

Programmatically controlling the order of functions within a hook

I am looking for an example, please, to programmatically control the order of functions within a particular hook: First in time, which is easy -- i.e., don't append using add-hook. Last in time, ...
12
votes
3answers
4k views

before-save-hook for cc-mode

I want to customize cc-mode to execute a function before saving. One solution would be to modify cc-mode keymap to bind C-x C-s to a function which performs the work I need and then saves it. My ...
24
votes
3answers
6k views

Proper way to enable minor mode

I have foo-mode and would enable bar-minor-mode for it. So which way is more common and preferable? A (add-hook 'foo-mode-hook 'bar-minor-mode) B (add-hook 'foo-mode-hook (lambda () ...
8
votes
1answer
685 views

How to hook into buffer modified state?

Such as in the built-in variable mode-line-modified which displays an asterisk in the mode line if the buffer is modified. Specifically, I want to turn hl-line-mode off when the buffer is modified ...
12
votes
1answer
3k views

Execute external script upon save when in a certain mode?

When I'm in org-mode, I want Emacs to execute a bash script I wrote whenever I hit C-x s to save. The script automatically syncs the file I am saving to my Raspberry Pi. It expects the file name as ...
0
votes
1answer
80 views

How can I use two hooks with overlapping usecases?

I'm in the process of writing an Emacs package that helps you controlling popup windows and have hit a minor roadblock while developing a new feature for it. Currently I'm using window-configuration-...
18
votes
2answers
1k views

Is there fully-automatic fill-paragraph-mode for code comments?

I'm looking for a minor mode to keep paragraphs filled at all times while typing (similar to what aggressive-indent-mode does for indentation). It also needs to be smart enough to only fill comments (...
3
votes
2answers
477 views

Emacs flickering when using before-save-hook with gofmt

I am trying to use gofmt on my go before I save it. ; Run gofmt before save (setq gofmt-command "goimports") (setq exec-path (cons "/usr/lib/go/bin" exec-path)) (add-to-list 'exec-path "/home/...
9
votes
5answers
1k views

How to enter view-only mode when browsing Emacs source code from help?

When I browse Emacs help for functions via C-h f, I often want to peek into the Elisp/C implementation. I want to enter view-mode automatically when I access source code this way to avoid unnecessary ...
2
votes
1answer
895 views

Get irony-mode to automatically load .config_clang

So irony-mode scans include directories through a file called .clang_complete, which looks like something like: -I./include/ However, it does not automatically load this file. Rather, I have to go ...
5
votes
2answers
192 views

How to ensure lines are always displayed in groups of 3?

I am writing a major-mode which displays a list to the user. It is similar to tabulated-list-mode, except each entry takes up 3 lines, as opposed to just one: 0 0 Ctrl-} key in emacs 5m ...
1
vote
2answers
103 views

Why is `gnus-group-prepared-hook` never called?

I'm wondering why this hook never works: (add-hook 'gnus-group-prepared-hook 'gnus-group-list-all-groups) Description of the hook: is called as the very last thing after the group buffer has been ...
3
votes
1answer
235 views

`find-file-hook` problem for large buffer that is just one long line

I got a file(for instance, ~/.mozilla/firefox/xxx.default/sessionstore-backups/recovery.bak) that its content is one whole line and size of over 1MB, if I open it in Emacs, Emacs will become very ...
14
votes
3answers
2k views

Is there any way to run a hook function only once?

The context I'm using the after-make-frame-functions hook to load properly the themes in an emacs client/server configuration. Specifically this is the code snippet that I use to make that (based in ...
0
votes
1answer
80 views

How does autoload cookie work on non defun form

sometimes I see a "unkosher" use of autoload coookie, for example: ;;;###autoload (add-hook 'some-hook 'some-fun) How will the above work? Will it add a hook just by being installed (as autoloads ...
6
votes
3answers
540 views

Focus-hook: attenuate colours when losing focus

How can I use the focus hooks to attenuate all colours in visible buffers when the Emacs frame loses focus? I tried using the following code: (set-frame-parameter (selected-frame) 'alpha '(100 80)) ...
13
votes
2answers
973 views

Where should I include a lazy initialization?

I want to add a specific key binding to latex-mode: (define-key latex-mode-map (kbd "<f6>") 'my-latex-defun) At the same time I want to set it only when the specific mode is loaded. So I ...
5
votes
1answer
670 views

What is the difference between setq-mode-local and setq-local

I don't understand how setq-mode-local works (mode-local is a package from cedet). The macro's documentation says: setq-mode-local is a Lisp macro in `mode-local.el'. (setq-mode-local MODE &...
7
votes
2answers
723 views

Hook that indicates when the cursor has been moved by scrolling

Inspired by this question: Let Emacs move the cursor off-screen, I am considering writing a minor mode that will keep the cursor in a fixed position that is not affected by scrolling operations. I ...
3
votes
3answers
557 views

Debug why a function is removed from post-command-hook

I am trying to implement the auto-indentation snippet posted by @Malabarba in one of the emacs SE questions. From that post, below is the function that I am trying to add to the post-command-hook: (...
5
votes
2answers
255 views

Detect when a key is rebound to another command

First, some context: I am in the process of debugging a strange interaction between smartparens and Org Speed Keys: After editing an .org file for a while, specific speed keys for navigating the ...
4
votes
2answers
603 views

Turn off jabber notifications when Emacs has focus

I use jabber.el to communicate with people at work, and I have sound notifications setup so that I get notified even when I’m not using Emacs. The notification is setup in the following way. (add-...
14
votes
2answers
469 views

How to find out what a key sequence really does

From time to time I observe unexpected behavior when editing text. My first recourse is usually to use C-h k to find out what functions are being called by a given key sequence. However, sometimes ...