How to start a specific mode with emacs? - emacs

Users use 'M-x auto-revert-mode' for starting auto revert mode. How can I set the .emacs file to do the same thing when emacs starts?
How to start a specific mode, when a major mode starts? For example, how to set the .emacs file when I want to start the auto revert mode when LaTeX mode starts?

If you want auto-revert-mode on for all files, add:
(global-auto-revert-mode 1)
If you want it for files for specific modes, try:
(add-hook 'latex-mode-hook '(lambda () (auto-revert-mode 1)))
and substitute the mode name for latex.

Related

How to enable org-indent-mode by default?

I am using Emacs 25.1.50.2
When I am using Org-mode, the org-indent-mode is off by default. So I have to enable it using M-x org-indent-mode everytime.
I put the lisp below into my config file ~/.emecs.d/init.el with no effect.
;; Enable org-indent mode by default
(org-indent mode 1)
;; Above line really should be (org-indent-mode 1)
Thanks for your time :)
You can use the mode hook for the major mode to enable this buffer-local minor mode in org-mode buffers.
For Emacs 24+ you can simply write:
(add-hook 'org-mode-hook 'org-indent-mode)
In earlier Emacs versions you should instead use a custom function to explicitly enable the minor mode by calling (org-indent-mode 1), and then add that custom function to the hook variable.
In 2021 current version of org, you can do this:
(setq org-startup-indented t)

How to make Emacs start in `text-mode` and get rid of LISP message?

How can I make Emacs start in text-mode and get rid of the following message?
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
To get rid of the start message just set the initial-scratch-message variable to ""
(setq initial-scratch-message "")
To start the scratch buffer in text mode you will want to initial-major-mode variable
(setq initial-major-mode 'text-mode)
For setting of auto-mode when you start a specific major-mode you'll want to add an event to the mode hook
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Rather than fiddle with the way the scratch buffer works, I'd recommend you open Emacs with a file argument. E.g. if you do "emacs foo.txt" chances are it will already start up in text-mode without you having to do anything special for it.
You only do M-x text-mode in the scratch buffer.
That's all.

How can I disable auto-fill mode in Emacs?

Today I got my new PC (Windows 7, 32 bit) and installed Vincelt Goulets Emacs. The only other thing I did was updating Org-mode.
Now, I am stuck with auto-fill-mode on every time I start Emacs new, which I hate. I would like to turn auto-fill-mode off, for now and forever. I even deleted my .emacs file, but auto-fill-mode was still turned on.
The only solution that worked was (a) a nasty workaround or (b) always typing M-x auto-fill-mode every time I start Emacs anew.
Is there a solution?
To be clear, the only thing the current .emacs file contains is: '(inhibit-startup-screen t)
Add to your .emacs,
(auto-fill-mode -1)
If there are hooks for specific modes, you will need to zap those as well. My suspicion is that you do not actually have auto-fill-mode on by default in all modes, but with the information you have supplied, at least this should be a starting point.
A reasonable safeguard would be to also disable auto-fill mode from `text-mode-hook':
(remove-hook 'text-mode-hook #'turn-on-auto-fill)
You may need something similar for other modes as well.
Assuming that he has not made fundamental changes, you have several paths:
You can just turn off the mode globally in your .emacs file:
(turn-off-auto-fill)
;; ...or (auto-fill-mode -1)
Since Emacs of that vintage also turns on auto-fill for text-mode, add:
(remove-hook 'text-mode-hook 'turn-on-auto-fill)
That should account for all the default places, but check the major mode hooks if you have other modes enabling this automatically.
If you'd like to keep it turned-on in most text-mode while disable auto-fill in specific modes, e.g. org-mode in my case, you could use the following:
;; turn on auto-fill for text-mode
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; turn off auto-fill for org-mode
(add-hook 'org-mode-hook 'turn-off-auto-fill)

Turning on auto-fill mode as a minor mode when I run emacs

I have the following code to have auto-fill mode as minor mode when I run emacs/org-mode.
(defun my-org-mode-hook()
(progn
(turn-on-flyspell)
(auto-fill-mode)))
(add-hook 'org-mode-hook 'my-org-mode-hook)
But, when I open the org file, I see only (Org Fly Spc): flyspell mode is on, but not the auto-fill mode is not on.
What's wrong with this?
auto-fill-mode without an argument toggles the mode. Try using
(auto-fill-mode 1)
in your hook instead?

How do I enable line numbers (on the left) every time I open Emacs?

I enable them by pressing: M-x linum-mode. How can I "translate" that into my.emacs file in order to enable it automatically every time I open EMACS?
Drop (global-linum-mode t) into your .emacs if you want it for every buffer. Otherwise, you can add a function to the appropriate hook of modes you're interested in to enable it for just that mode.
You should really read though the manual like I suggested in the last question of yours that I answered. ;)
Since Emacs 26, the new way is to use (global-) display-line-numbers-mode:
(global-display-line-numbers-mode 1)
One more solution is to use a linum-mode
linum-mode works fast on large files, so in order to enable it for your mode put this into your configuration:
(add-hook 'js2-mode-hook
(lambda ()
(linum-mode 1)))
linum-mode is a part of Emacs after version 22
More documentation about this mode is here
You can also put (line-number-mode 1) into your .emacs file. This way you can also have it be mode specific:
(defun my-c-mode-common-hook ()
(line-number-mode 1))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
That way, it will only put the line numbers in if it's a C/C++ file.
You might want to consider this code in your .emacs file:
;; always show line numbers
(global-linum-mode 1)
;; insert a space if running in text mode
(if window-system
(progn)
(setq linum-format "%d ")
)
It adds a space between the line number and the editable lines in text mode, as it is done in graphics mode.