Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(centering): Caculate line length in pixel width #427

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

Merged
merged 3 commits into from
Jan 2, 2023
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
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)))
(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