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

Skip to content

Custom dashboard-agenda-prefix-format. #350

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
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
17 changes: 15 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ To show agenda for the upcoming seven days set the variable ~dashboard-week-agen
(setq dashboard-week-agenda t)
#+END_SRC

Note that setting list-size for the agenda list is intentionally ignored; all agenda items for the current day will be displayed.

By default org-agenda entries are filter by time, only showing those
task with ~DEADLINE~ or ~SCHEDULE-TIME~. To show all agenda entries
(except ~DONE~)
Expand Down Expand Up @@ -223,6 +221,21 @@ 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~

*** Agenda format

To personalize the aspect of each entry, there is
~dashboard-agenda-prefix-format~ which initial value is
~" %i %-12:c %-10s "~ where ~%i~ is the icon category of the item (see
[[https://orgmode.org/worg/doc.html#org-agenda-category-icon-alist][org-agenda-category-icon-alist]]), ~%-12:c~ gives the category a 12
chars wide field and append a colon to the category. A similar padding
but for a 10 wide field is ~%-10s~ that is for the scheduling or
deadline information. For more information see [[https://orgmode.org/worg/doc.html#org-agenda-prefix-format][org-agenda-prefix-format]].

Deadline or Scheduling time will be formatted using
~dashboard-agenda-time-string-format~ and the keywords (TODO, DONE)
respect [[https://orgmode.org/worg/doc.html#org-agenda-todo-keyword-format][org-agenda-todo-keyword-format]].


** Faces

It is possible to customize Dashboard's appearance using the following faces:
Expand Down
66 changes: 33 additions & 33 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
(defalias 'org-time-less-p 'time-less-p)
(defvar org-level-faces)
(defvar org-agenda-new-buffers)
(defvar org-agenda-prefix-format)
(defvar org-agenda-todo-keyword-format)
(defvar org-todo-keywords-1)
(defvar all-the-icons-dir-icon-alist)
(defvar package-activated-list)
Expand Down Expand Up @@ -1060,57 +1062,54 @@ It is the MATCH attribute for `org-map-entries'"
(const todo-state-up) (const todo-state-down)))
: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
is todays date format."
(let* ((time (or entry-time (org-today)))
(formated-time (format-time-string
dashboard-agenda-time-string-format time)))
(if entry-time
formated-time
(replace-regexp-in-string "." " " formated-time))))
(defcustom dashboard-agenda-prefix-format " %i %-12:c %s "
"Format for each entry in the agenda.
When the dashboard-agenda is created this format is inserted into
`org-agenda-prefix-format' as `dashboard-agenda' and compiled with
`org-compile-prefix-format' previous calling `dashboard-agenda-entry-format' for
each agenda entry."
:type 'string
:group 'dashboard)

(defun dashboard-agenda-entry-format ()
"Format agenda entry to show it on dashboard."
(let* ((scheduled-time (org-get-scheduled-time (point)))
(deadline-time (org-get-deadline-time (point)))
(entry-time (or scheduled-time deadline-time))
(item (org-agenda-format-item
(dashboard-agenda-entry-time entry-time)
(org-get-heading)
(dashboard-agenda--formatted-time)
(dashboard-agenda--formatted-headline)
(org-outline-level)
(org-get-category)
(org-get-tags)
t))
(org-get-tags)))
(loc (point))
(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 entry-data)))

(defun dashboard-agenda--set-agenda-headline-face (headline)
(defun dashboard-agenda--formatted-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))))
(let* ((headline (org-get-heading t t t t))
(todo (or (org-get-todo-state) ""))
(org-level-face (nth (- (org-outline-level) 1) org-level-faces))
(todo-state (format org-agenda-todo-keyword-format todo)))
(when (null (get-text-property 0 'face headline))
(add-face-text-property 0 (length headline) org-level-face t headline))
(when (null (get-text-property 0 'face todo-state))
(add-face-text-property 0 (length todo-state) (org-get-todo-face todo) t todo-state))
(concat todo-state headline)))

(defun dashboard-agenda--formatted-time ()
"Get the scheduled or dead time of an entry.
If no time is found return an empty string to be formatted."
(let* ((schedule-time (org-get-scheduled-time (point)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use macro if-let* here.

(deadline-time (org-get-deadline-time (point)))
(time (or schedule-time deadline-time)))
(if time (format-time-string dashboard-agenda-time-string-format time) " ")))

(defun dashboard-due-date-for-agenda ()
"Return due-date for agenda period."
Expand Down Expand Up @@ -1148,7 +1147,8 @@ if returns a point."

(defun dashboard-get-agenda ()
"Get agenda items for today or for a week from now."
(org-compile-prefix-format 'agenda)
(add-to-list 'org-agenda-prefix-format (cons 'dashboard-agenda dashboard-agenda-prefix-format))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try to avoid add-to-list and use push instead?

(org-compile-prefix-format 'dashboard-agenda)
(prog1 (org-map-entries 'dashboard-agenda-entry-format
dashboard-match-agenda-entry
'agenda
Expand Down