summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2009-07-26 04:48:32 +0800
committerBastien Guerry <bzg@altern.org>2009-07-26 04:48:32 +0800
commit8b840fe73c835f617d727f1dff60bce9acddec24 (patch)
tree6920e6b94c75985e87ee4eda8d18a48c1ee2a22b
parent3a0382d5be93ef4ec188686ca84cf79dc3f1c0e2 (diff)
downloadorg-mode-8b840fe73c835f617d727f1dff60bce9acddec24.tar.gz
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.
-rwxr-xr-xlisp/ChangeLog6
-rw-r--r--lisp/org-list.el38
-rw-r--r--lisp/org.el4
3 files changed, 45 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 401b12b..2f8c9c0 100755
--- a/lisp/ChangeLog
+++ b/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.
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 865e9a1..243a9cb 100644
--- a/lisp/org-list.el
+++ b/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
diff --git a/lisp/org.el b/lisp/org.el
index 2fb92e0..02c2b5c 100644
--- a/lisp/org.el
+++ b/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)