From b66ec8a0466b6f0b2dbb1cd3fa3e2ed17b457362 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Tue, 3 Jan 2023 01:33:56 +0800 Subject: [PATCH 1/3] fix(centering): Caculate line length in pixel width --- dashboard-widgets.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 530462b..c2daeb8 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -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 @@ -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))))))) From c7606599798c10f1e8b2601ea9a486ade78b5491 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Tue, 3 Jan 2023 01:36:34 +0800 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dda7fe2..23f35c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 02c59506ff08ef90aa4aaa436d3d83237044fcfb Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Tue, 3 Jan 2023 01:48:43 +0800 Subject: [PATCH 3/3] fix compile warnings --- .dir-locals.el | 2 +- dashboard-widgets.el | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.dir-locals.el b/.dir-locals.el index 383b4a6..9edffdd 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,3 +1,3 @@ ((emacs-lisp-mode . ((indent-tabs-mode . nil) - (fill-column . 100) + (fill-column . 80) (elisp-lint-indent-specs . ((when-let . 1)))))) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index c2daeb8..8e2e8b9 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -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) @@ -688,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." @@ -1248,14 +1249,16 @@ 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." @@ -1263,6 +1266,7 @@ This is similar as `org-entries-lessp' but with a different aproach." (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."