From f7f83b3a73a51789f45ce0c1e1ce8ca201128437 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Thu, 21 Nov 2024 03:36:16 +0800 Subject: [PATCH 1/2] feat: Use built-in truncation symbols --- sideline.el | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/sideline.el b/sideline.el index a4cb0b0..fd387fd 100644 --- a/sideline.el +++ b/sideline.el @@ -92,11 +92,6 @@ :type 'number :group 'sideline) -(defcustom sideline-truncate-suffix "..." - "Truncation suffix." - :type 'string - :group 'sideline) - (defface sideline-default '((((background light)) :foreground "DarkOrange") (t :foreground "yellow")) @@ -201,6 +196,21 @@ (defvar-local sideline-render-this-command nil "If this is non-nil, re-render this command.") +;; +;; (@* "Obsolete" ) +;; + +(defcustom sideline-truncate-suffix "..." + "Truncation suffix." + :type 'string + :group 'sideline) + +(define-obsolete-variable-alias + 'sideline-truncate-suffix + 'truncate-string-ellipsis + "sideline 0.3.0" + "Use built-in variable instead.") + ;; ;; (@* "Externals" ) ;; @@ -270,8 +280,8 @@ (defmacro sideline--with-buffer-window (buffer-or-name &rest body) "Execute the forms in BODY with BUFFER-OR-NAME temporarily current." (declare (indent 1) (debug t)) - `(when-let (((buffer-live-p ,buffer-or-name)) - (window (get-buffer-window ,buffer-or-name))) + `(when-let* (((buffer-live-p ,buffer-or-name)) + (window (get-buffer-window ,buffer-or-name))) (with-selected-window window (with-current-buffer ,buffer-or-name ,@body)))) @@ -600,14 +610,12 @@ FACE, NAME, ON-LEFT, and ORDER for details." (let* ((win-width (sideline--render-data :win-width)) (used-space (- pos-start occ-pt)) (available-space (- win-width used-space)) - (suffix nil)) - (when (and sideline-truncate-suffix - (> available-space (sideline--render-data :suffix-width))) - (setq suffix (copy-sequence sideline-truncate-suffix)) - (set-text-properties 0 (length suffix) - (text-properties-at (1- (length title)) title) - suffix)) - (truncate-string-to-width title available-space 0 nil suffix)))) + (suffix (copy-sequence (truncate-string-ellipsis)))) + (set-text-properties 0 (length suffix) + (text-properties-at (1- (length title)) title) + suffix) + (truncate-string-to-width title available-space 0 nil + suffix)))) ;; Align left/right (str (concat (unless on-left From d2ccf5049e777c9dc6cc7cd6d8d4254f6539c00a Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Thu, 21 Nov 2024 03:36:58 +0800 Subject: [PATCH 2/2] docs: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5140a19..6a9d436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how > Released N/A * feat: Truncate long lines (#25) +* feat: Use built-in truncation symbols (#27) ## 0.2.0 > Released Aug 24, 2024