summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2019-06-10 00:08:26 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2019-06-10 00:19:32 +0200
commit0ff65e9f4c37e1cbcd6403a185eede5199d1e934 (patch)
tree01288d65b3fc53414333fed1d417e47b814d4c3d
parentbba9116cb8fcb14c5ff616760b606efc0bbb738e (diff)
downloadorg-mode-0ff65e9f4c37e1cbcd6403a185eede5199d1e934.tar.gz
org-list: Change `org-list-to-subtree' signature
* lisp/org-list.el (org-list-to-subtree): Add optional argument to specify level of the subtree. (org-list-make-subtree): * lisp/org.el (org-toggle-heading): Adapt to signature change. Reported-by: Felix Wiemuth <felixwiemuth@hotmail.de> <http://lists.gnu.org/r/emacs-orgmode/2019-06/msg00010.html>
-rw-r--r--etc/ORG-NEWS3
-rw-r--r--lisp/org-list.el23
-rw-r--r--lisp/org.el13
3 files changed, 26 insertions, 13 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 95358ca..bd27fae 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -246,6 +246,9 @@ dynamic block in ~org-dynamic-block-alist~.
It was unused throughout the code base.
** Miscellaneous
+*** Change signature for ~org-list-to-subtree~
+The function now accepts the level of the subtree as an optional
+argument. It no longer deduces it from the current level.
*** LaTeX preview is simplified
Function ~org-latex-preview~, formerly known as
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 9864b18..f32a203 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -3153,10 +3153,14 @@ Point is left at list's end."
(defun org-list-make-subtree ()
"Convert the plain list at point into a subtree."
(interactive)
- (if (not (ignore-errors (goto-char (org-in-item-p))))
- (error "Not in a list")
- (let ((list (save-excursion (org-list-to-lisp t))))
- (insert (org-list-to-subtree list) "\n"))))
+ (let ((item (org-in-item-p)))
+ (unless item (error "Not in a list"))
+ (goto-char item)
+ (let ((level (pcase (org-current-level)
+ (`nil 1)
+ (l (1+ (org-reduced-level l)))))
+ (list (save-excursion (org-list-to-lisp t))))
+ (insert (org-list-to-subtree list level) "\n"))))
(defun org-list-to-generic (list params)
"Convert a LIST parsed through `org-list-to-lisp' to a custom format.
@@ -3465,21 +3469,22 @@ with overruling parameters for `org-list-to-generic'."
:cbtrans "[-] ")))
(org-list-to-generic list (org-combine-plists defaults params))))
-(defun org-list-to-subtree (list &optional params)
+(defun org-list-to-subtree (list &optional start-level params)
"Convert LIST into an Org subtree.
-LIST is as returned by `org-list-to-lisp'. PARAMS is a property
-list with overruling parameters for `org-list-to-generic'."
+LIST is as returned by `org-list-to-lisp'. Subtree starts at
+START-LEVEL or level 1 if nil. PARAMS is a property list with
+overruling parameters for `org-list-to-generic'."
(let* ((blank (pcase (cdr (assq 'heading org-blank-before-new-entry))
(`t t)
(`auto (save-excursion
(org-with-limited-levels (outline-previous-heading))
(org-previous-line-empty-p)))))
- (level (org-reduced-level (or (org-current-level) 0)))
+ (level (or start-level 1))
(make-stars
(lambda (_type depth &optional _count)
;; Return the string for the heading, depending on DEPTH
;; of current sub-list.
- (let ((oddeven-level (+ level depth)))
+ (let ((oddeven-level (+ level (1- depth))))
(concat (make-string (if org-odd-levels-only
(1- (* 2 oddeven-level))
oddeven-level)
diff --git a/lisp/org.el b/lisp/org.el
index c15de97..7bf2b68 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18154,7 +18154,12 @@ number of stars to add."
(min (org-list-get-bottom-point struct) (1+ end))))
(save-restriction
(narrow-to-region (point) list-end)
- (insert (org-list-to-subtree (org-list-to-lisp t)) "\n")))
+ (insert (org-list-to-subtree
+ (org-list-to-lisp t)
+ (pcase (org-current-level)
+ (`nil 1)
+ (l (1+ (org-reduced-level l)))))
+ "\n")))
(setq toggled t))
(forward-line)))
;; Case 3. Started at normal text: make every line an heading,
@@ -18163,10 +18168,10 @@ number of stars to add."
(make-string
(if (numberp nstars) nstars (or (org-current-level) 0)) ?*))
(add-stars
- (cond (nstars "") ; stars from prefix only
- ((equal stars "") "*") ; before first heading
+ (cond (nstars "") ; stars from prefix only
+ ((equal stars "") "*") ; before first heading
(org-odd-levels-only "**") ; inside heading, odd
- (t "*"))) ; inside heading, oddeven
+ (t "*"))) ; inside heading, oddeven
(rpl (concat stars add-stars " "))
(lend (when (listp nstars) (save-excursion (end-of-line) (point)))))
(while (< (point) (if (equal nstars '(4)) lend end))