浏览代码

Make line splitting with M-RET configurable.

Carsten Dominik 17 年之前
父节点
当前提交
bde33fdb07
共有 4 个文件被更改,包括 117 次插入38 次删除
  1. 8 0
      ChangeLog
  2. 9 4
      ORGWEBPAGE/Changes.org
  3. 84 23
      org.el
  4. 16 11
      org.texi

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2008-02-22  Carsten Dominik  <dominik@science.uva.nl>
+
+	* org.el (org-insert-heading, org-insert-item): More intelligent
+	splitting of lines when creating a new headline or item.
+	(org-M-RET-may-split-line): New option.
+	(org-table-wrap-region): Respect the table setting in
+	org-M-RET-may-split-line'.
+
 2008-02-19  Phil Jackson  <phil@shellarchive.co.uk>
 
 	* org.el (org-store-link): org-irc required.

+ 9 - 4
ORGWEBPAGE/Changes.org

@@ -11,10 +11,15 @@
 
 ** Details
 
-   - M-RET can again be used to split a line, but it will keep
-     any tags in the current line.  A lot of people complained
-     about the M-RET in 5.22, so the splitting is back.  I hope
-     everyone can agree that is go to keep tags in place anyway.
+   - M-RET can again be used to split a line so tha the rest of
+     the line becomes the new heading.  However, if you do this
+     in a heading containing tags, the tags will stay in the old
+     line. 
+
+     Customize the variable `org-M-RET-may-split-line' if you
+     don't want this command to split a line in the middle.  The
+     same variable also influences line splitting in items and in
+     tables.
 
 
 * Version 5.22

+ 84 - 23
org.el

@@ -5,7 +5,7 @@
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 5.22a
+;; Version: 5.22a+
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -84,7 +84,7 @@
 
 ;;; Version
 
-(defconst org-version "5.22a"
+(defconst org-version "5.22a+"
   "The version number of the file org.el.")
 
 (defun org-version (&optional here)
@@ -4669,6 +4669,7 @@ This will extract info from a string like \"WAIT(w@/!)\"."
 		 (and log2 (if (equal log2 "!") 'time 'note)))))))
 
 (defun org-remove-keyword-keys (list)
+  "Remove a pair of parenthesis at the end of each string in LIST."
   (mapcar (lambda (x)
 	    (if (string-match "(.*)$" x)
 		(substring x 0 (match-beginning 0))
@@ -6211,21 +6212,49 @@ but create the new hedline after the current line."
 	  ;; insert right here
 	  nil)
 	 (t
+;	  ;; in the middle of the line
+;	  (org-show-entry)
+;	  (if (org-get-alist-option org-M-RET-may-split-line 'headline)
+;	      (if (and
+;		   (org-on-heading-p)
+;		   (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \r\n]"))
+;		  ;; protect the tags
+;;		  (let ((tags (match-string 2)) pos)
+;		    (delete-region (match-beginning 1) (match-end 1))
+;		    (setq pos (point-at-bol))
+;		    (newline (if blank 2 1))
+;		    (save-excursion
+;		      (goto-char pos)
+;		      (end-of-line 1)
+;		      (insert " " tags)
+;		      (org-set-tags nil 'align)))
+;		(newline (if blank 2 1)))
+;	    (newline (if blank 2 1))))
+
+
 	  ;; in the middle of the line
 	  (org-show-entry)
-	  (if (and (org-on-heading-p)
-		   (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \r\n]"))
-	      ;; protect the tags
-	      (let ((tags (match-string 2)) pos)
-		(delete-region (match-beginning 1) (match-end 1))
-		(setq pos (point-at-bol))
-		(newline (if blank 2 1))
-		(save-excursion
-		  (goto-char pos)
-		  (end-of-line 1)
-		  (insert " " tags)
-		  (org-set-tags nil 'align)))
-	  (newline (if blank 2 1)))))
+	  (let ((split
+		 (org-get-alist-option org-M-RET-may-split-line 'headline))
+		tags pos)
+	    (if (org-on-heading-p)
+		(progn
+		  (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
+		  (setq tags (and (match-end 2) (match-string 2)))
+		  (and (match-end 1)
+		       (delete-region (match-beginning 1) (match-end 1)))
+		  (setq pos (point-at-bol))
+		  (or split (end-of-line 1))
+		  (just-one-space 0)
+		  (newline (if blank 2 1))
+		  (when tags
+		    (save-excursion
+		      (goto-char pos)
+		      (end-of-line 1)
+		      (insert " " tags)
+		      (org-set-tags nil 'align))))
+	      (or split (end-of-line 1))
+	      (newline (if blank 2 1))))))
 	(insert head) (just-one-space)
 	(setq pos (point))
 	(end-of-line 1)
@@ -6985,7 +7014,11 @@ Return t when things worked, nil when we are not in an item."
 	(open-line (if blank 2 1)))
        ((<= (point) eow)
 	(beginning-of-line 1))
-       (t (newline (if blank 2 1))))
+       (t 
+	(unless (org-get-alist-option org-M-RET-may-split-line 'item)
+	  (end-of-line 1)
+	  (just-one-space ))
+	(newline (if blank 2 1))))
       (insert bul (if checkbox "[ ]" ""))
       (just-one-space)
       (setq pos (point))
@@ -9454,6 +9487,8 @@ blank, and the content is appended to the field above."
 	(org-table-goto-column ccol)
 	(org-table-paste-rectangle))
     ;; No region, split the current field at point
+    (unless (org-get-alist-option org-M-RET-may-split-line 'table)
+      (skip-chars-forward "^\r\n|"))
     (if arg
 	;; combine with field above
 	(let ((s (org-table-blank-field))
@@ -9466,13 +9501,14 @@ blank, and the content is appended to the field above."
 	  (insert " " (org-trim s))
 	  (org-table-align))
       ;;  split field
-      (when (looking-at "\\([^|]+\\)+|")
-	(let ((s (match-string 1)))
-	  (replace-match " |")
-	  (goto-char (match-beginning 0))
-	  (org-table-next-row)
-	  (insert (org-trim s) " ")
-	  (org-table-align))))))
+      (if (looking-at "\\([^|]+\\)+|")
+	  (let ((s (match-string 1)))
+	    (replace-match " |")
+	    (goto-char (match-beginning 0))
+	    (org-table-next-row)
+	    (insert (org-trim s) " ")
+	    (org-table-align))
+	(org-table-next-row)))))
 
 (defvar org-field-marker nil)
 
@@ -28250,3 +28286,28 @@ Still experimental, may disappear in the future."
 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
 ;;; org.el ends here
 
+(defcustom org-M-RET-may-split-line '((default . t))
+  "Non-nil means, M-RET will split the line at the cursor position.
+When nil, it will go to the end of the line before making a
+new line.
+You may also set this option in a different way for different
+contexts.  Valid contexts are:
+
+headline  when creating a new headline
+item      when creating a new item
+table     in a table field
+default   the value to be used for all contexts not explicitly
+          customized"
+  :group 'org-structure
+  :group 'org-table
+  :type '(choice
+	  (const :tag "Always" t)
+	  (const :tag "Never" nil)
+	  (repeat :greedy t :tag "Individual contexts"
+		  (cons
+		   (choice :tag "Context"
+			   (const headline)
+			   (const item)
+			   (const table)
+			   (const default))
+		   (boolean)))))

+ 16 - 11
org.texi

@@ -833,12 +833,14 @@ plain list item, a new item is created (@pxref{Plain lists}).  To force
 creation of a new headline, use a prefix arg, or first press @key{RET}
 to get to the beginning of the next line.  When this command is used in
 the middle of a line, the line is split and the rest of the line becomes
-the new headline.  If the command is used at the beginning of a
-headline, the new headline is created before the current line.  If at
-the beginning of any other line, the content of that line is made the
-new heading.  If the command is used at the end of a folded subtree
-(i.e. behind the ellipses at the end of a headline), then a headline
-like the current one will be inserted after the end of the subtree.
+the new headline@footnote{If you do not want the line to be split,
+customize the variable @code{org-M-RET-may-split-line}.}.  If the
+command is used at the beginning of a headline, the new headline is
+created before the current line.  If at the beginning of any other line,
+the content of that line is made the new heading.  If the command is
+used at the end of a folded subtree (i.e. behind the ellipses at the end
+of a headline), then a headline like the current one will be inserted
+after the end of the subtree.
 @kindex C-@key{RET}
 @item C-@key{RET}
 Insert a new heading after the current subtree, same level as the
@@ -1156,11 +1158,12 @@ fixes the indentation of the curent line in a heuristic way.
 Insert new item at current level.  With prefix arg, force a new heading
 (@pxref{Structure editing}).  If this command is used in the middle of a
 line, the line is @emph{split} and the rest of the line becomes the new
-item.  If this command is executed in the @emph{whitespace before a bullet or
-number}, the new item is created @emph{before} the current item.  If the
-command is executed in the white space before the text that is part of
-an item but does not contain the bullet, a bullet is added to the
-current line.
+item@footnote{If you do not want the line to be split, customize the
+variable @code{org-M-RET-may-split-line}.}.  If this command is executed
+in the @emph{whitespace before a bullet or number}, the new item is
+created @emph{before} the current item.  If the command is executed in
+the white space before the text that is part of an item but does not
+contain the bullet, a bullet is added to the current line.
 @kindex M-S-@key{RET}
 @item M-S-@key{RET}
 Insert a new item with a checkbox (@pxref{Checkboxes}).
@@ -1418,7 +1421,9 @@ the table is enlarged as needed.  The process ignores horizontal separator
 lines.
 @c
 @kindex C-c C-q
+@kindex M-@key{RET}
 @item C-c C-q
+@itemx M-@kbd{RET}
 Wrap several fields in a column like a paragraph.  If there is an active
 region, and both point and mark are in the same column, the text in the
 column is wrapped to minimum width for the given number of lines.  A