mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2025-01-16 17:19:49 +00:00
Auto-fill shouldn't insert new items
* lisp/org-list.el (org-list-in-valid-context-p): renamed from org-list-in-valid-block-p. (org-at-item-p,org-list-search-generic): use renamed function. * lisp/org.el (org-fill-item-nobreak-p): new function. (org-set-autofill-regexps): modify `fill-nobreak-predicate' to prevent auto-fill from breaking line just before an item regexp.
This commit is contained in:
parent
9a8dab1436
commit
abad1b4994
@ -401,7 +401,7 @@ group 4: description tag")
|
|||||||
(goto-char (match-end 0)))
|
(goto-char (match-end 0)))
|
||||||
(looking-at regexp))))
|
(looking-at regexp))))
|
||||||
|
|
||||||
(defun org-list-in-valid-block-p ()
|
(defun org-list-in-valid-context-p ()
|
||||||
"Non-nil if point is in a valid block.
|
"Non-nil if point is in a valid block.
|
||||||
Invalid blocks are referring to `org-list-forbidden-blocks'."
|
Invalid blocks are referring to `org-list-forbidden-blocks'."
|
||||||
(save-match-data
|
(save-match-data
|
||||||
@ -491,7 +491,7 @@ This checks `org-list-ending-method'."
|
|||||||
"Is point in a line starting a hand-formatted item?"
|
"Is point in a line starting a hand-formatted item?"
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(and (looking-at (org-item-re)) (org-list-in-valid-block-p))))
|
(and (looking-at (org-item-re)) (org-list-in-valid-context-p))))
|
||||||
|
|
||||||
(defun org-at-item-bullet-p ()
|
(defun org-at-item-bullet-p ()
|
||||||
"Is point at the bullet of a plain list item?"
|
"Is point at the bullet of a plain list item?"
|
||||||
@ -1053,7 +1053,7 @@ in `re-search-forward'."
|
|||||||
nil)))
|
nil)))
|
||||||
;; 2. Match in valid context: return point. Else, continue
|
;; 2. Match in valid context: return point. Else, continue
|
||||||
;; searching.
|
;; searching.
|
||||||
(when (org-list-in-valid-block-p) (throw 'exit (point)))))))
|
(when (org-list-in-valid-context-p) (throw 'exit (point)))))))
|
||||||
|
|
||||||
(defun org-list-search-backward (regexp &optional bound noerror)
|
(defun org-list-search-backward (regexp &optional bound noerror)
|
||||||
"Like `re-search-backward' but stop only where lists are recognized.
|
"Like `re-search-backward' but stop only where lists are recognized.
|
||||||
|
@ -19180,6 +19180,11 @@ the functionality can be provided as a fall-back.")
|
|||||||
;; and fixed-width regions are not wrapped. That function will pass
|
;; and fixed-width regions are not wrapped. That function will pass
|
||||||
;; through to `fill-paragraph' when appropriate.
|
;; through to `fill-paragraph' when appropriate.
|
||||||
(org-set-local 'fill-paragraph-function 'org-fill-paragraph)
|
(org-set-local 'fill-paragraph-function 'org-fill-paragraph)
|
||||||
|
;; Prevent auto-fill from inserting unwanted new items.
|
||||||
|
(org-set-local 'fill-nobreak-predicate
|
||||||
|
(if (memq 'org-fill-item-nobreak-p fill-nobreak-predicate)
|
||||||
|
fill-nobreak-predicate
|
||||||
|
(cons 'org-fill-item-nobreak-p fill-nobreak-predicate)))
|
||||||
;; Adaptive filling: To get full control, first make sure that
|
;; Adaptive filling: To get full control, first make sure that
|
||||||
;; `adaptive-fill-regexp' never matches. Then install our own matcher.
|
;; `adaptive-fill-regexp' never matches. Then install our own matcher.
|
||||||
(unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
|
(unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
|
||||||
@ -19195,6 +19200,10 @@ the functionality can be provided as a fall-back.")
|
|||||||
(regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
|
(regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
|
||||||
(modes . '(org-mode))))))
|
(modes . '(org-mode))))))
|
||||||
|
|
||||||
|
(defun org-fill-item-nobreak-p ()
|
||||||
|
"Non-nil when a line break at point would insert a new item."
|
||||||
|
(and (looking-at (org-item-re)) (org-list-in-valid-context-p)))
|
||||||
|
|
||||||
(defun org-fill-paragraph (&optional justify)
|
(defun org-fill-paragraph (&optional justify)
|
||||||
"Re-align a table, pass through to fill-paragraph if no table."
|
"Re-align a table, pass through to fill-paragraph if no table."
|
||||||
(let ((table-p (org-at-table-p))
|
(let ((table-p (org-at-table-p))
|
||||||
|
Loading…
Reference in New Issue
Block a user