From 8b840fe73c835f617d727f1dff60bce9acddec24 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Sun, 26 Jul 2009 04:48:32 +0800 Subject: [PATCH] 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. --- lisp/ChangeLog | 6 ++++++ lisp/org-list.el | 38 ++++++++++++++++++++++++++++++++++++-- lisp/org.el | 4 +++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 401b12b26..2f8c9c034 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,11 @@ 2009-07-25 Bastien Guerry + * 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 865e9a142..243a9cb01 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 2fb92e0bd..02c2b5c17 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)