Browse Source

Fix `org-string-display'

* lisp/org-macs.el (org-string-display): Preserve original string's
  display property when computing displayed width.

* testing/lisp/test-org-macs.el (test-org/string-display): Add test.

Reported-by: Ruy Exel <ruyexel@gmail.com>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-11/msg00160.html>
Nicolas Goaziou 7 years ago
parent
commit
40f73953f6
2 changed files with 16 additions and 11 deletions
  1. 9 10
      lisp/org-macs.el
  2. 7 1
      testing/lisp/test-org-macs.el

+ 9 - 10
lisp/org-macs.el

@@ -108,16 +108,15 @@ text properties."
 			      (value (if (stringp display) display
 				       (cl-some #'stringp display))))
 			 (when value
-			   (apply
-			    #'propertize
-			    ;; Displayed string could contain
-			    ;; invisible parts, but no nested display.
-			    (funcall prune-invisible value)
-			    (plist-put props
-				       'display
-				       (and (not (stringp display))
-					    (cl-remove-if #'stringp
-							  display)))))))))))
+			   (apply #'propertize
+				  ;; Displayed string could contain
+				  ;; invisible parts, but no nested
+				  ;; display.
+				  (funcall prune-invisible value)
+				  'display
+				  (and (not (stringp display))
+				       (cl-remove-if #'stringp display))
+				  props))))))))
     ;; `display' property overrides `invisible' one.  So we first
     ;; replace characters with `display' property.  Then we remove
     ;; invisible characters.

+ 7 - 1
testing/lisp/test-org-macs.el

@@ -68,7 +68,13 @@
    (eq 'foo
        (get-text-property 1 'face
 			  (org-string-display
-			   #("123" 1 2 (display "abc" face foo)))))))
+			   #("123" 1 2 (display "abc" face foo))))))
+  ;; Also preserve `display' property in original string.
+  (should
+   (equal "abc"
+	  (let ((s #("123" 1 2 (display "abc" face foo))))
+	    (org-string-display s)
+	    (get-text-property 1 'display s)))))
 
 
 (provide 'test-org-macs)