From 872f339ddd7eca6f38c79d197a3721ee6de6a1df Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Thu, 23 Sep 2021 02:23:23 -0500 Subject: [PATCH 1/9] Dashboard agenda sort by time --- dashboard-widgets.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 30fe1d44..0ef5adf0 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1056,8 +1056,9 @@ is todays date format." "Format agenda entry to show it on dashboard." (let* ((schedule-time (org-get-scheduled-time (point))) (deadline-time (org-get-deadline-time (point))) + (entry-time (or schedule-time deadline-time)) (item (org-agenda-format-item - (dashboard-agenda-entry-time (or schedule-time deadline-time)) + (dashboard-agenda-entry-time entry-time) (org-get-heading) (org-outline-level) (org-get-category) @@ -1066,7 +1067,7 @@ is todays date format." (loc (point)) (file (buffer-file-name))) (dashboard-agenda--set-agenda-headline-face item) - (list item loc file))) + (list item loc file (list (cons 'time entry-time))))) (defun dashboard-agenda--set-agenda-headline-face (headline) "Set agenda faces to `HEADLINE' when face text property is nil." @@ -1144,15 +1145,24 @@ This is what `org-agenda-exit' do." (org-release-buffers org-agenda-new-buffers) (setq org-agenda-new-buffers nil))) +(defun dashboard-agenda-entry-sort (entry1 entry2) + (let ((time1 (alist-get 'time (nth 3 entry1))) + (time2 (alist-get 'time (nth 3 entry2)))) + (org-time-less-p time1 time2))) + (defun dashboard-insert-agenda (list-size) "Add the list of LIST-SIZE items of agenda." (require 'org-agenda) - (let ((agenda (dashboard-get-agenda))) + (let* ((agenda (dashboard-get-agenda)) + (sorted-agenda (if (eq dashboard-filter-agenda-entry + 'dashboard-filter-agenda-by-time) + (sort agenda 'dashboard-agenda-entry-sort) + agenda))) (dashboard-insert-section (if dashboard-week-agenda "Agenda for the coming week:" "Agenda for today:") - agenda + sorted-agenda list-size (dashboard-get-shortcut 'agenda) `(lambda (&rest ignore) From 650bc172656c7a78fc7c2a11dc5e9fa2e7098267 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Mon, 11 Oct 2021 22:09:12 -0500 Subject: [PATCH 2/9] Fix schedule-time typo --- dashboard-widgets.el | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 0ef5adf0..69d6ea5e 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1041,22 +1041,22 @@ It is the MATCH attribute for `org-map-entries'" :type 'boolean :group 'dashboard) -(defun dashboard-agenda-entry-time (schedule-time) - "Format SCHEDULE-TIME with custom format. -If SCHEDULE-TIME is nil returns a blank string which length +(defun dashboard-agenda-entry-time (entry-time) + "Format ENTRY-TIME with custom format. +If ENTRY-TIME is nil returns a blank string which length is todays date format." - (let* ((time (or schedule-time (org-today))) + (let* ((time (or entry-time (org-today))) (formated-time (format-time-string dashboard-agenda-time-string-format time))) - (if schedule-time + (if entry-time formated-time (replace-regexp-in-string "." " " formated-time)))) (defun dashboard-agenda-entry-format () "Format agenda entry to show it on dashboard." - (let* ((schedule-time (org-get-scheduled-time (point))) + (let* ((scheduled-time (org-get-scheduled-time (point))) (deadline-time (org-get-deadline-time (point))) - (entry-time (or schedule-time deadline-time)) + (entry-time (or scheduled-time deadline-time)) (item (org-agenda-format-item (dashboard-agenda-entry-time entry-time) (org-get-heading) @@ -1095,15 +1095,15 @@ Do nothing if `TEXT' has already a face property or is nil." (time-add (current-time) 86400))) (defun dashboard-filter-agenda-by-time () - "Include entry if it has a schedule-time or deadline-time in the future. + "Include entry if it has a scheduled-time or deadline-time in the future. An entry is included if this function returns nil and excluded if returns a point." - (let ((schedule-time (org-get-scheduled-time (point))) + (let ((scheduled-time (org-get-scheduled-time (point))) (deadline-time (org-get-deadline-time (point))) (due-date (dashboard-due-date-for-agenda))) (unless (and (not (org-entry-is-done-p)) - (or (and schedule-time - (org-time-less-p schedule-time due-date)) + (or (and scheduled-time + (org-time-less-p scheduled-time due-date)) (and deadline-time (org-time-less-p deadline-time due-date)))) (point)))) From 790bb7c4b0a2adf8a6cb479b16584b9d16a48b88 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Thu, 21 Oct 2021 18:19:56 -0500 Subject: [PATCH 3/9] Dashboard sort strategy --- dashboard-widgets.el | 46 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 69d6ea5e..a209ad0a 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1041,6 +1041,11 @@ It is the MATCH attribute for `org-map-entries'" :type 'boolean :group 'dashboard) +(defcustom dashboard-agenda-sort-strategy () + "If not nil agenda is sorted." + :type 'list + :group 'dashboard) + (defun dashboard-agenda-entry-time (entry-time) "Format ENTRY-TIME with custom format. If ENTRY-TIME is nil returns a blank string which length @@ -1145,24 +1150,41 @@ This is what `org-agenda-exit' do." (org-release-buffers org-agenda-new-buffers) (setq org-agenda-new-buffers nil))) -(defun dashboard-agenda-entry-sort (entry1 entry2) - (let ((time1 (alist-get 'time (nth 3 entry1))) - (time2 (alist-get 'time (nth 3 entry2)))) - (org-time-less-p time1 time2))) +(defun dashboard-agenda--sorted-agenda () + "Returns agenda sorted by time. +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 `dashboard-agenda-sorting-strategy'. +This is similar as `org-entries-lessp' but with a different aproach." + (dashboard-agenda--guess-sort-function dashboard-agenda-sort-strategy)) + +(defun dashboard-agenda--guess-sort-function (strategies) + "Get the function to compare entries based on strategies." + (cond + ((null strategies) (lambda (dont care) nil)) + ((eq 'time-up (car strategies)) (lambda (entry1 entry2) + (let ((time1 (alist-get 'time (nth 3 entry1))) + (time2 (alist-get 'time (nth 3 entry2)))) + (org-time-less-p time1 time2)))) + ((eq 'time-down (car strategies)) (lambda (entry1 entry2) + (let ((time1 (alist-get 'time (nth 3 entry1))) + (time2 (alist-get 'time (nth 3 entry2)))) + (org-time-less-p time2 time1)))) + (t (lambda (dont care) nil)))) (defun dashboard-insert-agenda (list-size) "Add the list of LIST-SIZE items of agenda." (require 'org-agenda) - (let* ((agenda (dashboard-get-agenda)) - (sorted-agenda (if (eq dashboard-filter-agenda-entry - 'dashboard-filter-agenda-by-time) - (sort agenda 'dashboard-agenda-entry-sort) - agenda))) - (dashboard-insert-section + (dashboard-insert-section (if dashboard-week-agenda "Agenda for the coming week:" "Agenda for today:") - sorted-agenda + (dashboard-agenda--sorted-agenda) list-size (dashboard-get-shortcut 'agenda) `(lambda (&rest ignore) @@ -1170,7 +1192,7 @@ This is what `org-agenda-exit' do." (with-current-buffer buffer (goto-char (nth 1 ',el)) (switch-to-buffer buffer)))) - (format "%s" (nth 0 el))))) + (format "%s" (nth 0 el)))) ;; ;; Registers From 83a9b6a75724fdcb0ed2bb2251674f3910892846 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Thu, 21 Oct 2021 22:56:56 -0500 Subject: [PATCH 4/9] Dashboard agenda sort with todo-state strategies --- dashboard-widgets.el | 46 +++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index a209ad0a..c4575403 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1072,7 +1072,10 @@ is todays date format." (loc (point)) (file (buffer-file-name))) (dashboard-agenda--set-agenda-headline-face item) - (list item loc file (list (cons 'time entry-time))))) + (list item loc file (list (cons 'time entry-time) + (cons 'todo-index (and (org-get-todo-state) + (length (member (org-get-todo-state) + org-todo-keywords-1)))))))) (defun dashboard-agenda--set-agenda-headline-face (headline) "Set agenda faces to `HEADLINE' when face text property is nil." @@ -1161,22 +1164,43 @@ and dashboard-agenda-sort is not nil." (defun dashboard-agenda--sort-function () "Get the function use to sorted the agenda depending on `dashboard-agenda-sorting-strategy'. This is similar as `org-entries-lessp' but with a different aproach." - (dashboard-agenda--guess-sort-function dashboard-agenda-sort-strategy)) + (dashboard-agenda--build-sort-function dashboard-agenda-sort-strategy)) -(defun dashboard-agenda--guess-sort-function (strategies) +(defun dashboard-agenda--build-sort-function (strategies) "Get the function to compare entries based on strategies." (cond ((null strategies) (lambda (dont care) nil)) - ((eq 'time-up (car strategies)) (lambda (entry1 entry2) - (let ((time1 (alist-get 'time (nth 3 entry1))) - (time2 (alist-get 'time (nth 3 entry2)))) - (org-time-less-p time1 time2)))) - ((eq 'time-down (car strategies)) (lambda (entry1 entry2) - (let ((time1 (alist-get 'time (nth 3 entry1))) - (time2 (alist-get 'time (nth 3 entry2)))) - (org-time-less-p time2 time1)))) + ((eq 'time-up (car strategies)) + (lambda (entry1 entry2) + (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) + :with 'org-time-less-p :by 'time))) + ((eq 'time-down (car strategies)) + (lambda (entry1 entry2) + (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) + :with (lambda (a b) (org-time-less-p b a)) :by 'time))) + ((eq 'todo-state-up (car strategies)) + (lambda (entry1 entry2) + (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) + :with '> :by 'todo-index))) + ((eq 'todo-state-down (car strategies)) + (lambda (entry1 entry2) + (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) + :with '< :by 'todo-index))) (t (lambda (dont care) nil)))) +(defun dashboard-agenda--compare-entries (entry1 entry2 strategies :with comparator :by attribute) + "Compare entries using comparator as a function and getting attributes form list." + (let ((arg1 (alist-get attribute (nth 3 entry1))) + (arg2 (alist-get attribute (nth 3 entry2)))) + (cond + ((or (and (null arg1) (null arg2)) + (equal arg1 arg2)) + (apply (dashboard-agenda--build-sort-function strategies) + (list entry1 entry2))) + ((null arg1) nil) + ((null arg2) t) + (t (apply comparator (list arg1 arg2)))))) + (defun dashboard-insert-agenda (list-size) "Add the list of LIST-SIZE items of agenda." (require 'org-agenda) From 812167782889f5155f411adc0bde77f1d2412720 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Fri, 22 Oct 2021 13:42:04 -0500 Subject: [PATCH 5/9] Readme modifications for agenda sort. --- README.org | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index a2a96ab6..3a63a45a 100644 --- a/README.org +++ b/README.org @@ -217,6 +217,12 @@ Once the agenda appears in the dashboard, ~org-agenda-files~ stay open. With ~(setq dashboard-agenda-release-buffers t)~ the org files are close. Note that this could slow down the dashboard buffer refreshment. +*** Agenda sort + +Agenda is now sorted with ~dashboard-agenda-sort-strategy~ following +the idea of [[https://orgmode.org/worg/doc.html#org-agenda-sorting-strategy][org-agenda-sorting-strategy]]. Suported strategies are +~time-up~, ~time-down~, ~todo-state-up~ and ~todo-state-down~ + ** Faces It is possible to customize Dashboard's appearance using the following faces: @@ -284,4 +290,3 @@ make install ** Prerequisites * [[https://github.com/cask/cask][Cask]] - From 866e2f60088b2e1a54d7d607d1d0b54be4b910c0 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Fri, 22 Oct 2021 16:28:06 -0500 Subject: [PATCH 6/9] Refactor sort function. --- dashboard-widgets.el | 47 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index c4575403..5801f69e 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1167,26 +1167,32 @@ 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) - "Get the function to compare entries based on strategies." + "Build a function to sort the dashboard agenda. +If `STRATEGIES' is nil then sort by the constant nil and don't do anything. Look for the strategy comparator +and the attributes of the entry and compare entries. If no comparator is found then sort by constant nil." + (if (null strategies) (lambda (dont care) nil) + (let ((comparator (dashboard-agenda--build-sort-function-comparator (car strategies))) + (attribute (dashboard-agenda--build-sort-function-attribute (car strategies)))) + (if (null comparator) (lambda (dont care) nil) + (lambda (entry1 entry2) + (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) + :with comparator :by attribute)))))) + +(defun dashboard-agenda--build-sort-function-comparator (strategy) + "Depends on the `STRATEGY' it returns a function to compare two dashboard-agenda entries." (cond - ((null strategies) (lambda (dont care) nil)) - ((eq 'time-up (car strategies)) - (lambda (entry1 entry2) - (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) - :with 'org-time-less-p :by 'time))) - ((eq 'time-down (car strategies)) - (lambda (entry1 entry2) - (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) - :with (lambda (a b) (org-time-less-p b a)) :by 'time))) - ((eq 'todo-state-up (car strategies)) - (lambda (entry1 entry2) - (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) - :with '> :by 'todo-index))) - ((eq 'todo-state-down (car strategies)) - (lambda (entry1 entry2) - (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) - :with '< :by 'todo-index))) - (t (lambda (dont care) nil)))) + ((eq 'time-up strategy) 'org-time-less-p) + ((eq 'time-down strategy) (lambda (a b) (org-time-less-p b a))) + ((eq 'todo-state-up strategy) '>) + ((eq 'todo-state-down strategy) '<) + (t nil))) + +(defun dashboard-agenda--build-sort-function-attribute (strategy) + "Depends on the `STRATEGY' it returns a function to compare two dashboard-agenda entries." + (cond + ((memq strategy '(time-up time-down)) 'time) + ((memq strategy '(todo-state-up todo-state-down)) 'todo-index) + (t nil))) (defun dashboard-agenda--compare-entries (entry1 entry2 strategies :with comparator :by attribute) "Compare entries using comparator as a function and getting attributes form list." @@ -1195,8 +1201,7 @@ This is similar as `org-entries-lessp' but with a different aproach." (cond ((or (and (null arg1) (null arg2)) (equal arg1 arg2)) - (apply (dashboard-agenda--build-sort-function strategies) - (list entry1 entry2))) + (apply (dashboard-agenda--build-sort-function strategies) (list entry1 entry2))) ((null arg1) nil) ((null arg2) t) (t (apply comparator (list arg1 arg2)))))) From a6a389e0b7ac6a99fd2345ce8bb55f8c8979633b Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Fri, 22 Oct 2021 20:58:16 -0500 Subject: [PATCH 7/9] Adjust documentation to use predicate instead of comparator. --- dashboard-widgets.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 5801f69e..6eab67f7 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1167,18 +1167,19 @@ 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 function to sort the dashboard agenda. -If `STRATEGIES' is nil then sort by the constant nil and don't do anything. Look for the strategy comparator -and the attributes of the entry and compare entries. If no comparator is found then sort by constant nil." + "Build a predicate to sort the dashboard agenda. +If `STRATEGIES' is nil then sort using the nil predicate. Looks for the strategy +predicate, the attributes of the entry and compare entries. If no predicate is +found for the strategy it uses nil predicate." (if (null strategies) (lambda (dont care) nil) - (let ((comparator (dashboard-agenda--build-sort-function-comparator (car strategies))) + (let ((predicate (dashboard-agenda--build-sort-function-predicate (car strategies))) (attribute (dashboard-agenda--build-sort-function-attribute (car strategies)))) - (if (null comparator) (lambda (dont care) nil) + (if (null predicate) (lambda (dont care) nil) (lambda (entry1 entry2) (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) - :with comparator :by attribute)))))) + :with predicate :by attribute)))))) -(defun dashboard-agenda--build-sort-function-comparator (strategy) +(defun dashboard-agenda--build-sort-function-predicate (strategy) "Depends on the `STRATEGY' it returns a function to compare two dashboard-agenda entries." (cond ((eq 'time-up strategy) 'org-time-less-p) @@ -1194,8 +1195,10 @@ and the attributes of the entry and compare entries. If no comparator is found t ((memq strategy '(todo-state-up todo-state-down)) 'todo-index) (t nil))) -(defun dashboard-agenda--compare-entries (entry1 entry2 strategies :with comparator :by attribute) - "Compare entries using comparator as a function and getting attributes form list." +(defun dashboard-agenda--compare-entries (entry1 entry2 strategies :with predicate :by attribute) + "Compare entries using predicate which has to return non-nil if the first element should sort +before the second. It get the `ATTRIBUTE' from entry1 and entry2, if both attributes are nil or equals then +the next strategy in `STRATEGIES' is used as a predicate." (let ((arg1 (alist-get attribute (nth 3 entry1))) (arg2 (alist-get attribute (nth 3 entry2)))) (cond @@ -1204,7 +1207,7 @@ and the attributes of the entry and compare entries. If no comparator is found t (apply (dashboard-agenda--build-sort-function strategies) (list entry1 entry2))) ((null arg1) nil) ((null arg2) t) - (t (apply comparator (list arg1 arg2)))))) + (t (apply predicate (list arg1 arg2)))))) (defun dashboard-insert-agenda (list-size) "Add the list of LIST-SIZE items of agenda." From 2c8666832cd898243a9c630277ad48b4e7528fe4 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Fri, 22 Oct 2021 22:30:32 -0500 Subject: [PATCH 8/9] Custom dashboard-agenda-sort-strategy --- dashboard-widgets.el | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 6eab67f7..29acc6f8 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1041,9 +1041,19 @@ It is the MATCH attribute for `org-map-entries'" :type 'boolean :group 'dashboard) -(defcustom dashboard-agenda-sort-strategy () - "If not nil agenda is sorted." - :type 'list +(defcustom dashboard-filter-agenda-entry 'dashboard-filter-agenda-by-time + "Function to filter `org-agenda' entries." + :type '(choice + (const :tag "No filter" dashboard-no-filter-agenda) + (const :tag "Filter by time" dashboard-filter-agenda-by-time) + (const :tag "Filter by todo" dashboard-filter-agenda-by-todo) + (function :tag "Custom function")) + :group 'dashboard) + +(defcustom dashboard-agenda-sort-strategy nil + "If nil agenda is not sorted. A list of strategies to sort the agenda." + :type '(repeat (choice (const time-up) (const time-down) + (const todo-state-up) (const todo-state-down))) :group 'dashboard) (defun dashboard-agenda-entry-time (entry-time) @@ -1128,15 +1138,6 @@ if returns a point." "No filter agenda entries." (when (org-entry-is-done-p) (point))) -(defcustom dashboard-filter-agenda-entry 'dashboard-filter-agenda-by-time - "Function to filter `org-agenda' entries." - :type '(choice - (const :tag "No filter" dashboard-no-filter-agenda) - (const :tag "Filter by time" dashboard-filter-agenda-by-time) - (const :tag "Filter by todo" dashboard-filter-agenda-by-todo) - (function :tag "Custom function")) - :group 'dashboard) - (defun dashboard-get-agenda () "Get agenda items for today or for a week from now." (org-compile-prefix-format 'agenda) From 31676af250d91da38f29c25d53ff96aa4c5eb5a5 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Sun, 24 Oct 2021 14:45:22 -0500 Subject: [PATCH 9/9] Clean linter complains. --- dashboard-widgets.el | 72 ++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 29acc6f8..27264ef0 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -58,6 +58,7 @@ (defalias 'org-time-less-p 'time-less-p) (defvar org-level-faces) (defvar org-agenda-new-buffers) +(defvar org-todo-keywords-1) (defvar all-the-icons-dir-icon-alist) (defvar package-activated-list) @@ -1051,7 +1052,7 @@ It is the MATCH attribute for `org-map-entries'" :group 'dashboard) (defcustom dashboard-agenda-sort-strategy nil - "If nil agenda is not sorted. A list of strategies to sort the agenda." + "A list of strategies to sort the agenda. If nil agenda is not sorted." :type '(repeat (choice (const time-up) (const time-down) (const todo-state-up) (const todo-state-down))) :group 'dashboard) @@ -1080,12 +1081,14 @@ is todays date format." (org-get-tags) t)) (loc (point)) - (file (buffer-file-name))) + (file (buffer-file-name)) + (todo-state (org-get-todo-state)) + (todo-index (and todo-state + (length (member todo-state org-todo-keywords-1)))) + (entry-data (list (cons 'time entry-time) + (cons 'todo-index todo-index)))) (dashboard-agenda--set-agenda-headline-face item) - (list item loc file (list (cons 'time entry-time) - (cons 'todo-index (and (org-get-todo-state) - (length (member (org-get-todo-state) - org-todo-keywords-1)))))))) + (list item loc file entry-data))) (defun dashboard-agenda--set-agenda-headline-face (headline) "Set agenda faces to `HEADLINE' when face text property is nil." @@ -1155,7 +1158,7 @@ This is what `org-agenda-exit' do." (setq org-agenda-new-buffers nil))) (defun dashboard-agenda--sorted-agenda () - "Returns agenda sorted by time. + "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." (let ((agenda (dashboard-get-agenda)) @@ -1163,25 +1166,29 @@ and dashboard-agenda-sort is not nil." (sort agenda sort-function))) (defun dashboard-agenda--sort-function () - "Get the function use to sorted the agenda depending on `dashboard-agenda-sorting-strategy'. + "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. Looks for the strategy -predicate, the attributes of the entry and compare entries. If no predicate is +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." - (if (null strategies) (lambda (dont care) nil) - (let ((predicate (dashboard-agenda--build-sort-function-predicate (car strategies))) - (attribute (dashboard-agenda--build-sort-function-attribute (car strategies)))) - (if (null predicate) (lambda (dont care) nil) + (if (null strategies) (lambda (_dont _care) nil) + (let ((predicate (dashboard-agenda--build-sort-function-predicate + (car strategies))) + (attribute (dashboard-agenda--build-sort-function-attribute + (car strategies)))) + (if (null predicate) (lambda (_dont _care) nil) (lambda (entry1 entry2) (dashboard-agenda--compare-entries entry1 entry2 (cdr strategies) - :with predicate :by attribute)))))) + predicate attribute)))))) (defun dashboard-agenda--build-sort-function-predicate (strategy) - "Depends on the `STRATEGY' it returns a function to compare two dashboard-agenda entries." + "Return the predicate to compare two entryes depending on the `STRATEGY'." (cond ((eq 'time-up strategy) 'org-time-less-p) ((eq 'time-down strategy) (lambda (a b) (org-time-less-p b a))) @@ -1190,16 +1197,15 @@ found for the strategy it uses nil predicate." (t nil))) (defun dashboard-agenda--build-sort-function-attribute (strategy) - "Depends on the `STRATEGY' it returns a function to compare two dashboard-agenda entries." + "Return the argument to compare two entries depending to the `STRATEGY'." (cond ((memq strategy '(time-up time-down)) 'time) ((memq strategy '(todo-state-up todo-state-down)) 'todo-index) (t nil))) -(defun dashboard-agenda--compare-entries (entry1 entry2 strategies :with predicate :by attribute) - "Compare entries using predicate which has to return non-nil if the first element should sort -before the second. It get the `ATTRIBUTE' from entry1 and entry2, if both attributes are nil or equals then -the next strategy in `STRATEGIES' is used as a predicate." +(defun dashboard-agenda--compare-entries (entry1 entry2 strategies predicate attribute) + "Compare `ENTRY1' and `ENTRY2' by `ATTRIBUTE' using `PREDICATE'. +If both attributes are nil or equals the next strategy in `STRATEGIES' is used to compare." (let ((arg1 (alist-get attribute (nth 3 entry1))) (arg2 (alist-get attribute (nth 3 entry2)))) (cond @@ -1214,18 +1220,18 @@ the next strategy in `STRATEGIES' is used as a predicate." "Add the list of LIST-SIZE items of agenda." (require 'org-agenda) (dashboard-insert-section - (if dashboard-week-agenda - "Agenda for the coming week:" - "Agenda for today:") - (dashboard-agenda--sorted-agenda) - list-size - (dashboard-get-shortcut 'agenda) - `(lambda (&rest ignore) - (let ((buffer (find-file-other-window (nth 2 ',el)))) - (with-current-buffer buffer - (goto-char (nth 1 ',el)) - (switch-to-buffer buffer)))) - (format "%s" (nth 0 el)))) + (if dashboard-week-agenda + "Agenda for the coming week:" + "Agenda for today:") + (dashboard-agenda--sorted-agenda) + list-size + (dashboard-get-shortcut 'agenda) + `(lambda (&rest ignore) + (let ((buffer (find-file-other-window (nth 2 ',el)))) + (with-current-buffer buffer + (goto-char (nth 1 ',el)) + (switch-to-buffer buffer)))) + (format "%s" (nth 0 el)))) ;; ;; Registers