1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-22 18:35:09 +00:00

Use '…' for ellipsis in truncate-string-to-width by default (bug#41250)

* 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.
This commit is contained in:
Juri Linkov 2020-10-04 22:41:36 +03:00
parent 96a8e84606
commit 5ec21155c3
5 changed files with 29 additions and 14 deletions

View 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)

View File

@ -1474,6 +1474,12 @@ ledit.el, lmenu.el, lucid.el and old-whitespace.el.
* 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',

View File

@ -44,9 +44,22 @@
(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))

View 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))))

View 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.