Is there a way I can turn on whitespace-mode in a minibuffer? I'm not sure I'll stick to it - but sometimes I need it. I tried to add-hook all the M-x apropos RET minibuffer hook RET:
(mapc
(lambda (language-mode-hook)
(add-hook language-mode-hook
(lambda () (interactive) (whitespace-mode 1))))
'(minibuffer-setup-hook
icicle-minibuffer-setup-hook
icomplete-minibuffer-setup-hook
ido-minibuffer-setup-hook
minibuffer-inactive-mode-hook))
but it doesn't work.
It looks like you've got something that should work, this worked for me:
(defun enable-ws-mode ()
(whitespace-mode 1))
(add-hook 'minibuffer-inactive-mode-hook 'enable-ws-mode)
as did the code you posted. Have you tried running Emacs without your initialization files?
emacs -q
emacs -q --no-site-init
and evaluating the code you had?
Perhaps this is only because it's been six years, but . . . with Emacs 26.3 I was able to add the regular whitespace mode command to the hook with no intermediating function:
(add-hook 'minibuffer-inactive-mode-hook 'whitespace-mode)
No fuss, no muss, works here.
Related
I have several abbrev defined that I was accessible everywhere except in latex mode. I defined
(setq-default abbrev-mode t)
(add-hook 'latex-mode-hook (lambda () (abbrev-mode -1)))
But whenever I open a latex file it still has abbrev mode enabled. What's going on?
Never worked with latex before, but for me the following works fine:
(setq auto-mode-alist (cons '("\\.lat\\'" . latex-mode) auto-mode-alist))
(setq-default abbrev-mode t)
(add-hook 'latex-mode-hook (lambda () (abbrev-mode -1)))
M-x abbrev-mode
%Abbrev mode enabled in current buffer
Please make sure the emacs recognized your file as a latex file, the first line I wrote should do the trick.
The reason was that AUCTex uses LaTeX-mode-hook. Thanks to stefan in the comment for pointing that out
I installed SML Mode in Emacs and the indentation is messed up. I disabled all my .emacs customizations, but that didn't make any difference. At the end of each line in the code below, I used C-j, which is mapped to newline-and-indent.
If I highlight everything and reindent (C-M-\), the result makes more sense:
I'm using Emacs 24.1.1 and SML Mode 6.2 on Ubuntu 12.10. What should I do?
Don't use newline-and-indent.
You can use reindent-then-new-and-indent or electric-indent-mode instead.
try in the .emacs file:
(setq default-tab-width 4);
(setq-default indent-tabs-mode nil);
(global-set-key (kbd "TAB") 'self-insert-command);
I'm no wizard but that worked for me.
http://www.pement.org/emacs_tabs.htm
Following up on Stefan's (now 4 year old...) suggestion, you can auto-enable the minor mode electric-indent-mode for sml-mode by putting this:
(push (lambda () electric-indent-local-mode 1) sml-mode-hook)
somewhere in your emacs initialization code.
Or, you might prefer:
(use-package sml-mode
:config
(push (lambda () electric-indent-local-mode 1) sml-mode-hook))
This seems to me to produce reasonably sane behavior for indenting code in sml-mode.
I've got an emacs configuration file whatever.el :
(abbrev-mode +1)
(provide 'whatever)
and in my init.el :
(require 'whatever)
but when i start emacs, abbrev-mode isn't enabled. why ?
thank you
Quoting from http://emacswiki.org/emacs/AbbrevMode:
You can also put the following in your ~/.emacs file if you want it
always on:
(setq default-abbrev-mode t)
If you only want it on in text and derived modes, you could do
something like this:
(add-hook 'text-mode-hook (lambda () (abbrev-mode 1)))
For multiple modes, use something like the following:
(dolist (hook '(erc-mode-hook
emacs-lisp-mode-hook
text-mode-hook))
(add-hook hook (lambda () (abbrev-mode 1))))
Abbrev-mode is enabled per-buffer.
One way is to create a hook function that you could add to the major mode hooks you will want to use it in.
For example:
(defun my-enable-abbrev-mode ()
(abbrev-mode 1))
(add-hook 'c-mode-hook 'my-enable-abbrev-hook)
(add-hook 'java-mode-hook 'my-enable-abbrev-hook)
Another approach is to use change-major-mode-hook.
While others explained how to get what you presumably want, I'll just point out that w.r.t to your actual question ("Why?"), the reason is simple: abbrev-mode is a buffer-local minor-mode, so when you run (abbrev-mode +1) at startup it will just enable abbrev-mode in the buffer that happens to be current during evaluation of the ~/.emacs (typically scratch) but not in subsequent buffers.
I want to enable line-wrapping without having to type 'M-x auto-fill-mode' everytime I start emacs. I've tried putting (setq auto-fill-mode 1) and (auto-fill-mode 1) in the .emacs file, but neither work. Why is this, and how do I fix it?
Thanks
It is a minor-mode so you need to enable it for the modes where you want it used. So, for example, if you want auto-fill-mode enabled in text mode, you need to add the following to your .emacs file:
(add-hook 'text-mode-hook '(lambda ()
(auto-fill-mode 1)))
auto-fill-mode is a minor mode so (setq auto-fill-mode 1) wont start it.
You can add a hook to start auto-fill-mode with the text-mode (with which it is normally used) or any other mode you normally use it with, by doing
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Alternatively, if you want the auto-fill-mode on for all the files you edit. You can start it when any type of file is opened with:
(setq auto-mode-alist (cons '("*" . auto-fill-mode) auto-mode-alist))
But having it always on is irritating at times, so its better to bind the starting of the mode to a familiar key sequence
(global-set-key (kbd "C-c q") 'auto-fill-mode)
When I open emacs, I would like to see the following:
2 windows, left window is for editing the document and the right windows run the program "multi-term"
I tried to edit my ~/.emacs with:
(add-hook 'emacs-startup-hook 'other-window)
(add-hook 'emacs-startup-hook 'multi-term)
(add-hook 'emacs-startup-hook 'split-window-horizontally)
the last two commands work, i.e I get 2 windows, one in left and one in right and the left one runs multi-term. (Althought I wanna the converse). But the command
(add-hook 'emacs-startup-hook 'other-window)
doesn't work. I get
wrong number of arguments: other-window, 0
Why? I think I can do everything if I type a correct function name, if this function really works if I type it in Emacs with M-x function_name.
How could I resolve this problem?
The command other-window takes an argument, which you're not providing. When you hit the keys C-x n, the argument is filled in for you automatically. Try:
(add-hook 'emacs-startup-hook (lambda () (other-window 1)))
Or, you could mimic the keystroke by doing:
(add-hook 'emacs-startup-hook (lambda () (call-interactively 'other-window)))