Browse Source

Prevent point movement when switching between org and code buffers.

Keep point in the same location relative to surrounding text when
switching between org and code buffers.
Dan Davison 16 years ago
parent
commit
8da6520429
1 changed files with 9 additions and 2 deletions
  1. 9 2
      lisp/org-src.el

+ 9 - 2
lisp/org-src.el

@@ -164,6 +164,7 @@ This will remove the original code in the Org buffer, and replace it with
 the edited version."
 the edited version."
   (interactive)
   (interactive)
   (let ((line (org-current-line))
   (let ((line (org-current-line))
+	(col (current-column))
 	(case-fold-search t)
 	(case-fold-search t)
 	(msg (substitute-command-keys
 	(msg (substitute-command-keys
 	      "Edit, then exit with C-c ' (C-c and single quote)"))
 	      "Edit, then exit with C-c ' (C-c and single quote)"))
@@ -230,6 +231,8 @@ the edited version."
 	  (while (re-search-forward "^," nil t)
 	  (while (re-search-forward "^," nil t)
 	    (replace-match "")))
 	    (replace-match "")))
 	(org-goto-line (1+ (- line begline)))
 	(org-goto-line (1+ (- line begline)))
+	(org-move-to-column
+	 (if preserve-indentation col (max 0 (- col total-nindent))))
 	(org-set-local 'org-edit-src-beg-marker beg)
 	(org-set-local 'org-edit-src-beg-marker beg)
 	(org-set-local 'org-edit-src-end-marker end)
 	(org-set-local 'org-edit-src-end-marker end)
 	(org-set-local 'org-edit-src-overlay ovl)
 	(org-set-local 'org-edit-src-overlay ovl)
@@ -277,6 +280,7 @@ exit with \\[org-edit-src-exit].  The edited text will then replace
 the fragment in the Org-mode buffer."
 the fragment in the Org-mode buffer."
   (interactive)
   (interactive)
   (let ((line (org-current-line))
   (let ((line (org-current-line))
+	(col (current-column))
 	(case-fold-search t)
 	(case-fold-search t)
 	(msg (substitute-command-keys
 	(msg (substitute-command-keys
 	      "Edit, then exit with C-c ' (C-c and single quote)"))
 	      "Edit, then exit with C-c ' (C-c and single quote)"))
@@ -342,6 +346,7 @@ the fragment in the Org-mode buffer."
 	(while (re-search-forward "^[ \t]*: ?" nil t)
 	(while (re-search-forward "^[ \t]*: ?" nil t)
 	  (replace-match ""))
 	  (replace-match ""))
 	(org-goto-line (1+ (- line begline)))
 	(org-goto-line (1+ (- line begline)))
+	(org-move-to-column (max 0 (- col block-nindent 2)))
 	(org-set-local 'org-edit-src-beg-marker beg)
 	(org-set-local 'org-edit-src-beg-marker beg)
 	(org-set-local 'org-edit-src-end-marker end)
 	(org-set-local 'org-edit-src-end-marker end)
 	(org-set-local 'org-edit-src-overlay ovl)
 	(org-set-local 'org-edit-src-overlay ovl)
@@ -458,7 +463,7 @@ the language, a switch telling of the content should be in a single line."
 	 (total-nindent (+ (or org-edit-src-block-indentation 0)
 	 (total-nindent (+ (or org-edit-src-block-indentation 0)
 			   org-edit-src-content-indentation))
 			   org-edit-src-content-indentation))
 	 (preserve-indentation org-src-preserve-indentation)
 	 (preserve-indentation org-src-preserve-indentation)
-	 code line indent)
+	 code line col indent)
     (untabify (point-min) (point-max))
     (untabify (point-min) (point-max))
     (save-excursion
     (save-excursion
       (goto-char (point-min))
       (goto-char (point-min))
@@ -467,7 +472,8 @@ the language, a switch telling of the content should be in a single line."
 	(if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))))
 	(if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))))
     (setq line (if (org-bound-and-true-p org-edit-src-force-single-line)
     (setq line (if (org-bound-and-true-p org-edit-src-force-single-line)
 		   1
 		   1
-		 (org-current-line)))
+		 (org-current-line))
+	  col (current-column))
     (when single
     (when single
       (goto-char (point-min))
       (goto-char (point-min))
       (if (re-search-forward "\\s-+\\'" nil t) (replace-match ""))
       (if (re-search-forward "\\s-+\\'" nil t) (replace-match ""))
@@ -508,6 +514,7 @@ the language, a switch telling of the content should be in a single line."
     (goto-char beg)
     (goto-char beg)
     (if single (just-one-space))
     (if single (just-one-space))
     (org-goto-line (1- (+ (org-current-line) line)))
     (org-goto-line (1- (+ (org-current-line) line)))
+    (org-move-to-column (if preserve-indentation col (+ col total-nindent)))
     (move-marker beg nil)
     (move-marker beg nil)
     (move-marker end nil)))
     (move-marker end nil)))