Browse Source

org-table: Fix shrunk columns on hlines

* lisp/org-table.el (org-table--shrunk-field): Fix function when on
  a hline.
* testing/lisp/test-org-table.el (test-org-table/shrunk-columns): Add
  tests.

Reported-by: Kaushal Modi <kaushal.modi@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-02/msg00231.html>
Nicolas Goaziou 1 year ago
parent
commit
58da7d4d17
2 changed files with 42 additions and 2 deletions
  1. 3 1
      lisp/org-table.el
  2. 39 1
      testing/lisp/test-org-table.el

+ 3 - 1
lisp/org-table.el

@@ -3842,7 +3842,9 @@ When non-nil, return the overlay narrowing the field."
 	     (and (eq 'table-column-hide (overlay-get o 'org-overlay-type))
 		  o))
 	   (overlays-at (save-excursion
-			  (skip-chars-forward "^|" (line-end-position))
+			  (skip-chars-forward (if (org-at-table-hline-p) "^+|"
+						"^|")
+					      (line-end-position))
 			  (1- (point))))))
 
 (defun org-table--list-shrunk-columns ()

+ 39 - 1
testing/lisp/test-org-table.el

@@ -2591,7 +2591,45 @@ See also `test-org-table/copy-field'."
 	    (org-table-toggle-column-width)
 	    (org-table-get-field nil "b")
 	    (mapcar (lambda (o) (overlay-get o 'help-echo))
-		    (overlays-in (point-min) (point-max)))))))
+		    (overlays-in (point-min) (point-max))))))
+  ;; Moving to next field doesn't change shrunk state.
+  (should
+   (equal "a"
+	  (org-test-with-temp-text "| <point>a | b |"
+	    (org-table-toggle-column-width)
+	    (org-table-next-field)
+	    (overlay-get (car (overlays-at (1+ (line-beginning-position))))
+			 'help-echo))))
+  (should
+   (equal "b"
+	  (org-test-with-temp-text "| a | <point>b |"
+	    (org-table-toggle-column-width)
+	    (goto-char 2)
+	    (org-table-next-field)
+	    (overlay-get (car (overlays-at (point))) 'help-echo))))
+  ;; Aligning table doesn't alter shrunk state.
+  (should
+   (equal "a"
+	  (org-test-with-temp-text "| <point>a | b   |"
+	    (org-table-toggle-column-width)
+	    (org-table-align)
+	    (overlay-get (car (overlays-at (1+ (line-beginning-position))))
+			 'help-echo))))
+  (should
+   (equal "b"
+	  (org-test-with-temp-text "|---+-----|\n| a | <point>b   |"
+	    (org-table-toggle-column-width)
+	    (org-table-align)
+	    (overlay-get (car (overlays-at (point)))
+			 'help-echo))))
+  (should
+   (equal
+    '("b")
+    (org-test-with-temp-text "|---+-----|\n| a | <point>b   |"
+      (org-table-toggle-column-width)
+      (org-table-align)
+      (mapcar (lambda (o) (overlay-get o 'help-echo))
+	      (overlays-in (line-beginning-position) (line-end-position)))))))