The elisp manual section about auto-filling describes the
-- Variable: auto-fill-chars
A char table of characters which invoke ‘auto-fill-function’ when
self-inserted—space and newline in most language environments.
They have an entry ‘t’ in the table.
About char tables it says:
A char-table is much like a vector, except ...
If you don't mind filling paragraphs rather than just individual
sentences, the simplest way to do it is probably to select the
entire buffer and use fill-region. Here's a simple command that
will automate the process:
(defun fill-buffer ()
(fill-region (point-min) (point-max)))))
Based on the docstrings of the commands, you probably want something along the lines of:
(defun fill-sentence ()
(fill-region (point) (mark))
The optional save-excursion (and commented )) will keep the point where you started (so can be ...
This is expected Vim behavior.
One way to fix this is to just switch to d e instead of d w when you get to the EOL (which I recommend), or you can make that switch automatic:
(defun nadvice/evil-forward-word-begin (old-fun &rest args)
(if (looking-at "[[:space:]]*$")
(apply #'evil-forward-word-end args)
;; fix off-by-one
You have sentence-end-double-space set to its default value,
which is t. The relevant part of the docstring:
Non-nil means a single space does not end a sentence.
This is relevant for filling. See also sentence-end-without-period
That variable needs to be set to nil to get the
wrapping you expect. So:
This will work:
(add-hook 'org-mode-hook '(lambda () (setq fill-column 80)))
(add-hook 'org-mode-hook 'auto-fill-mode)
It enables a minor mode called auto-fill-mode that does exactly what you asked and sets the column where the line break happens to 80 (only for org-mode!).
To be consistent with Emacs Manual you could use
(add-hook 'org-mode-hook '...
You could modify the category of characters G, C, A, and T to make them line-breakable:
(defun break-at-gcat ()
"Make characters G, C, A, and T line-breakable to simplify
wrapping DNA sequence strings."
(dolist (char '(?G ?C ?A ?T))
(modify-category-entry char ?|)))
Now if I evaluate (break-at-gcat), set fill-column to 20,
(setq-local fill-column ...
You can add the following lines to your init-file. Additionally to the default setting, they define lines consisting of at least two equal non-alphanumerical characters as paragraph start and delimiter.
(setq paragraph-start "^\\([^[:alnum:]]\\)\\1+\n\\|\f\\|[ ]*$")
(setq paragraph-separate "\\([^[:alnum:]]\\)\\1+\n\\|[ \f]*$")
Alternatively, you can ...
From the auto-fill-mode docs:
When Auto Fill mode is enabled, inserting a space at a column
beyond `current-fill-column' automatically breaks the line at a
So if you e.g., type a continuous string starting from column 1 to column 100, it will not break at 80 even if you set fill-column to 80. However, if you enter a space at any point ...
You didn't mention which major mode this happens in, but I can see the problem using c-mode. Here is an (abridged) backtrace which you can get after setting debug-on-error:
Debugger entered--Lisp error: (args-out-of-range #<buffer xx> 66 66)...
buffer-substring(#<marker at 66 in xx> #<marker at 66 in xx>)
When some key sequence triggers an unexpected command, use view-lossage (bound to C-h lby default) to see what keystrokes Emacs has recently received. This is most useful since Emacs 25 as it now shows the commands invoked by each key sequence -- in earlier releases you'll just see the raw keystrokes.
When an unexpected minor-mode has been enabled, use ...
Prevent hooks from parent mode in derived mode
Not trivial. I certainly can't think of a nice approach. You may find https://stackoverflow.com/a/19295380 of interest, though.
How can I disable auto-fill for nxml?
The trivial approach is to simply switch it off in nxml-mode-hook. The mode will be switched on, and almost immediately switched off again.
The directory local variables are set after the major mode command run. Otherwise the major-mode dependent file local variables would not work.
Therefore, you just buffer-locally add turn-on-auto-fill to text-mode-hook. But the hook is not run again and your configuration is without effect.
If you want to deactivate truncate-lines for all major modes and ...
If you want to globally set auto-fill-mode, as you say, the solution would be
to put this in your .emacs.s/init.el (or equivalent):
(add-hook 'org-mode-hook 'turn-on-auto-fill)
This means that all files that are viewed in org-mode (usually, files ending in .org) will have auto-fill-mode switched on.
If you do that, you will only use @Tyler's answer once:...
As DoMiNeLa10♦ metioned, lsp-mode can do this:
You should install typescript-language-server in your system and lsp-mode, js2-mode, autocomplete in your emacs. You can check these link for more details.
Or you can check my emacs.d file:
This is the expected behaviour as resulted from the emacs manual:
When Auto Fill mode breaks a line, it tries to obey the adaptive fill prefix: if a fill prefix can be deduced from the first and/or second line of the current paragraph, it is inserted into the new line (see Adaptive Fill). Otherwise the new line is indented, as though you had typed on it (...
If you want to fill all the lines in a region, use the command M-x fill-region. To mark the entire buffer (so the region includes the entire file), use the command M-x mark-whole-buffer, which is also bound to the keybinding C-x h.
If you only want to temporarily wrap the lines for easier reading, you can use visual-line-mode, combined with visual-fill-...
I had comment-auto-fill-only-comments set to t. Since Magit commit buffer supports comments, it won't auto-fill.
(defun me/git-commit-set-fill-column ()
(setq-local comment-auto-fill-only-comments nil)
(setq fill-column 72))
(advice-add 'git-commit-turn-on-auto-fill :before #'me/git-...
Operator Error: After getting a suggestion from @Dan ( emacs -Q ), I tried org-mode again. With distractions out of the way it became clear that headers and paragraphs are treated differently. I was expecting a header to wrap, but they don't. Paragraphs are wrapping just fine with no fixes required.