Skip to content

Commit

Permalink
fix(centering): Caculate line length in pixel width (#427)
Browse files Browse the repository at this point in the history
* fix(centering): Caculate line length in pixel width

* changelog

* fix compile warnings
  • Loading branch information
jcs090218 committed Jan 2, 2023
1 parent 5bb17b8 commit 594f2d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
((emacs-lisp-mode . ((indent-tabs-mode . nil)
(fill-column . 100)
(fill-column . 80)
(elisp-lint-indent-specs . ((when-let . 1))))))
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Fix dashboard not showing up in daemon mode (#382)
* Calculate truncate path length in pixel (#402)
* Center banner with properties and combine text with image (#407)
* Caculate line length in pixel width (#427)

## 1.7.0
> Released Feb 21, 2020
Expand Down
19 changes: 12 additions & 7 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ preserved."

(defcustom dashboard-navigator-buttons nil
"Specify the navigator buttons.
The format is: 'icon title help action face prefix suffix'.
The format is: `icon title help action face prefix suffix`.
Example:
'((\"\" \"Star\" \"Show stars\" (lambda (&rest _)
(show-stars)) 'warning \"[\" \"]\"))"
`((\"\" \"Star\" \"Show stars\" (lambda (&rest _)
(show-stars)) warning \"[\" \"]\"))"
:type '(repeat (repeat (list string string string function symbol string string)))
:group 'dashboard)

Expand Down Expand Up @@ -388,7 +388,7 @@ If nil it is disabled. Possible values for list-type are:

(defun dashboard-str-len (str)
"Calculate STR in pixel width."
(let ((width (window-font-width))
(let ((width (frame-char-width))
(len (dashboard-string-pixel-width str)))
(+ (/ len width)
(if (zerop (% len width)) 0 1)))) ; add one if exceeed
Expand Down Expand Up @@ -496,7 +496,8 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer."
(goto-char start)
(let ((width 0))
(while (< (point) end)
(let ((line-length (- (line-end-position) (line-beginning-position))))
(let* ((line-str (buffer-substring (line-beginning-position) (line-end-position)))

This comment has been minimized.

Copy link
@ThibaultGH

ThibaultGH Jan 7, 2023

I have reported an issue on the repo concerning a bug that f* up the centering and think the bug might be here, but not really sure cause I'm not a elisp programmer. Here is a link to the issue :
#430

This comment has been minimized.

Copy link
@jcs090218

jcs090218 Jan 7, 2023

Author Member

Can you try to revert these lines and see if that fixed your issue? 😕

(line-length (dashboard-str-len line-str)))
(setq width (max width line-length)))
(forward-line 1))
(let ((prefix (propertize " " 'display `(space . (:align-to (- center ,(/ width 2)))))))
Expand Down Expand Up @@ -687,6 +688,7 @@ Argument IMAGE-PATH path to the image."

(defmacro dashboard-insert-section (section-name list list-size shortcut-id shortcut-char action &rest widget-params)
"Add a section with SECTION-NAME and LIST of LIST-SIZE items to the dashboard.
SHORTCUT-CHAR is the keyboard shortcut used to access the section.
ACTION is theaction taken when the user activates the widget button.
WIDGET-PARAMS are passed to the \"widget-create\" function."
Expand Down Expand Up @@ -1247,21 +1249,24 @@ This is what `org-agenda-exit' do."

(defun dashboard-agenda--sorted-agenda ()
"Return agenda sorted by time.
For now, it only works when dashboard-agenda has been filter by time
and dashboard-agenda-sort is not nil."
For now, it only works when dashboard-agenda has been filter by time and
dashboard-agenda-sort is not nil."
(let ((agenda (dashboard-get-agenda))
(sort-function (dashboard-agenda--sort-function)))
(sort agenda sort-function)))

(defun dashboard-agenda--sort-function ()
"Get the function use to sorted the agenda.
Depending on the list `dashboard-agenda-sorting-strategy' use this strategies to
build a predicate to compare each enty.
This is similar as `org-entries-lessp' but with a different aproach."
(dashboard-agenda--build-sort-function dashboard-agenda-sort-strategy))

(defun dashboard-agenda--build-sort-function (strategies)
"Build a predicate to sort the dashboard agenda.
If `STRATEGIES' is nil then sort using the nil predicate. Look for the strategy
predicate, the attributes of the entry and compare entries. If no predicate is
found for the strategy it uses nil predicate."
Expand Down

0 comments on commit 594f2d9

Please sign in to comment.