Yasnippet has a nice "run ... after exiting a snippet".
What I would like to do is include some visual effect after each ending snippet (changing background color for, say a second, or more sophisticated stuff).
I did this by switching background colors back and forth in that hook, but it's really short and not efficient, and also ugly.
However, how can this, or something similar be done with a timer?
Optional: Suggestions for fancy effects (including a timer) are welcome.
You can change the background once and then change it again 1 second later by using run-with-timer:
(run-with-timer 1 nil 'my-fun)
where my-fun does the action you want.
My first thought would be to make Emacs "beep". I actually hate that sound, so I have it flash the frame instead.
(setq visible-bell t)
(add-hook 'yas-whatever-hook (lambda () (beep t)))
Related
I'm an Emacs user with no skills with regards to configuring the editor. After I upgraded from haskell-mode 2.4 to 2.7, I've noticed two changes:
Indentation is different somehow, in a way I don't quite like. I can't quite put my finger on what it is.
More importantly: If I have cua-mode enabled and highlight a block of text, backspace/delete does not delete the entire block, just the previous/next character from my marker.
I see that haskell-mode 2.7 uses the minor mode haskell-indentation-mode by default, while 2.4's behaviour has been preserved in the form of haskell-indent-mode. If I first turn off the former, and then on the latter, the behaviour I want is restored (i.e. indentation feels like before, and backspace/delete deletes highlighted blocks).
I can't, however, get this to happen automatically whenever I open a file with a .hs suffix. I've tried various things resembling
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent-mode)
and the likes of it, but I either end up with the standard mode or with plain haskell-mode without indent and doc.
Any ideas?
Solution (thanks to nominolo):
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indent)
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
)
The best way to configure such things is by writing a custom hook:
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
;; further customisations go here. For example:
(setq locale-coding-system 'utf-8 )
(flyspell-prog-mode) ;; spell-checking in comments and strings
;; etc.
)
You could also stick an anonymous function in there, but having a named function is easier if you want to experiment with some settings. Just redefining the function (and re-opening a Haskell file) will give you the new behaviour.
I use (global-hl-line-mode) to enable hl-line-mode, But i want to use
it in certain mode like cc-mode, so i add this line to mode-hook,
(setq hl-line-mode t), it doesn't work, i enable hl-line-mode use
M-x, it shows disabled, which means at first, it's really enabled, but
i can't see any highlight.
Same problem occurs to linum-mode, maybe there are others.
Anyone knows what's wrong with it?
Thanks.
In general, it's a good idea to turn the mode on through the function call, rather than just setting the variable. The function call will set the variable for you, and likely do some other work.
Try this:
(add-hook 'c-mode-common-hook
(lambda () (hl-line-mode 1)
(linum-mode 1)))
When I go abroad text or even under any conditions in Emacs works system speaker. How can i turn of it.
I try to write system-bell off in /etc/inputrc but it isn't help
Thank you
I have the following in my .emacs:
(setq ring-bell-function (lambda () ))
That turns off all beeps. I hate beeps of any sort so this works for me, but if you only want to turn off some types of beeps, there are ways to do that too. For example, if you would like to make all the beeps into a visible flash on the screen, you can use:
(setq visible-bell t)
instead of setting the ring-bell-function. Also, check out this similar question.
Or execute
xset b off
in a terminal.
My .emacs file is here. I want the theme to change when I am in shell-mode. But what happens is that the theme gets applied to all the windows. I set the variable color-theme-is-global to nil, but the problem still persists.
(add-hook 'shell-mode-hook 'color-theme-monokai-terminal)
(set-variable 'color-theme-is-global nil)
These are the corresponding lines in my .emacs file. What should I do to make it work?
I usually start Emacs as a daemon and then open frames as needed. I use different color themes for X frames and terminal frames like so:
(require 'color-theme)
(color-theme-initialize)
(defun apply-color-theme (frame)
"Apply color theme to a frame based on whether its a 'real'
window or a console window."
(select-frame frame)
(if (window-system frame)
(color-theme-tango)
(color-theme-tango-black)))
(setq color-theme-is-global nil)
(add-hook 'after-make-frame-functions 'apply-color-theme)
You can replace the (if window-system ...) part with your check for shell-script-mode and the color-theme-X parts with your favorite themes.
There is one downside to this: if you don't start Emacs as a deamon, the customization will only kick in after you create a second frame, the first one that pops up will have the standard theme.
I think your terminology is off: in emacs-speak frame means what people normally mean by window in a graphical environment. (That is, the thing that has the close, minimize and maximize buttons and a titlebar, etc, is the "frame".) Whereas the things that show up when you do a C-x 3 (split-window) are called windows, and when you do something like M-x shell-mode you get a new buffer, which may or may not be in a new window.
Color themes are always frame-global (as far as I know, and it's certainly what the documentation suggests) the variable color-theme-is-global determines whether a single theme propagates across frames.
I'm thinking that the closest thing to what you want is something like (completely untested, probably broken):
(defun shell-mode-in-new-frame ()
(interactive)
(select-frame (make-frame))
(color-theme-monokai-terminal)
(shell-mode))
Although this does create a new frame, which isn't what you want.
I am doing small modification to SLIME, so that I can get all currently loaded symbols from Lisp, analyze them and make font-lock fontify them.
I managed to do all these steps, but I have a small problem - when keyword list changes in font-lock the buffer is not updated unless you restart the major lisp-mode. I don't want to restart lisp-mode every time I update keywords, because I have several hooks on lisp-mode that I want to run only when I load the file for the first time.
Is there an other way to update font-lock so it reads all then new keywords and fontifies the buffer accordingly? Switching off font-lock and using font-lock-fontify-buffer does not do the trick.
UPD: Added bounty - the question is still up. I need a way to reload font-lock keyword without reloading major mode.
Ok, how about this instead:
(defun my-font-lock-restart ()
(interactive)
(setq font-lock-mode-major-mode nil)
(font-lock-fontify-buffer))
You could temporarily clear the mode hook variable and restart it:
(defun my-restart-lisp-mode ()
(interactive)
(let ((lisp-mode-hook nil))
(normal-mode)))
Triggering the major-mode is not what makes font-lock do its thing. I am not intimately familiar with the internals of SLIME or lisp-mode, but just setting the variable should make it work. Toggling font-lock-mode will make font-lock start refontifying with the new keywords in mind, as should font-lock-fontify-buffer.
I hack on cperl-mode, mostly, and it is a simple matter of cperl-init-faces (which sets the internal font-lock variables) and a restart of font-lock. lisp-mode should not be much different, except for not needing a call to cperl-init-faces ;)
Edit: some experimentation with lisp-interaction-mode reveals that even restarting font-lock-mode is not strictly necessary. Just changing font-lock-keywords is enough, as long as you re-trigger fontification somehow. (Editing text, font-lock-fontify-buffer, etc.)