Skip to content

Commit

Permalink
feat: Use built-in truncation symbols (#27)
Browse files Browse the repository at this point in the history
* feat: Use built-in truncation symbols

* docs: changelog
  • Loading branch information
jcs090218 authored Nov 20, 2024
1 parent 56d4a85 commit 0307db5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 23 additions & 15 deletions sideline.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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" )
;;
Expand Down Expand Up @@ -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))))

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0307db5

Please sign in to comment.