浏览代码

org-table: Fix shrunk hlines

* lisp/org-table.el (org-table--shrink-field): Handle properly shrunk
  hlines with a width cookie.
* testing/lisp/test-org-table.el (test-org-table/toggle-column-width):
  Add test.  Fix tests.

Reported-by: William Denton <wtd@pobox.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-04/msg00306.html>
Nicolas Goaziou 7 年之前
父节点
当前提交
3719cdd48e
共有 2 个文件被更改,包括 25 次插入15 次删除
  1. 8 4
      lisp/org-table.el
  2. 17 11
      testing/lisp/test-org-table.el

+ 8 - 4
lisp/org-table.el

@@ -3937,13 +3937,17 @@ Return a list of overlays hiding the field, or nil if field is
 already hidden."
   (cond
    ((org-table--shrunk-field) nil)	;already shrunk: bail out
-   ((eq contents 'hline)		;no contents to hide
-    (list (org-table--make-shrinking-overlay
-	   (+ start width 1) end org-table-shrunk-column-indicator contents)))
    ((or (= 0 width)			;shrink to one character
 	(>= 1 (org-string-width (buffer-substring start end))))
     (list (org-table--make-shrinking-overlay
-	   start end org-table-shrunk-column-indicator contents)))
+	   start end org-table-shrunk-column-indicator
+	   (if (eq 'hline contents) "" contents))))
+   ((eq contents 'hline)		;no contents to hide
+    (list (org-table--make-shrinking-overlay
+	   start end
+	   (concat (make-string (max 0 (1+ width)) ?-)
+		   org-table-shrunk-column-indicator)
+	   "")))
    (t
     ;; If the field is not empty, consider using two overlays: one for
     ;; the blanks at the beginning of the field, and another one at

+ 17 - 11
testing/lisp/test-org-table.el

@@ -2371,7 +2371,7 @@ See also `test-org-table/copy-field'."
   (should-error
    (org-test-with-temp-text "<point>a"
      (org-table-toggle-column-width)))
-  ;; A shrunk columns is overlaid with
+  ;; A shrunk column is overlaid with
   ;; `org-table-shrunk-column-indicator'.
   (should
    (equal org-table-shrunk-column-indicator
@@ -2392,17 +2392,15 @@ See also `test-org-table/copy-field'."
 			 'display))))
   ;; When column is already shrunk, expand it, i.e., remove overlays.
   (should-not
-   (equal org-table-shrunk-column-indicator
-	  (org-test-with-temp-text "| <point>a |"
-	    (org-table-toggle-column-width)
-	    (org-table-toggle-column-width)
-	    (overlays-in (point-min) (point-max)))))
+   (org-test-with-temp-text "| <point>a |"
+     (org-table-toggle-column-width)
+     (org-table-toggle-column-width)
+     (overlays-in (point-min) (point-max))))
   (should-not
-   (equal org-table-shrunk-column-indicator
-	  (org-test-with-temp-text "| a |\n| <point>b |"
-	    (org-table-toggle-column-width)
-	    (org-table-toggle-column-width)
-	    (overlays-in (point-min) (point-max)))))
+   (org-test-with-temp-text "| a |\n| <point>b |"
+     (org-table-toggle-column-width)
+     (org-table-toggle-column-width)
+     (overlays-in (point-min) (point-max))))
   ;; With a column width cookie, limit overlay to the specified number
   ;; of characters.
   (should
@@ -2421,6 +2419,14 @@ See also `test-org-table/copy-field'."
 			      (overlay-start
 			       (car (overlays-in (line-beginning-position)
 						 (line-end-position))))))))
+  (should
+   (equal (concat "----" org-table-shrunk-column-indicator)
+	  (org-test-with-temp-text "| <3>  |\n|--<point>----|"
+	    (org-table-toggle-column-width)
+	    (overlay-get
+	     (car (overlays-in (line-beginning-position)
+			       (line-end-position)))
+	     'display))))
   ;; Width only takes into account visible characters.
   (should
    (equal "| [[http"