In list environment, after I copy several paragraphs, the next item number will change into number 1, How can I deal with that?

For example,

1. aaa
2. aaa
3. aaa
bbb    <---this is what I copied
1. aaa <---I want it becomes 4
  • 1
    All you need is to add space before bbb and ccc. Or are you asking about how to add space automatically upon copying?
    – wvxvw
    Commented Jan 4, 2016 at 16:40
  • @wvxvw add space automatically might be good
    – yuxuan
    Commented Jan 4, 2016 at 17:10
  • You would probably need to advise yank and pad the strings you insert with as many spaces as the current indentation level... but this seems like a low of work. If you don't encounter this problem very often, you could just insert region (of blanks) before the inserted text: a bit slower, but easier to do.
    – wvxvw
    Commented Jan 4, 2016 at 18:24
  • you can use (org-get-indentation) to find the indentation. then you could use a temp buffer to add the necessary amount of space for each line, before inserting it into your buffer.
    – rasmus
    Commented Jan 5, 2016 at 22:59

2 Answers 2


It is not a good idea to adjust the yanked region directly on yank. The indent is syntactic relevant for the structure of an org-file. If you copy-paste already structured text the structure would get lost through the adjustments.

I propose that you leave yank as it is and use the following command org-adjust-region that re-adjusts all the stuff in the current region according to the preceeding stuff.

I have bound this function to C-+.

You can install the lisp snippet below in your init file. In your use case you just press C-+ right after pasting and see what happens...

(require 'org)
(defun org-adjust-region (b e)
  "Readjust stuff in region according to the preceeding stuff."
  (interactive "r") ;; current region
    (let ((e (set-marker (make-marker) e))
      (_indent (lambda ()
             (insert ?\n)
             (delete-char 1)))
      (goto-char b)
      (while (< (point) e)
    (indent-line-to 0)
     ((looking-at "[[:space:]]*$")) ;; ignore empty lines
      (error "Headings cannot be balanced (yet)."))
      (funcall _indent)
      (let ((struct (org-list-struct))
        (mark-active nil))
        (ignore-errors (org-list-indent-item-generic -1 t struct)))
      (setq last-item-pos (point)))
      (funcall _indent)
      (goto-char (plist-get (cadr (org-element-special-block-parser e nil)) :contents-end))
     (t (funcall _indent)))
      (when last-item-pos
    (goto-char last-item-pos)

(define-key org-mode-map (kbd "C-+") 'org-adjust-region)

Paragraph bbb\nccc is not part of item 3:

1. aaa
2. aaa
3. aaa
bbb    <---this is what I copied
4. [@4] aaa <---I want it becomes 4

Paragraph bbb\nccc is a separate paragraph within item 3

1. aaa
2. aaa
3. aaa

   bbb    <---this is what I copied
4. aaa <---I want it becomes 4
  • Item 4 starts a separate list with the method in the first text snippet. If you insert an additional item below item 2 org-list-repair does not work as expected. The first list runs from 1 to 4 and the next one starts at 4?! I do not know how you get from the first text snippet to the second one. Selecting a region and running org-indent does work for this small example but not in the general case where there are several items in the pasted text. That is the point where I started to write down my solution.
    – Tobias
    Commented Jan 6, 2016 at 8:20
  • Note also that you need to preserve the indentation of code blocks in the inserted text. I do not yet know what to do with headlines. Do we want to demote them? I do also not yet know what to do with drawers.
    – Tobias
    Commented Jan 6, 2016 at 8:58
  • tobias: re first message. yes they are separate lists. The first element is a plain-list of items; the second element is a paragraph; the third element is again a plain-list. To verify use org-element-at-point at pos 0, 22, and 59. The second list starts at 4 because of the @ operator, and it's the point of the exercise. The second example is independent of the first and it seems we are trying to solve different problems. I simply show how to make the paragraph either a separate element or part of the item starting at pos 15.
    – rasmus
    Commented Jan 9, 2016 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.