This question already has an answer here:
How to enable a non-global minor mode by default, on emacs startup?
(1 answer)
Closed 8 years ago.
I use the minor mode writeroom which I have set to be global, but this setting only makes the mode global for all text-modes. I can specify more modes in the settings. But is there something I can write to enable this minor mode for all major modes?
Add a hook to find-file:
(add-hook 'find-file-hook #'writeroom-mode)
Substitute #'writeroom-mode with whatever function you want to run.
Related
This question already has answers here:
Globally override key binding in Emacs
(8 answers)
Closed 8 years ago.
Im trying make a new key binding, but i get conflicts with modes redefining this key.
After a good hour googling, what I think I want to do is:
(eval-after-load ANY_MODE
(define-key (current-global-map) (kbd "C-M-h") 'shrink-window-horizontally))
So is there a way to do this? Is there even anything like ANYMODE? Or is there another way?
In modern Emacs versions, all programming modes inherit from prog-mode, text-related modes from text-mode, and some of the others from special-mode. You can add a hook function (that sets (or unbinds) a local key) to prog-mode-hook, text-mode-hook, and special-mode-hook, that way it will be executed for most major modes. The remaining ones you could manage on a case-by-case basis.
You can use global minor mode for this purpose.
Minor mode setting has higher priority over global mode setting.
(define-minor-mode my-overriding-minor-mode
"Most superior minir mode"
t ;; default is enable
"" ;; Not display mode-line
`((,(kbd "C-M-h") . shrink-window-horizontally)))
I want to enable rainbow-mode everytime I start emacs, rather than having to use M-x rainbow-mode.
I guess there is some command I put in my .emacs file.
I tried all of the following, but none of them worked:
(require 'rainbow-mode)
(rainbow-mode initialize)
(global-rainbow-mode)
More generally, how do I load any mode/package automatically on startup?
rainbow-mode isn't a global minor mode, so it needs to be enabled on a per-buffer basis.
I only use it for CSS, so I have:
(add-hook 'css-mode-hook 'my-css-mode-hook)
(defun my-css-mode-hook ()
(rainbow-mode 1))
If you genuinely want it to be global, everywhere, you can easily define a global minor mode yourself:
(define-globalized-minor-mode my-global-rainbow-mode rainbow-mode
(lambda () (rainbow-mode 1)))
(my-global-rainbow-mode 1)
You can add any arbitrary logic to that (lambda () (rainbow-mode 1)) function (which will be evaluated in every buffer) in order to decide whether or not to actually call (rainbow-mode 1) for a given buffer, so if you're comfortable with elisp then you can easily extend this approach to cover your specific requirements for the mode in question.
More generally, how do I load any mode/package automatically on startup?
It can vary, but the approaches I've shown would suffice for most minor modes: Either you want them enabled whenever MODE is enabled (being some specific other mode name), in which case you can use the MODE-hook variable (which will always be available) as per the css-mode-hook example; or else you want the mode enabled permanently, in which case a global minor mode is a good approach (because you can toggle it on and off globally). Some minor modes are global by default (or provide global variants), but you can create your own if necessary, as per the my-global-rainbow-mode example.
Also be aware that modes can be derived from other modes, in which case all relevant MODE-hook hooks will be run (for details see https://stackoverflow.com/a/19295380/324105). A common use-case is to use prog-mode-hook to enable functionality wanted for all the programming modes which are derived from it (which is most programming modes).
Remember that many (hopefully most) libraries and packages will provide usage instructions. If you can't find documentation, be sure to try M-x find-library to visit the library file, and then read through the comments at the top. There is often a very informative "Commentary" section, and sometimes this is the primary source of end-user documentation, and explain how to enable its functionality.
This question already has answers here:
Emacs: check for no-window-system in .emacs
(2 answers)
Closed 8 years ago.
there are portions of my .emacs file that I would like to behave differently depending if emacs was opened in a terminal (ie, emacs -nw) or in a window. How does one go about detecting this?
In my FSF .emacs, I have code like this:
(if (null window-system)
(global-set-key "\C-h" 'delete-backward-char))
It looks like this works under XEmacs as well, though the preferred XEmacs way is to use the console-type function instead. Do M-x describe-function on console-type for details.
I've set up cedet/semantic code completion for my c++ projects (using this tutorial: http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html) but do not want the or all the helpers it (automagically it seems to me) offers in lisp mode.
So, my question is how to disable them in lisp-mode or have them enabled in c++-mode only.
Thanks,
Rene.
I think, that you need to slightly change config that is in the article - there are many global modes are used there, for example:
(global-srecode-minor-mode 1)
(global-semantic-mru-bookmark-mode 1)
etc. you can enable corresponding semantic-mru-bookmark-mode, srecode-minor-mode, etc. in the common C mode hook, like:
(defun my-c-mode-cedet-hook ()
(semantic-mru-bookmark-mode 1)
;; .....
)
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)
Or disable these modes for Lisp only... The other modes include semantic-auto-parse-mode, semantic-idle-summary-mode, semantic-idle-scheduler-mode - you can get this list using M-x apropos semantic.*mode
And the main thing here - you need to use semantic-load-enable-minimum-features in your config to enable minimal number of features by default, and enable other necessary features only in C/C++ mode hook...
I have a Emacs extension that creates a buffer named *erl-output*. This buffer gets created with only fundamental-mode by default. Is there any way to automatically enable compilation-minor-mode on that buffer?
To automatically change major modes you can add the following to your .emacs file:
(add-to-list 'auto-mode-alist '("^\\*erl-output\\*$" . my-major-mode))
This won't work for you; it's for major mode selection and you're after minor mode selection.
Instead you could try a Hook. The manual says:
A hook is a Lisp variable which holds a list of functions, to be called on some well-defined occasion.
So you should be able to write a function which sets the minor mode when required. Looking at the List of Standard Hooks I think you should be trying temp-buffer-setup-hook or temp-buffer-show-hook.
You'll have to write a function which checks the buffer name and sets the mode if required, and add it to the hook using something like the following in your .emacs:
(add-hook 'temp-buffer-setup-hook 'my-func-to-set-mode)
Since your extension is creating the buffer, why not just add:
(compilation-mode)
(or (compilation-minor-mode) if you're really set on the minor mode idea) in the code that's creating the *erl-output* buffer. You can edit the source for the mode, or use advice around the creation routine...