15

Customize python-fill-docstring-style accordingly, presuming that you are using the built-in Python Mode in Emacs 24.4. The default is pep-257, which leads to the style you observed, i.e. no newline at the beginning and two newlines before the end of a docstring. Change this variable to symmetric or django to have Python Mode obey your preferred style, i.e....


13

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. Wrapping ...


11

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). Configuring fill-...


11

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, ...


10

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 ...


9

Would your version-control issues be avoided/resolved if you use git diff --color-words or latexdiff? Then you can look at changed words.


7

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) (interactive "r") (shell-command-on-region beg end "format")) (defun my-format-paragraph () (interactive) (save-...


7

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 ...


7

Perhaps you're looking for indent-pp-sexp, which is bound to C-M-q by default in emacs lisp mode. With a prefix argument (e.g. C-u C-M-q) this will "pretty print" the sexp at point.


6

Change emacs-lisp-docstring-fill-column to nil. From the docstring (emphasis mine): Value of fill-column to use when filling a docstring. Any non-integer value means do not use a different value of `fill-column' when filling docstrings. Please don't do this, though. There is a reason for this setting: Emacs shows docstrings exactly like the ...


6

I've been a happy user of filladapt-mode for a long time, which handles this sort of thing really nicely. For info, see http://emacswiki.org/emacs/FillAdapt 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 “*”. For ...


6

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" (interactive "r") (copy-region-as-kill beg end) (with-temp-buffer (yank) (goto-char 0) (while (looking-at "[ \t\n]") (delete-char 1)) (compact-uncompact-block) (mark-whole-...


5

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 ...


5

The elisp manual section about auto-filling describes the auto-fill-chars variable. -- 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 ...


4

I don't see how to make filling work. So a work-around is to use M-x toggle-truncate-lines. This only affects the presentation of the heading. It does not insert newlines.


4

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 () (interactive) (fill-paragraph) (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 ...


4

Customize org-plain-list-ordered-item-terminator. 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....


4

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 () (interactive) (save-excursion (save-restriction (widen) (fill-region (point-min) (point-max)))))


4

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 ...


3

(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 ...


3

Python Mode provides its own fill-paragraph-function, called python-fill-paragraph. This function implements extensive formatting of code beyond just wrapping paragraphs. Change the filling style Notably, it formats docstrings according to python-fill-docstring-style, whose default value is pep-257, that is, formatting docstrings according to PEP 257 ...


3

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\\. *" (- (...


3

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.


3

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 ]")) (font-lock-add-keywords nil `((,eol-regexp 1 '(face default display " "))))) (visual-line-mode 1) This will "remove" newlines if it ...


3

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 ...


3

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 whitespace ...


3

Essentially you want your function to do the equivalent of marking the paragraph and typing C-uM-| par RET Something like: (defun my-fill-paragraph-using-par (&optional _justify) "Invoke shell command `par' on the current paragraph." (interactive) (save-excursion (mark-paragraph) (forward-whitespace 1) (shell-command-on-region (point) ...


3

You have sentence-end-double-space set to its default value, which is t. The relevant part of the docstring: Documentation: Non-nil means a single space does not end a sentence. This is relevant for filling. See also sentence-end-without-period and colon-double-space. That variable needs to be set to nil to get the wrapping you expect. So: (...


3

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.


3

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 ...


Only top voted, non community-wiki answers of a minimum length are eligible