For (1), I would use an enlarged margin, so that visual-line-mode wraps lines at the desired fill-column. This will affect both text lines and equations, though.
As for (2), one can define a custom filling command to be bound to M-q and correctly fill paragraphs. I haven't yet managed to write a command with the correct behaviour for auto-filling.
If you just want something like visual-line-mode but configurable, you can try longlines-mode which is what I use for most of my prose. longlines-mode wraps your text similarly to visual-line-mode with the width configured by fill-column.
Here's a screenshot with fill-column set to 70 (the window actually extends even more to the right).
The original poster is using the words fill and wrap interchangeably -- they are not the same.
See the variable org-startup-truncated:
Non-nil means entering Org-mode will set `truncate-lines'.
This is useful since some lines containing links can be very long and
uninteresting. Also tables look terrible when wrapped.
The default is t. To change this, ...
The problem is that fill-paragraph (or rather, fill-region-as-paragraph) will remove and re-insert newlines while it breaks down your paragraph. It won't modify the buffer if there is only one line. The no-op in the undo list you witness is just fill-paragraph removing and re-inserting newlines.
It is non-trivial to avoid this. The following is a pretty bad ...
It would be better to have 2 functions, although one can be implemented in terms of the other. The reason being that a paragraph is an implicit region, so the input in both cases should be different
(defun my-format-region (beg end)
(shell-command-on-region beg end "format"))
(defun my-format-paragraph ()
This has been a problem for me when creating documents in Danish, where "3rd quarter" is "3. kvartal". The solution I use in such situations is to replace the space after the dot by a non-breaking space by typing C-q 240. This is appropriate in such situations where the dot is not an end of sentence character and could perhaps be used as a work around in ...
I've been a happy user of filladapt-mode for a long time, which handles this sort of thing really nicely. For info, see
From that page:
Filladapt by KyleJones enhances Emacs’ fill functions by guessing a
fill prefix, such as a comment sequence in program code, and handling
bullet points like “1.” or “*”.
I use the following for this:
(defun my-copy-simple (beg end)
"Save the current region to the kill ring after stripping extra whitespace and new lines"
(copy-region-as-kill beg end)
(while (looking-at "[ \t\n]")
The behavior of filling of math switches is controlled by the LaTeX-fill-break-at-separators variable and there are currently discussions about its best default value.
I recently came up with with setting
(setq LaTeX-fill-break-at-separators '(\\\( \\\[))
which fulfills the goal of keeping math formulae in the the same line (this is useful for example for ...
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 ...
While generally, customizing what org considers or doesn't consider a list item is somewhat tricky, the option provides exactly what you need. You have three options:
this is an item,
2) this is an item, or
3 both 1. and 2) are items.
[Note that stackexchange also seems to have a problem interpreting this....
I came up with a minimal way of implementing this functionality: just bind space bar to also call (fill-paragraph)!
(defun fill-then-insert-space ()
(insert " "))
(global-set-key (kbd "SPC") #'fill-then-insert-space)
There are a couple of caveat's that I've stumbled across so far:
elisp-mode (possibly others) does some ...
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)))))
Here I have taken what @phils had posted and have modified it to:
Take more par options
Apply par formatting only on the region, without limiting to paragraph marking because mark-paragraph relies on the major mode to work correctly.
Attempt to make this work on code comments (by marking comment-start characters as Quote characters for par).
Attempt to ...
Sean's gist pointed me in the right direction, and here's the snippet that solved it.
(defun my-adaptive-fill-function ()
"Return prefix for filling paragraph or nil if not determined."
;; List item inside blockquote
((looking-at "^[ \t]*>[ \t]*\\([0-9]+\\.\\|[*+-]\\)[ \t]+")
"[0-9\\.*+-]" " " (match-...
(fill-paragraph &optional JUSTIFY REGION)
If `fill-paragraph-function' is non-nil, we call it (passing our
argument to it), and if it returns non-nil, we simply return its value.
If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling.
markdown-mode presumably sets fill-paragraph-function to nil so that the ...
In emacs-lisp-mode the fill-paragraph-function is set to lisp-fill-paragraph. There is a separate fill column used specifically for docstrings, seeemacs-lisp-docstring-fill-column.
From the variable documentation, you can set emacs-lisp-docstring-fill-column to any non-integer value to make it use the current fill-column instead.
The function you put on fill-nobreak-predicate should return non-nil when point is at the space you don't want to break. So your my-nobreak-p doesn't help because that position is not followed by \cite... and hence doesn't match the regexp.
You can try something like
(defun my-nobreak-p ()
(and (looking-at " *[0-9]")
(looking-back "\\[p\\. *" (- (...
As Tom said, putting a display property on the newlines will kind of work.
The problem is to figure out which lines to wrap.
Here is an example to get you started:
(let ((eol-regexp "[[:graph:]] ?\\(\n\\)[^\t\n ]"))
`((,eol-regexp 1 '(face default display " ")))))
This will "remove" newlines if it ...
Here's what I managed to come up with: fill-paragraph uses fill-region, which uses current-fill-column to decide how to break a particular line. This means that we can tweak current-fill-column to change the current fill column depending on the context.
This function increases the fill column by 1 for each \\ and \" to the left of the tentative line break ...
If you only want to remove newlines, then use replace-regexp-in-string on the result of buffer-substring to remove them.
If you want to remove all extra (typically "insignificant") whitespace, then try function ni-buffer-substring-collapsed-visible from library narrow-indirect.el.
It returns the buffer content between two positions, but with
Essentially you want your function to do the equivalent of marking the paragraph and typing C-uM-| par RET
(defun my-fill-paragraph-using-par (&optional _justify)
"Invoke shell command `par' on the current paragraph."
(shell-command-on-region (point) ...
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:
Just run fill-paragraph bound by default to M-q
Depending on where you are copying from, remember that the paragraph is one logical object, how it shows depends on the width of the browser on your screen. Emacs is doing the correct thing by not inserting extra newlines.