Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use built-in truncation symbols #27

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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