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

Skip to content

Agenda highlight headlines #281

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 2 commits into from
Dec 29, 2020
Merged
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
36 changes: 29 additions & 7 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
(declare-function org-get-tags "ext:org.el")
(declare-function org-map-entries "ext:org.el")
(declare-function org-outline-level "ext:org.el")
(declare-function org-get-todo-face "ext:org.el")
;; Org-time-less-p is define in emacs-27 as time-less-p alias
(when (< emacs-major-version 27)
(defalias 'org-time-less-p 'time-less-p))
Expand Down Expand Up @@ -936,20 +937,40 @@ is todays date format."
formated-time
(replace-regexp-in-string "." " " formated-time))))

(defun dashboard-format-agenda-entry ()
(defun dashboard-agenda-entry-format ()
"Format agenda entry to show it on dashboard."
(let* ((schedule-time (org-get-scheduled-time (point)))
(deadline-time (org-get-deadline-time (point)))
(item (org-agenda-format-item
(dashboard-agenda-entry-time (or schedule-time deadline-time))
(dashboard-agenda-entry-time (or schedule-time deadline-time))
(org-get-heading)
(org-outline-level)
(org-get-category)
(org-get-tags)
t))
(loc (point))
(file (buffer-file-name)))
(list item schedule-time deadline-time loc file)))
(dashboard-agenda--set-agenda-headline-face item)
(list item loc file)))

(defun dashboard-agenda--set-agenda-headline-face (headline)
"Set agenda faces to `HEADLINE' when face text property is nil."
(let ((todo (org-get-todo-state))
(org-level-face (nth (- (org-outline-level) 1) org-level-faces)))
(dashboard-agenda--set-face-when-match org-level-face
(org-get-heading t t t t)
headline)
(dashboard-agenda--set-face-when-match (org-get-todo-face todo)
todo
headline)))

(defun dashboard-agenda--set-face-when-match (face text entry)
"Set `FACE' to match text between `TEXT' and `ENTRY'.
Do nothing if `TEXT' has already a face property or is nil."
(let ((match-part (and text (string-match text entry))))
(when (and match-part (null (get-text-property 0 'face text)))
(add-face-text-property (match-beginning 0) (match-end 0)
face t entry))))

(defun dashboard-due-date-for-agenda ()
"Return due-date for agenda period."
Expand Down Expand Up @@ -995,7 +1016,7 @@ if returns a point."
(defun dashboard-get-agenda ()
"Get agenda items for today or for a week from now."
(org-compile-prefix-format 'agenda)
(org-map-entries `dashboard-format-agenda-entry
(org-map-entries 'dashboard-agenda-entry-format
dashboard-match-agenda-entry
'agenda
dashboard-filter-agenda-entry))
Expand All @@ -1012,9 +1033,10 @@ if returns a point."
list-size
(dashboard-get-shortcut 'agenda)
`(lambda (&rest ignore)
(let ((buffer (find-file-other-window (nth 4 ',el))))
(with-current-buffer buffer (goto-char (nth 3 ',el)))
(switch-to-buffer buffer)))
(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)))))

;;
Expand Down