From 3719cdd48e3c580f0b0b1111467ea097265cfded Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 20 Apr 2018 11:57:37 +0200 Subject: [PATCH] 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 --- lisp/org-table.el | 12 ++++++++---- testing/lisp/test-org-table.el | 28 +++++++++++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 6616c9a12..87060feb0 100644 --- a/lisp/org-table.el +++ b/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 diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 760e6e919..ecef7ea8e 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -2371,7 +2371,7 @@ See also `test-org-table/copy-field'." (should-error (org-test-with-temp-text "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 "| a |" - (org-table-toggle-column-width) - (org-table-toggle-column-width) - (overlays-in (point-min) (point-max))))) + (org-test-with-temp-text "| 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| b |" - (org-table-toggle-column-width) - (org-table-toggle-column-width) - (overlays-in (point-min) (point-max))))) + (org-test-with-temp-text "| a |\n| 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|------|" + (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" -- 2.11.4.GIT