[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 9ab3081959 26/84: Add string-pixel-width from Em
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 9ab3081959 26/84: Add string-pixel-width from Emacs 29 |
Date: |
Tue, 3 Jan 2023 08:57:32 -0500 (EST) |
branch: externals/compat
commit 9ab3081959fd47d368e216c41c4f6d6875fd095b
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add string-pixel-width from Emacs 29
---
compat-29.el | 12 ++++++++++++
compat.texi | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/compat-29.el b/compat-29.el
index 757f9e76ee..4389289105 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -311,5 +311,17 @@ than this function."
(end (substring string (- (length string) length)))
(t (substring string 0 length)))))
+;;* UNTESTED
+(compat-defun string-pixel-width (string)
+ "Return the width of STRING in pixels."
+ (if (zerop (length string))
+ 0
+ ;; Keeping a work buffer around is more efficient than creating a
+ ;; new temporary buffer.
+ (with-current-buffer (get-buffer-create " *string-pixel-width*")
+ (delete-region (point-min) (point-max))
+ (insert string)
+ (car (compat--buffer-text-pixel-size nil nil t)))))
+
(provide 'compat-29)
;;; compat-29.el ends here
diff --git a/compat.texi b/compat.texi
index c1e61be279..f19c884df5 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2446,6 +2446,41 @@ optional @code{buffer-list} argument. Optional third
argument
@xref{Buffer List,,,elisp}.
@end defun
+@c copied from lispref/display.texi
+@defun string-pixel-width string
+This is a convenience function that uses @code{window-text-pixel-size}
+to compute the width of @var{string} (in pixels).
+
+@xref{Size of Displayed Text,,,elisp}.
+@end defun
+
+@c copied from lispref/display.texi
+@defun string-glyph-split string
+When character compositions are in effect, sequence of characters can
+be composed for display to form @emph{grapheme clusters}, for example
+to display accented characters, or ligatures, or Emoji, or when
+complex text shaping requires that for some scripts. When that
+happens, characters no longer map in a simple way to display columns,
+and display layout decisions with such strings, such as truncating too
+wide strings, can be a complex job. This function helps in performing
+suvh jobs: it splits up its argument @var{string} into a list of
+substrings, where each substring produces a single grapheme cluster
+that should be displayed as a unit. Lisp programs can then use this
+list to construct visually-valid substrings of @var{string} which will
+look correctly on display, or compute the width of any substring of
+@var{string} by adding the width of its constituents in the returned
+list, etc.
+
+For instance, if you want to display a string without the first glyph,
+you can say:
+
+@example
+(apply #'insert (cdr (string-glyph-split string))))
+@end example
+
+@xref{Size of Displayed Text,,,elisp}.
+@end defun
+
@subsection Prefixed Definitions
- [elpa] externals/compat 9e0eb5b72f 33/84: Add compat-declare-version to compat-29.el, (continued)
- [elpa] externals/compat 9e0eb5b72f 33/84: Add compat-declare-version to compat-29.el, ELPA Syncer, 2023/01/03
- [elpa] externals/compat fdae099b00 34/84: Move if-let and related function from subr-x to subr, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 6ac6ed2a99 36/84: Use make-symbol instead of gensym in function-alias-p tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ef5246cf55 38/84: Fix issues related to 'expect' tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0a84a7c219 48/84: Add add-display-text-property from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e6d279af18 14/84: Extend byte-compile-docstring-max-column to 100, ELPA Syncer, 2023/01/03
- [elpa] externals/compat c177ff5e83 17/84: Reuse ntake in take definition, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0de389aca6 19/84: Add string-equal-ignore-case from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ff331f6c29 22/84: Add prefixed plist-put from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9aac0f55d1 23/84: Add prefixed plist-member from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9ab3081959 26/84: Add string-pixel-width from Emacs 29,
ELPA Syncer <=
- [elpa] externals/compat d375504e3c 27/84: Add with-buffer-unmodified-if-unchanged from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ded0f01036 40/84: Revert "Fix gv-expander for compat-alist-get", ELPA Syncer, 2023/01/03
- [elpa] externals/compat 878221eabd 44/84: Update the commentary section for compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 4a56adbcdf 42/84: Remove references to the deleted "Emacs 24.5" node, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0c14c42bc1 50/84: Copy edebug specifications instead of referencing, ELPA Syncer, 2023/01/03
- [elpa] externals/compat b888c2fb49 53/84: Replace when-let with expansions in compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 59cd42a912 60/84: Generate test names without double-dashes, ELPA Syncer, 2023/01/03
- [elpa] externals/compat b0f8f6eaac 61/84: Remove realname for ntake, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 45028d9fa7 64/84: Merge branch 'master' into emacs-29.1, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 68c6ccd5cc 68/84: Always load compat-macs, ELPA Syncer, 2023/01/03