emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Org mode list <emacs-orgmode@gnu.org>
Cc: Nicolas Goaziou <n.goaziou@gmail.com>
Subject: [PATCH] Auto-fill shouldn't insert new items
Date: Sat, 12 Mar 2011 17:29:39 +0100	[thread overview]
Message-ID: <1299947379-19291-1-git-send-email-n.goaziou@gmail.com> (raw)

* 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.
---
 lisp/org-list.el |    6 +++---
 lisp/org.el      |    9 +++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 4b50910..bdef14e 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -400,7 +400,7 @@ group 4: description tag")
            (goto-char (match-end 0)))
 	 (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.
 Invalid blocks are referring to `org-list-forbidden-blocks'."
   (save-match-data
@@ -487,7 +487,7 @@ This checks `org-list-ending-method'."
   "Is point in a line starting a hand-formatted item?"
   (save-excursion
     (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 ()
   "Is point at the bullet of a plain list item?"
@@ -1049,7 +1049,7 @@ in `re-search-forward'."
 			    nil)))
 	;; 2. Match in valid context: return point. Else, continue
 	;;    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)
   "Like `re-search-backward' but stop only where lists are recognized.
diff --git a/lisp/org.el b/lisp/org.el
index 96ad8ff..4a3efc4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19113,6 +19113,11 @@ the functionality can be provided as a fall-back.")
   ;; and fixed-width regions are not wrapped.  That function will pass
   ;; through to `fill-paragraph' when appropriate.
   (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-fill-regexp' never matches.  Then install our own matcher.
   (unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
@@ -19128,6 +19133,10 @@ the functionality can be provided as a fall-back.")
       (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
       (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)
   "Re-align a table, pass through to fill-paragraph if no table."
   (let ((table-p (org-at-table-p))
-- 
1.7.4.1

                 reply	other threads:[~2011-03-12 16:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299947379-19291-1-git-send-email-n.goaziou@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).