Ver código fonte

org-table: Fix `org-table-move-row-down' without final newline

* lisp/org-table.el (org-table-move-row): Fix
  `org-table-move-row-down' without final newline.
Nicolas Goaziou 7 anos atrás
pai
commit
969daf41ac
1 arquivos alterados com 17 adições e 16 exclusões
  1. 17 16
      lisp/org-table.el

+ 17 - 16
lisp/org-table.el

@@ -1532,7 +1532,7 @@ non-nil, the one above is used."
 	 (dline1 (org-table-current-dline))
 	 (dline2 (+ dline1 (if up -1 1)))
 	 (tonew (if up 0 2))
-	 txt hline2p)
+	 hline2p)
     (when (and up (= (point-min) (line-beginning-position)))
       (user-error "Cannot move row further"))
     (beginning-of-line tonew)
@@ -1541,21 +1541,22 @@ non-nil, the one above is used."
       (user-error "Cannot move row further"))
     (setq hline2p (looking-at org-table-hline-regexp))
     (goto-char pos)
-    (beginning-of-line 1)
-    (setq pos (point))
-    (setq txt (buffer-substring (point) (1+ (point-at-eol))))
-    (delete-region (point) (1+ (point-at-eol)))
-    (beginning-of-line tonew)
-    (insert txt)
-    (beginning-of-line 0)
-    (org-move-to-column col)
-    (unless (or hline1p hline2p
-		(not (or (not org-table-fix-formulas-confirm)
-			 (funcall org-table-fix-formulas-confirm
-				  "Fix formulas? "))))
-      (org-table-fix-formulas
-       "@" (list (cons (number-to-string dline1) (number-to-string dline2))
-		 (cons (number-to-string dline2) (number-to-string dline1)))))))
+    (let ((row (delete-and-extract-region (line-beginning-position)
+					  (line-beginning-position 2))))
+      (beginning-of-line tonew)
+      (unless (bolp) (insert "\n"))	;at eob without a newline
+      (insert row)
+      (unless (bolp) (insert "\n"))	;missing final newline in ROW
+      (beginning-of-line 0)
+      (org-move-to-column col)
+      (unless (or hline1p hline2p
+		  (not (or (not org-table-fix-formulas-confirm)
+			   (funcall org-table-fix-formulas-confirm
+				    "Fix formulas? "))))
+	(org-table-fix-formulas
+	 "@" (list
+	      (cons (number-to-string dline1) (number-to-string dline2))
+	      (cons (number-to-string dline2) (number-to-string dline1))))))))
 
 ;;;###autoload
 (defun org-table-insert-row (&optional arg)