summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2008-11-07 21:35:27 +0100
committerCarsten Dominik <carsten.dominik@gmail.com>2008-11-07 21:35:27 +0100
commit4fa160447d5f20774a36fbb5a9b515368371df21 (patch)
tree86abe4202b3e356e4b42baa84d558d92fdbbab2f
parent7a9e12dc00bbbf8435fcf42f570966eed95cf4dc (diff)
downloadorg-mode-4fa160447d5f20774a36fbb5a9b515368371df21.tar.gz
Fix bug with cursor movement after org-yank.
When org-yank inserts a subtree, it moves the cursor to the headline after the yank. A structural bug in the `org-yank' function did cause this motion also to happen after a normal yank. Fixed now.
-rwxr-xr-xlisp/ChangeLog4
-rw-r--r--lisp/org.el63
2 files changed, 39 insertions, 28 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ac4ce35..77f64f0 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2008-11-07 Carsten Dominik <carsten.dominik@gmail.com>
+
+ * org.el (org-yank): Fix bug when not inserting a subtree.
+
2008-11-06 Carsten Dominik <carsten.dominik@gmail.com>
* org-vm.el (org-vm-follow-link): Call `vm-preview-current-message'
diff --git a/lisp/org.el b/lisp/org.el
index 3767b3a..e1e983e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -13967,10 +13967,11 @@ beyond the end of the headline."
(defun org-yank ()
"Yank. If the kill is a subtree, treat it specially.
-This command will look at the current kill and check it is a single
-subtree, or a series of subtrees[1]. If it passes the test, it is
-treated specially, depending on the value of the following variables, both
-set by default.
+This command will look at the current kill and check if is a single
+subtree, or a series of subtrees[1]. If it passes the test, and if the
+cursor is at the beginning of a line or after the stars of a currently
+empty headline, then the yank is handeled specially. How exactly depends
+on the value of the following variables, both set by default.
org-yank-folded-subtrees
When set, the subree(s) wiil be folded after insertion.
@@ -13979,33 +13980,39 @@ org-yank-adjusted-subtrees
When set, the subtree will be promoted or demoted in order to
fit into the local outline tree structure.
-
\[1] Basically, the test checks if the first non-white line is a heading
and if there are no other headings with fewer stars."
(interactive)
- (let ((subtreep (org-kill-is-subtree-p)))
- (if org-yank-folded-subtrees
- (let ((beg (point))
- end)
- (if (and subtreep org-yank-adjusted-subtrees)
- (org-paste-subtree nil nil 'for-yank)
- (call-interactively 'yank))
- (setq end (point))
- (goto-char beg)
- (when (and (bolp) subtreep)
- (or (looking-at outline-regexp)
- (re-search-forward (concat "^" outline-regexp) end t))
- (while (and (< (point) end) (looking-at outline-regexp))
- (hide-subtree)
- (org-cycle-show-empty-lines 'folded)
- (condition-case nil
- (outline-forward-same-level 1)
- (error (goto-char end)))))
- (goto-char end)
- (skip-chars-forward " \t\n\r"))
- (if (and subtreep org-yank-adjusted-subtrees)
- (org-paste-subtree nil nil 'for-yank)
- (call-interactively 'yank)))))
+ (let ((subtreep ; is kill a subtree, and the yank position appropriate?
+ (and (org-kill-is-subtree-p)
+ (or (bolp)
+ (and (looking-at "[ \t]*$")
+ (string-match
+ "\\`\\*+\\'"
+ (buffer-substring (point-at-bol) (point))))))))
+ (cond
+ ((and subtreep org-yank-folded-subtrees)
+ (let ((beg (point))
+ end)
+ (if (and subtreep org-yank-adjusted-subtrees)
+ (org-paste-subtree nil nil 'for-yank)
+ (call-interactively 'yank))
+ (setq end (point))
+ (goto-char beg)
+ (when (and (bolp) subtreep)
+ (or (looking-at outline-regexp)
+ (re-search-forward (concat "^" outline-regexp) end t))
+ (while (and (< (point) end) (looking-at outline-regexp))
+ (hide-subtree)
+ (org-cycle-show-empty-lines 'folded)
+ (condition-case nil
+ (outline-forward-same-level 1)
+ (error (goto-char end)))))
+ (goto-char end)
+ (skip-chars-forward " \t\n\r")))
+ ((and subtreep org-yank-adjusted-subtrees)
+ (org-paste-subtree nil nil 'for-yank))
+ (t (call-interactively 'yank)))))
(define-key org-mode-map "\C-y" 'org-yank)