浏览代码

New function `org-list-make-subtree' bound to C-c C-*

This function convert the plain list at point into a subtree, preserving
the list structure.  Thanks to Ilya Shlyakhter for this suggestion.
Bastien Guerry 15 年之前
父节点
当前提交
8b840fe73c
共有 3 个文件被更改,包括 45 次插入3 次删除
  1. 6 0
      lisp/ChangeLog
  2. 36 2
      lisp/org-list.el
  3. 3 1
      lisp/org.el

+ 6 - 0
lisp/ChangeLog

@@ -1,5 +1,11 @@
 2009-07-25  Bastien Guerry  <bzg@altern.org>
 
+	* org.el (org-mode-map): Define new key `C-c C-*': convert a plain
+	list to a subtree, preserving the structure of the list.
+
+	* org-list.el (org-list-goto-true-beginning)
+	(org-list-make-subtree, org-list-make-subtrees): New functions.
+
 	* org.el (org-eval-in-calendar): Select the right frame.
 	(org-save-frame-excursion): Remove this macro.
 

+ 36 - 2
lisp/org-list.el

@@ -1102,6 +1102,41 @@ cdr is the indentation string."
 	(progn (goto-char (point-min)) (point))
       (cons (match-beginning 0) (match-string 1)))))
 
+(defun org-list-goto-true-beginning ()
+  "Go to the beginning of the list at point."
+  (beginning-of-line 1)
+  (while (looking-at org-list-beginning-re)
+    (beginning-of-line 0))
+  (progn
+    (re-search-forward org-list-beginning-re nil t)
+    (goto-char (match-beginning 0))))
+  
+(defun org-list-make-subtree ()
+  "Convert the plain list at point into a subtree."
+  (interactive)
+  (org-list-goto-true-beginning)
+  (let ((list (org-list-parse-list t)) nstars)
+    (save-excursion 
+      (if (condition-case nil
+	      (org-back-to-heading)
+	    (error nil))
+	  (progn (re-search-forward org-complex-heading-regexp nil t)
+		 (setq nstars (length (match-string 1))))
+	(setq nstars 0)))
+    (org-list-make-subtrees list (1+ nstars))))
+
+(defun org-list-make-subtrees (list level)
+  "Convert LIST into subtrees starting at LEVEL."
+  (if (symbolp (car list))
+      (org-list-make-subtrees (cdr list) level)
+    (mapcar (lambda (item)
+	      (if (stringp item)
+		  (insert (make-string 
+			   (if org-odd-levels-only 
+			       (1- (* 2 level)) level) ?*) " " item "\n")
+		(org-list-make-subtrees item (1+ level))))
+	    list)))
+
 (defun org-list-end (indent)
   "Return the position of the end of the list.
 INDENT is the indentation of the list, as a string."
@@ -1139,8 +1174,7 @@ this list."
   (catch 'exit
     (unless (org-at-item-p) (error "Not at a list"))
     (save-excursion
-      ;; bzg use org-list-find-true-beginning here?
-      (goto-char (car (org-list-item-beginning)))
+      (org-list-find-true-beginning)
       (beginning-of-line 0)
       (unless (looking-at "#\\+ORGLST: *SEND +\\([a-zA-Z0-9_]+\\) +\\([^ \t\r\n]+\\)\\( +.*\\)?")
 	(if maybe

+ 3 - 1
lisp/org.el

@@ -13968,7 +13968,9 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
 (org-defkey org-mode-map "\C-c:"    'org-toggle-fixed-width-section)
 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
-(org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
+(org-defkey org-mode-map "\C-c\C-xf"    'org-footnote-action)
+(org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
+;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
 
 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)