]> git.eshelyaron.com Git - emacs.git/commitdiff
Use '…' for ellipsis in truncate-string-to-width by default (bug#41250)
authorJuri Linkov <juri@linkov.net>
Sun, 4 Oct 2020 19:41:36 +0000 (22:41 +0300)
committerJuri Linkov <juri@linkov.net>
Sun, 4 Oct 2020 19:41:36 +0000 (22:41 +0300)
* lisp/international/mule-util.el (truncate-string-ellipsis):
Change the default value to nil.
(truncate-string-ellipsis): New function.
(truncate-string-to-width): Use the value returned from the
function 'truncate-string-ellipsis'.

* lisp/tab-bar.el (tab-bar-tab-name-truncated):
* lisp/tab-line.el (tab-line-tab-name-ellipsis):
Take advantage of the improvement of the ellipsis default value
in truncate-string-to-width and truncate-string-ellipsis.

* doc/lispref/display.texi (Size of Displayed Text):
Improve description of truncate-string-ellipsis.

doc/lispref/display.texi
etc/NEWS
lisp/international/mule-util.el
lisp/tab-bar.el
lisp/tab-line.el

index 7d1c14c8169a39d5c63a644a84e72658dd947189..a70f61e43e2e0b2c8a08e220a76e24ed14a6f512 100644 (file)
@@ -1999,7 +1999,8 @@ replace the end of @var{string} (including any padding) if it extends
 beyond @var{width}, unless the display width of @var{string} is equal
 to or less than the display width of @var{ellipsis}.  If
 @var{ellipsis} is non-@code{nil} and not a string, it stands for
-the value of the variable @code{truncate-string-ellipsis}.
+the value of the variable @code{truncate-string-ellipsis}, or
+to three dots when it's nil.
 
 @example
 (truncate-string-to-width "\tab\t" 12 4)
index 88957fb01a9a00422d180d63486c8a06da8f480e..d67156194a2d38bec209acc036814c7197ad0706 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1474,6 +1474,12 @@ ledit.el, lmenu.el, lucid.el and old-whitespace.el.
 \f
 * Lisp Changes in Emacs 28.1
 
++++
+** 'truncate-string-ellipsis' uses the character '…' by default.
+Modes that use 'truncate-string-to-width' with non-nil non-string
+argument 'ellipsis', now indicate truncation using '…' when
+the selected frame can display it, and "..." otherwise.
+
 +++
 *** New command 'make-directory-autoloads'.
 This does the same as the old command 'update-directory-autoloads',
index 660ac58e0227835cb39c8584eab8015c832ea9f4..d792b2530c4792931fdd82fa0ad329e911f4e868 100644 (file)
        (setq i (1+ i)))))
   string)
 
-(defvar truncate-string-ellipsis "..."  ;"…"
+(defvar truncate-string-ellipsis nil
   "String to use to indicate truncation.
-Serves as default value of ELLIPSIS argument to `truncate-string-to-width'.")
+Serves as default value of ELLIPSIS argument to `truncate-string-to-width'
+returned by the function `truncate-string-ellipsis'.")
+
+(defun truncate-string-ellipsis ()
+  "Return a string to use to indicate truncation.
+Use the value of the variable `truncate-string-ellipsis' when it's non-nil.
+Otherwise, return `…' when it's displayable on the selected frame,
+or `...'.  This function needs to be called on every use of
+`truncate-string-to-width' to decide whether the selected frame
+can display the character `…'."
+  (cond
+   (truncate-string-ellipsis)
+   ((char-displayable-p ?…) "…")
+   ("...")))
 
 ;;;###autoload
 (defun truncate-string-to-width (str end-column
@@ -73,7 +86,7 @@ If ELLIPSIS is non-nil, it should be a string which will replace the
 end of STR (including any padding) if it extends beyond END-COLUMN,
 unless the display width of STR is equal to or less than the display
 width of ELLIPSIS.  If it is non-nil and not a string, then ELLIPSIS
-defaults to `truncate-string-ellipsis'.
+defaults to `truncate-string-ellipsis', or to three dots when it's nil.
 
 If ELLIPSIS-TEXT-PROPERTY is non-nil, a too-long string will not
 be truncated, but instead the elided parts will be covered by a
@@ -81,7 +94,7 @@ be truncated, but instead the elided parts will be covered by a
   (or start-column
       (setq start-column 0))
   (when (and ellipsis (not (stringp ellipsis)))
-    (setq ellipsis truncate-string-ellipsis))
+    (setq ellipsis (truncate-string-ellipsis)))
   (let ((str-len (length str))
        (str-width (string-width str))
        (ellipsis-width (if ellipsis (string-width ellipsis) 0))
index 9c6b9cbc048d61e3d56d28c8d35de90160649c0f..2604955224261993b17858b39817fd2a2b90241d 100644 (file)
@@ -363,22 +363,18 @@ to `tab-bar-tab-name-truncated'."
   :group 'tab-bar
   :version "27.1")
 
-(defvar tab-bar-tab-name-ellipsis nil)
+(defvar tab-bar-tab-name-ellipsis t)
 
 (defun tab-bar-tab-name-truncated ()
   "Generate tab name from the buffer of the selected window.
 Truncate it to the length specified by `tab-bar-tab-name-truncated-max'.
 Append ellipsis `tab-bar-tab-name-ellipsis' in this case."
-  (let ((tab-name (buffer-name (window-buffer (minibuffer-selected-window))))
-        (ellipsis (cond
-                   (tab-bar-tab-name-ellipsis)
-                   ((char-displayable-p ?…) "…")
-                   ("..."))))
+  (let ((tab-name (buffer-name (window-buffer (minibuffer-selected-window)))))
     (if (< (length tab-name) tab-bar-tab-name-truncated-max)
         tab-name
       (propertize (truncate-string-to-width
                    tab-name tab-bar-tab-name-truncated-max nil nil
-                   ellipsis)
+                   tab-bar-tab-name-ellipsis)
                   'help-echo tab-name))))
 
 \f
index 8da554a326750ce267b88c143babea39a9f5922f..46bf89f14eb7c2b3013f14f3f2bfe8684cf3c2c5 100644 (file)
@@ -240,8 +240,7 @@ to `tab-line-tab-name-truncated-buffer'."
   :group 'tab-line
   :version "27.1")
 
-(defvar tab-line-tab-name-ellipsis
-  (if (char-displayable-p ?…) "…" "..."))
+(defvar tab-line-tab-name-ellipsis t)
 
 (defun tab-line-tab-name-truncated-buffer (buffer &optional _buffers)
   "Generate tab name from BUFFER.