Browse Source

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.
Carsten Dominik 16 years ago
parent
commit
4fa160447d
2 changed files with 39 additions and 28 deletions
  1. 4 0
      lisp/ChangeLog
  2. 35 28
      lisp/org.el

+ 4 - 0
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>
 2008-11-06  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org-vm.el (org-vm-follow-link): Call `vm-preview-current-message'
 	* org-vm.el (org-vm-follow-link): Call `vm-preview-current-message'

+ 35 - 28
lisp/org.el

@@ -13967,10 +13967,11 @@ beyond the end of the headline."
 
 
 (defun org-yank ()
 (defun org-yank ()
   "Yank.  If the kill is a subtree, treat it specially.
   "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
 org-yank-folded-subtrees
     When set, the subree(s) wiil be folded after insertion.
     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
     When set, the subtree will be promoted or demoted in order to
     fit into the local outline tree structure.
     fit into the local outline tree structure.
 
 
-
 \[1] Basically, the test checks if the first non-white line is a heading
 \[1] Basically, the test checks if the first non-white line is a heading
     and if there are no other headings with fewer stars."
     and if there are no other headings with fewer stars."
   (interactive)
   (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)
 (define-key org-mode-map "\C-y" 'org-yank)