In list environment, after I copy several paragraphs, the next item number will change into number 1, How can I deal with that?
1. aaa 2. aaa 3. aaa bbb <---this is what I copied ccc 1. aaa <---I want it becomes 4
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
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 (save-excursion (let ((e (set-marker (make-marker) e)) (_indent (lambda () (insert ?\n) (backward-char) (org-indent-line) (delete-char 1))) last-item-pos) (goto-char b) (beginning-of-line) (while (< (point) e) (indent-line-to 0) (cond ((looking-at "[[:space:]]*$")) ;; ignore empty lines ((org-at-heading-p) (error "Headings cannot be balanced (yet).")) ((org-at-item-p) (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))) ((org-at-block-p) (funcall _indent) (goto-char (plist-get (cadr (org-element-special-block-parser e nil)) :contents-end)) (org-indent-line)) (t (funcall _indent))) (forward-line)) (when last-item-pos (goto-char last-item-pos) (org-list-repair) )))) (define-key org-mode-map (kbd "C-+") 'org-adjust-region)