Browse Source

Fix positioning bug when returning from source code editing

Carsten Dominik 16 năm trước cách đây
mục cha
commit
a6449c0324
2 tập tin đã thay đổi với 45 bổ sung42 xóa
  1. 2 0
      lisp/ChangeLog
  2. 43 42
      lisp/org-src.el

+ 2 - 0
lisp/ChangeLog

@@ -1,6 +1,8 @@
 2009-06-09  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-src.el (org-src-mode): Renamed from `org-exit-edit-mode'.
+	(org-edit-src-exit): Better cursor positioning when returning from
+	editing.
 
 	* org-latex.el (org-export-latex-use-verb): New variable.
 	(org-export-latex-emph-format): Prefer \texttt over \verb when

+ 43 - 42
lisp/org-src.el

@@ -407,53 +407,54 @@ the language, a switch telling of the content should be in a single line."
   (interactive)
   (unless (string-match "\\`*Org Edit " (buffer-name (current-buffer)))
     (error "This is not an sub-editing buffer, something is wrong..."))
-  (let ((line (if (org-bound-and-true-p org-edit-src-force-single-line)
-		  1
-		(org-current-line)))
-	(beg org-edit-src-beg-marker)
+  (let ((beg org-edit-src-beg-marker)
 	(end org-edit-src-end-marker)
 	(ovl org-edit-src-overlay)
 	(buffer (current-buffer))
 	(nindent org-edit-src-nindent)
-	code)
-  (goto-char (point-min))
-  (if (looking-at "[ \t\n]*\n") (replace-match ""))
-  (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))
-  (when (org-bound-and-true-p org-edit-src-force-single-line)
-    (goto-char (point-min))
-    (while (re-search-forward "\n" nil t)
-      (replace-match " "))
-    (goto-char (point-min))
-    (if (looking-at "\\s-*") (replace-match " "))
-    (if (re-search-forward "\\s-+\\'" nil t)
-	(replace-match "")))
-  (when (org-bound-and-true-p org-edit-src-from-org-mode)
-    (goto-char (point-min))
-    (while (re-search-forward
-	    (if (org-mode-p) "^\\(.\\)" "^\\([*]\\|[ \t]*#\\+\\)") nil t)
-      (replace-match ",\\1")))
-  (when (org-bound-and-true-p org-edit-src-picture)
-    (untabify (point-min) (point-max))
-    (goto-char (point-min))
-    (while (re-search-forward "^" nil t)
-      (replace-match ": ")))
-  (when nindent
-    (setq nindent (make-string (+ org-edit-src-content-indentation nindent)
-			       ?\ ))
-    (goto-char (point-min))
-    (while (re-search-forward "^" nil t)
+	code line)
+    (save-excursion
+      (goto-char (point-min))
+      (if (looking-at "[ \t\n]*\n") (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)
+		   1
+		 (org-current-line)))
+    (when (org-bound-and-true-p org-edit-src-force-single-line)
+      (goto-char (point-min))
+      (while (re-search-forward "\n" nil t)
+	(replace-match " "))
+      (goto-char (point-min))
+      (if (looking-at "\\s-*") (replace-match " "))
+      (if (re-search-forward "\\s-+\\'" nil t)
+	  (replace-match "")))
+    (when (org-bound-and-true-p org-edit-src-from-org-mode)
+      (goto-char (point-min))
+      (while (re-search-forward
+	      (if (org-mode-p) "^\\(.\\)" "^\\([*]\\|[ \t]*#\\+\\)") nil t)
+	(replace-match ",\\1")))
+    (when (org-bound-and-true-p org-edit-src-picture)
+      (untabify (point-min) (point-max))
+      (goto-char (point-min))
+      (while (re-search-forward "^" nil t)
+	(replace-match ": ")))
+    (when nindent
+      (setq nindent (make-string (+ org-edit-src-content-indentation nindent)
+				 ?\ ))
+      (goto-char (point-min))
+      (while (re-search-forward "^" nil t)
       (replace-match nindent)))
-  (setq code (buffer-string))
-  (switch-to-buffer (marker-buffer beg))
-  (kill-buffer buffer)
-  (goto-char beg)
-  (org-delete-overlay ovl)
-  (delete-region beg end)
-  (insert code)
-  (goto-char beg)
-  (goto-line (1- (+ (org-current-line) line)))
-  (move-marker beg nil)
-  (move-marker end nil)))
+    (setq code (buffer-string))
+    (switch-to-buffer (marker-buffer beg))
+    (kill-buffer buffer)
+    (goto-char beg)
+    (org-delete-overlay ovl)
+    (delete-region beg end)
+    (insert code)
+    (goto-char beg)
+    (goto-line (1- (+ (org-current-line) line)))
+    (move-marker beg nil)
+    (move-marker end nil)))
 
 (defun org-edit-src-save ()
   "Save parent buffer with current state source-code buffer."