Structure editing: Improved item/headline conversion

The conversion commands `C-c -' and `C-c *' are now better
    behaved and therefore more useful, I hope.

    If there is an active region, these commands will act on the
    region, otherwise on the current line.

    - C-c - :: This command turns headings or normal lines into
         items, or items into normal lines.  When there is a
         region, everything depends on the first line of the
         region:
         - if it is a item, turn all items in the region into
           normal lines.
         - if it is a headline, turn all headlines in the region
           into items.
         - if it is a normal line, turn all lines into items.
         - special case: if there is no active region and the
           current line is an item, cycle the bullet type of the
           current list.
    - C-c * :: This command turns items and normal lines into
         headings, or headings into normal lines.  When there is
         a region, everything depends on the first line of the
         region:
         - if it is a item, turn all items in the region into
           headlines.
         - if it is a headline, turn all headlines in the region
           into normal lines.
         - if it is a normal line, turn all lines into headlines.
This commit is contained in:
Carsten Dominik 2009-01-21 17:45:07 +01:00
parent 039d28fbb0
commit ac2347589e
6 changed files with 131 additions and 72 deletions

View File

@ -10,11 +10,45 @@
#+LINK_UP: index.html
#+LINK_HOME: http://orgmode.org
* Version 6.18
* Version 6.19 (in preparation)
:PROPERTIES:
:VISIBILITY: content
:END:
** Details
*** Improved behavior of conversion commands =C-c -= and =C-c *=
The conversion commands =C-c -= and =C-c *= are now better
behaved and therefore more useful, I hope.
If there is an active region, these commands will act on the
region, otherwise on the current line.
- C-c - :: This command turns headings or normal lines into
items, or items into normal lines. When there is a
region, everything depends on the first line of the
region:
- if it is a item, turn all items in the region into
normal lines.
- if it is a headline, turn all headlines in the region
into items.
- if it is a normal line, turn all lines into items.
- special case: if there is no active region and the
current line is an item, cycle the bullet type of the
current list.
- C-c * :: This command turns items and normal lines into
headings, or headings into normal lines. When there is
a region, everything depends on the first line of the
region:
- if it is a item, turn all items in the region into
headlines.
- if it is a headline, turn all headlines in the region
into normal lines.
- if it is a normal line, turn all lines into headlines.
* Version 6.18
** Incompatible changes
*** Short examples must have a space after the colon

View File

@ -995,10 +995,11 @@ Narrow buffer to current subtree.
Widen buffer to remove a narrowing.
@kindex C-c *
@item C-c *
Turn a normal line or plain list item into a headline (so that it
becomes a subheading at its location). Also turn a headline into a
normal line by removing the stars. If there is an active region, turn
all lines in the region into headlines. Or, if the first line is a
Turn a normal line or plain list item into a headline (so that it becomes a
subheading at its location). Also turn a headline into a normal line by
removing the stars. If there is an active region, turn all lines in the
region into headlines. If the first line in the region was an item, turn
only the item lines into headlines. Finally, if the first line is a
headline, remove the stars from all headlines in the region.
@end table

View File

@ -308,17 +308,16 @@ are preserved on all copies.
\key{insert new heading after subtree}{C-RET}
\key{insert new TODO entry/checkbox item}{M-S-RET}
\key{insert TODO entry/ckbx after subtree}{C-S-RET}
\key{turn (head)line into item, cycle item type}{C-c -}
\key{turn item/line into headline}{C-c *}
\key{promote/demote heading}{M-LEFT/RIGHT}
\metax{promote/demote current subtree}{M-S-LEFT/RIGHT}
\key{move subtree/list item up/down}{M-S-UP/DOWN}
\key{refile subtree}{C-c C-w}
\key{kill subtree}{C-c C-x C-w}
\key{copy subtree}{C-c C-x M-w}
\metax{move subtree/list item up/down}{M-S-UP/DOWN}
\metax{refile subtree}{C-c C-w}
\metax{kill/copy subtree}{C-c C-x C-w/M-w}
\metax{yank subtree}{C-c C-x C-y or C-y}
\key{narrow buffer to current subtree}{C-x n s}
\key{widen restriction to full buffer}{C-x n w}
\metax{narrow buffer to subtree / widen}{C-x n s/w}
\section{Archiving}

View File

@ -41,6 +41,9 @@ insert new heading/item at current level M-RET
insert new heading after subtree C-RET
insert new TODO entry/checkbox item M-S-RET
insert TODO entry/ckbx after subtree C-S-RET
turn (head)line into item, cycle bullet type C-c -
turn item/line into headline, and back into line C-c *
promote/demote current heading up one level M-LEFT/RIGHT
promote/demote current subtree up one level M-S-LEFT/RIGHT
move subtree/list item up/down M-S-UP/DOWN

View File

@ -1,5 +1,15 @@
2009-01-21 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-toggle-heading): Renamed from
`org-toggel-region-headings'.
No longer needs a region defined, but will use it if there is one.
(org-ctrl-c-star): Simplified, relying more on the internal
workings of `org-toggle-heading'.
(org-toggle-item): Renamed from `org-toggle-region-items'.
No longer needs a region defined, but will use it if there is one.
(org-ctrl-c-minus): Simplified, relying more on the inernal
workings of `org-toggle-item'.
* org-export-latex.el (org-export-latex-preprocess): Fix bug in
environment detection. Also, do real changes only in unprotected
places.

View File

@ -13266,65 +13266,47 @@ context. See the individual commands for more information."
(defun org-ctrl-c-star ()
"Compute table, or change heading status of lines.
Calls `org-table-recalculate' or `org-toggle-region-headings',
depending on context. This will also turn a plain list item or a normal
line into a subheading."
Calls `org-table-recalculate' or `org-toggle-heading',
depending on context."
(interactive)
(cond
((org-at-table-p)
(call-interactively 'org-table-recalculate))
((org-region-active-p)
(t
;; Convert all lines in region to list items
(call-interactively 'org-toggle-region-headings))
((org-on-heading-p)
(org-toggle-region-headings (point-at-bol)
(min (1+ (point-at-eol)) (point-max))))
((org-at-item-p)
;; Convert to heading
(let ((level (save-match-data
(save-excursion
(condition-case nil
(progn
(org-back-to-heading t)
(funcall outline-level))
(error 0))))))
(replace-match
(concat (make-string (org-get-valid-level level 1) ?*) " ") t t)))
(t (org-toggle-region-headings (point-at-bol)
(min (1+ (point-at-eol)) (point-max))))))
(call-interactively 'org-toggle-heading))))
(defun org-ctrl-c-minus ()
"Insert separator line in table or modify bullet status of line.
Also turns a plain line or a region of lines into list items.
Calls `org-table-insert-hline', `org-toggle-region-items', or
Calls `org-table-insert-hline', `org-toggle-item', or
`org-cycle-list-bullet', depending on context."
(interactive)
(cond
((org-at-table-p)
(call-interactively 'org-table-insert-hline))
((org-on-heading-p)
;; Convert to item
(save-excursion
(beginning-of-line 1)
(if (looking-at "\\*+ ")
(replace-match
(concat (make-string
(- (match-end 0) (point) (if org-odd-levels-only 2 1)) ?\ )
"- ")))))
((org-region-active-p)
;; Convert all lines in region to list items
(call-interactively 'org-toggle-region-items))
(call-interactively 'org-toggle-item))
((org-in-item-p)
(call-interactively 'org-cycle-list-bullet))
(t (org-toggle-region-items (point-at-bol)
(min (1+ (point-at-eol)) (point-max))))))
(t
(call-interactively 'org-toggle-item))))
(defun org-toggle-region-items (beg end)
"Convert all lines in region to list items.
If the first line is already an item, convert all list items in the region
to normal lines."
(interactive "r")
(let (l2 l)
(defun org-toggle-item ()
"Convert headings or normal lines to items, items to normal lines.
If there is no active region, only the current line is considered.
If the first line in the region is a headline, convert all headlines to items.
If the first line in the region is an item, convert all items to normal lines.
If the first line is normal text, add an item bullet to each line."
(interactive)
(let (l2 l beg end)
(if (org-region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (point-at-bol)
end (min (1+ (point-at-eol)) (point-max))))
(save-excursion
(goto-char end)
(setq l2 (org-current-line))
@ -13339,18 +13321,41 @@ to normal lines."
(delete-region (match-beginning 2) (match-end 2))
(and (looking-at "[ \t]+") (replace-match "")))
(beginning-of-line 2))
(if (org-on-heading-p)
;; Headings, convert to items
(while (< (setq l (1+ l)) l2)
(if (looking-at org-outline-regexp)
(replace-match "- " t t))
(beginning-of-line 2))
;; normal lines, turn them into items
(while (< (setq l (1+ l)) l2)
(unless (org-at-item-p)
(if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
(replace-match "\\1- \\2")))
(beginning-of-line 2))))))
(beginning-of-line 2)))))))
(defun org-toggle-region-headings (beg end)
"Convert all lines in region to list items.
If the first line is already an item, convert all list items in the region
to normal lines."
(interactive "r")
(let (l2 l)
(defun org-toggle-heading (&optional nstars)
"Convert headings to normal text, or items or text to headings.
If there is no active region, only the current line is considered.
If the first line is a heading, remove the stars from all headlines
in the region.
If the first line is a plain list item, turn all plain list items into
headings.
If the first line is a normal line, turn each and every line in the region
into a heading.
When converting a line into a heading, the number of stars is chosen
such that the lines become children of the current entry. However, when
a prefix argument is given, its value determines the number of stars to add."
(interactive "P")
(let (l2 l itemp beg end)
(if (org-region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (point-at-bol)
end (min (1+ (point-at-eol)) (point-max))))
(save-excursion
(goto-char end)
(setq l2 (org-current-line))
@ -13363,15 +13368,22 @@ to normal lines."
(when (org-on-heading-p t)
(and (looking-at outline-regexp) (replace-match "")))
(beginning-of-line 2))
(let* ((stars (save-excursion
(setq itemp (org-at-item-p))
(let* ((stars
(if nstars
(make-string (prefix-numeric-value current-prefix-arg)
?*)
(save-excursion
(re-search-backward org-complex-heading-regexp nil t)
(or (match-string 1) "*")))
(add-stars (if org-odd-levels-only "**" "*"))
(rpl (concat stars add-stars " \\2")))
(or (match-string 1) "*"))))
(add-stars (if nstars "" (if org-odd-levels-only "**" "*")))
(rpl (concat stars add-stars " ")))
(while (< (setq l (1+ l)) l2)
(if itemp
(and (org-at-item-p) (replace-match rpl t t))
(unless (org-on-heading-p)
(if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
(replace-match rpl)))
(replace-match (concat rpl (match-string 2))))))
(beginning-of-line 2)))))))
(defun org-meta-return (&optional arg)