Function: use-hard-newlines

use-hard-newlines is an interactive and byte-compiled function defined in paragraphs.el.gz.

Signature

(use-hard-newlines &optional ARG INSERT)

Documentation

Toggle between hard and soft newlines in the current buffer.

When enabled, the functions newline and open-line add the text-property hard to newlines that they insert, and a line is only considered as a candidate to match paragraph-start or paragraph-separate if it follows a hard newline.

When enabling, if there are newlines in the buffer but no hard newlines, ask the user whether to mark as hard any newlines preceding a paragraph-start line. From a program, second arg INSERT specifies whether to do this; it can be never to change nothing, t or always to force marking, guess to try to do the right thing with no questions, nil or anything else to ask the user.

Newlines not marked hard are called "soft", and are always internal to paragraphs. The fill functions insert and delete only soft newlines.

This is a minor mode. If called interactively, toggle the Use-Hard-Newlines mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable use-hard-newlines(var)/use-hard-newlines(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

View in manual

Probably introduced at or before Emacs version 19.29.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/paragraphs.el.gz
(define-minor-mode use-hard-newlines
  "Toggle between hard and soft newlines in the current buffer.

When enabled, the functions `newline' and `open-line' add the
text-property `hard' to newlines that they insert, and a line is
only considered as a candidate to match `paragraph-start' or
`paragraph-separate' if it follows a hard newline.

When enabling, if there are newlines in the buffer but no hard
newlines, ask the user whether to mark as hard any newlines
preceding a `paragraph-start' line.  From a program, second arg
INSERT specifies whether to do this; it can be `never' to change
nothing, t or `always' to force marking, `guess' to try to do the
right thing with no questions, nil or anything else to ask the
user.

Newlines not marked hard are called \"soft\", and are always internal
to paragraphs.  The fill functions insert and delete only soft newlines."
  :group 'paragraphs
  :extra-args (insert)
  (when use-hard-newlines
    ;; Turn mode on
    ;; Intuit hard newlines --
    ;;   mark as hard any newlines preceding a paragraph-start line.
    (if (or (eq insert t) (eq insert 'always)
	    (and (not (eq 'never insert))
		 (not (text-property-any (point-min) (point-max) 'hard t))
		 (save-excursion
		   (goto-char (point-min))
		   (search-forward "\n" nil t))
		 (or (eq insert 'guess)
		     (y-or-n-p "Make newlines between paragraphs hard? "))))
	(save-excursion
	  (goto-char (point-min))
	  (while (search-forward "\n" nil t)
	    (let ((pos (point)))
	      (move-to-left-margin)
	      (when (looking-at paragraph-start)
		(set-hard-newline-properties (1- pos) pos))
	      ;; If paragraph-separate, newline after it is hard too.
	      (when (looking-at paragraph-separate)
		(set-hard-newline-properties (1- pos) pos)
		(end-of-line)
		(unless (eobp)
		  (set-hard-newline-properties (point) (1+ (point)))))))))))