* [PATCH] org-agenda: add support for category icons
@ 2010-10-29 8:49 Julien Danjou
2010-11-04 12:02 ` [Accepted] " Carsten Dominik
0 siblings, 1 reply; 2+ messages in thread
From: Julien Danjou @ 2010-10-29 8:49 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Julien Danjou
Signed-off-by: Julien Danjou <julien@danjou.info>
---
doc/org.texi | 4 +++
lisp/org-agenda.el | 65 +++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index aa4f30b..41121d3 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -7337,6 +7337,10 @@ special category you want to apply as the value.
The display in the agenda buffer looks best if the category is not
longer than 10 characters.
+@noindent
+You can set up icons for category by customizing the
+@code{org-agenda-category-icon-alist} variable.
+
@node Time-of-day specifications, Sorting of agenda items, Categories, Presentation and sorting
@subsection Time-of-day specifications
@cindex time-of-day specification
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 70c698d..da96318 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1211,11 +1211,11 @@ When nil, such items are sorted as 0 minutes effort."
:group 'org-agenda)
(defcustom org-agenda-prefix-format
- '((agenda . " %-12:c%?-12t% s")
+ '((agenda . " %i %-12:c%?-12t% s")
(timeline . " % s")
- (todo . " %-12:c")
- (tags . " %-12:c")
- (search . " %-12:c"))
+ (todo . " %i %-12:c")
+ (tags . " %i %-12:c")
+ (search . " %i %-12:c"))
"Format specifications for the prefix of items in the agenda views.
An alist with four entries, for the different agenda types. The keys to the
sublists are `agenda', `timeline', `todo', and `tags'. The values
@@ -1224,6 +1224,8 @@ This format works similar to a printf format, with the following meaning:
%c the category of the item, \"Diary\" for entries from the diary, or
as given by the CATEGORY keyword or derived from the file name.
+ %i the icon category of the item, as give in
+ `org-agenda-category-icon-alist'.
%T the *last* tag of the item. Last because inherited tags come
first in the list.
%t the time-of-day specification if one applies to the entry, in the
@@ -1431,6 +1433,45 @@ determines if it is a foreground or a background color."
(string :tag "Color")
(sexp :tag "Face"))))))
+(defcustom org-agenda-category-icon-alist nil
+ "Alist of category icon to be displayed in agenda views.
+
+Each entry should have the following format:
+
+ (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
+
+Where CATEGORY-REGEXP is a regexp matching the categories where
+the icon should be displayed.
+FILE-OR-DATA either a file path or a string containing image data.
+
+The other fields can be ommited safely if not needed:
+TYPE indicates the image type.
+DATA-P is a boolean indicating whether the FILE-OR-DATA string is
+image data.
+PROPS are additional image attributes to assign to the image,
+like, e.g. `:ascent center'.
+
+ (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
+
+If you want to set the display properties yourself, just put a
+list as second element:
+
+ (CATEGORY-REGEXP (MY PROPERTY LIST))
+
+For example, to display a 16px horizontal space for Emacs
+category, you can use:
+
+ (\"Emacs\" '(space . (:width (16))))"
+ :group 'org-agenda-line-format
+ :type '(list :tag "Category icons"
+ (repeat
+ (list
+ (string :tag "Category regexp")
+ (string :tag "File or data")
+ (string :tag "Type")
+ (boolean :tag "Data?")
+ (list :tag "Properties")))))
+
(defgroup org-agenda-column-view nil
"Options concerning column view in the agenda."
:tag "Org Agenda Column View"
@@ -4924,6 +4965,14 @@ The flag is set if the currently compiled format contains a `%e'.")
(defvar org-prefix-category-max-length nil
"Used by `org-compile-prefix-format' to remember the category field width.")
+(defun org-agenda-get-category-icon (category)
+ "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
+ (dolist (entry org-agenda-category-icon-alist)
+ (when (org-string-match-p (car entry) category)
+ (if (listp (cadr entry))
+ (return (cadr entry))
+ (return (apply 'create-image (cdr entry)))))))
+
(defun org-format-agenda-item (extra txt &optional category tags dotime
noprefix remove-re habitp)
"Format TXT to be inserted into the agenda buffer.
@@ -4953,6 +5002,10 @@ Any match of REMOVE-RE will be removed from TXT."
(file-name-sans-extension
(file-name-nondirectory buffer-file-name))
"")))
+ (category-icon (org-agenda-get-category-icon category))
+ (category-icon (if category-icon
+ (propertize " " 'display category-icon)
+ ""))
;; time, tag, effort are needed for the eval of the prefix format
(tag (if tags (nth (1- (length tags)) tags) ""))
time effort neffort
@@ -5163,11 +5216,11 @@ The resulting form is returned and stored in the variable
(t " %-12:c%?-12t% s")))
(start 0)
varform vars var e c f opt)
- (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
+ (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\)"
s start)
(setq var (cdr (assoc (match-string 4 s)
'(("c" . category) ("t" . time) ("s" . extra)
- ("T" . tag) ("e" . effort))))
+ ("i" . category-icon) ("T" . tag) ("e" . effort))))
c (or (match-string 3 s) "")
opt (match-beginning 1)
start (1+ (match-beginning 0)))
--
1.7.2.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Accepted] org-agenda: add support for category icons
2010-10-29 8:49 [PATCH] org-agenda: add support for category icons Julien Danjou
@ 2010-11-04 12:02 ` Carsten Dominik
0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2010-11-04 12:02 UTC (permalink / raw)
To: emacs-orgmode
Patch 351 (http://patchwork.newartisans.com/patch/351/) is now "Accepted".
Maintainer comment: Great idea, thanks. I added the required ChangeLog entry to the commit message, please look at them so that you can provide them next time.
This relates to the following submission:
http://mid.gmane.org/%3C1288342172-7194-1-git-send-email-julien%40danjou.info%3E
Here is the original message containing the patch:
> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [Orgmode] org-agenda: add support for category icons
> Date: Fri, 29 Oct 2010 13:49:32 -0000
> From: Julien Danjou <julien@danjou.info>
> X-Patchwork-Id: 351
> Message-Id: <1288342172-7194-1-git-send-email-julien@danjou.info>
> To: emacs-orgmode@gnu.org
> Cc: Julien Danjou <julien@danjou.info>
>
> Signed-off-by: Julien Danjou <julien@danjou.info>
>
> ---
> doc/org.texi | 4 +++
> lisp/org-agenda.el | 65 +++++++++++++++++++++++++++++++++++++++++++++++----
> 2 files changed, 63 insertions(+), 6 deletions(-)
>
> diff --git a/doc/org.texi b/doc/org.texi
> index aa4f30b..41121d3 100644
> --- a/doc/org.texi
> +++ b/doc/org.texi
> @@ -7337,6 +7337,10 @@ special category you want to apply as the value.
> The display in the agenda buffer looks best if the category is not
> longer than 10 characters.
>
> +@noindent
> +You can set up icons for category by customizing the
> +@code{org-agenda-category-icon-alist} variable.
> +
> @node Time-of-day specifications, Sorting of agenda items, Categories, Presentation and sorting
> @subsection Time-of-day specifications
> @cindex time-of-day specification
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index 70c698d..da96318 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -1211,11 +1211,11 @@ When nil, such items are sorted as 0 minutes effort."
> :group 'org-agenda)
>
> (defcustom org-agenda-prefix-format
> - '((agenda . " %-12:c%?-12t% s")
> + '((agenda . " %i %-12:c%?-12t% s")
> (timeline . " % s")
> - (todo . " %-12:c")
> - (tags . " %-12:c")
> - (search . " %-12:c"))
> + (todo . " %i %-12:c")
> + (tags . " %i %-12:c")
> + (search . " %i %-12:c"))
> "Format specifications for the prefix of items in the agenda views.
> An alist with four entries, for the different agenda types. The keys to the
> sublists are `agenda', `timeline', `todo', and `tags'. The values
> @@ -1224,6 +1224,8 @@ This format works similar to a printf format, with the following meaning:
>
> %c the category of the item, \"Diary\" for entries from the diary, or
> as given by the CATEGORY keyword or derived from the file name.
> + %i the icon category of the item, as give in
> + `org-agenda-category-icon-alist'.
> %T the *last* tag of the item. Last because inherited tags come
> first in the list.
> %t the time-of-day specification if one applies to the entry, in the
> @@ -1431,6 +1433,45 @@ determines if it is a foreground or a background color."
> (string :tag "Color")
> (sexp :tag "Face"))))))
>
> +(defcustom org-agenda-category-icon-alist nil
> + "Alist of category icon to be displayed in agenda views.
> +
> +Each entry should have the following format:
> +
> + (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
> +
> +Where CATEGORY-REGEXP is a regexp matching the categories where
> +the icon should be displayed.
> +FILE-OR-DATA either a file path or a string containing image data.
> +
> +The other fields can be ommited safely if not needed:
> +TYPE indicates the image type.
> +DATA-P is a boolean indicating whether the FILE-OR-DATA string is
> +image data.
> +PROPS are additional image attributes to assign to the image,
> +like, e.g. `:ascent center'.
> +
> + (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
> +
> +If you want to set the display properties yourself, just put a
> +list as second element:
> +
> + (CATEGORY-REGEXP (MY PROPERTY LIST))
> +
> +For example, to display a 16px horizontal space for Emacs
> +category, you can use:
> +
> + (\"Emacs\" '(space . (:width (16))))"
> + :group 'org-agenda-line-format
> + :type '(list :tag "Category icons"
> + (repeat
> + (list
> + (string :tag "Category regexp")
> + (string :tag "File or data")
> + (string :tag "Type")
> + (boolean :tag "Data?")
> + (list :tag "Properties")))))
> +
> (defgroup org-agenda-column-view nil
> "Options concerning column view in the agenda."
> :tag "Org Agenda Column View"
> @@ -4924,6 +4965,14 @@ The flag is set if the currently compiled format contains a `%e'.")
> (defvar org-prefix-category-max-length nil
> "Used by `org-compile-prefix-format' to remember the category field width.")
>
> +(defun org-agenda-get-category-icon (category)
> + "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
> + (dolist (entry org-agenda-category-icon-alist)
> + (when (org-string-match-p (car entry) category)
> + (if (listp (cadr entry))
> + (return (cadr entry))
> + (return (apply 'create-image (cdr entry)))))))
> +
> (defun org-format-agenda-item (extra txt &optional category tags dotime
> noprefix remove-re habitp)
> "Format TXT to be inserted into the agenda buffer.
> @@ -4953,6 +5002,10 @@ Any match of REMOVE-RE will be removed from TXT."
> (file-name-sans-extension
> (file-name-nondirectory buffer-file-name))
> "")))
> + (category-icon (org-agenda-get-category-icon category))
> + (category-icon (if category-icon
> + (propertize " " 'display category-icon)
> + ""))
> ;; time, tag, effort are needed for the eval of the prefix format
> (tag (if tags (nth (1- (length tags)) tags) ""))
> time effort neffort
> @@ -5163,11 +5216,11 @@ The resulting form is returned and stored in the variable
> (t " %-12:c%?-12t% s")))
> (start 0)
> varform vars var e c f opt)
> - (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
> + (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\)"
> s start)
> (setq var (cdr (assoc (match-string 4 s)
> '(("c" . category) ("t" . time) ("s" . extra)
> - ("T" . tag) ("e" . effort))))
> + ("i" . category-icon) ("T" . tag) ("e" . effort))))
> c (or (match-string 3 s) "")
> opt (match-beginning 1)
> start (1+ (match-beginning 0)))
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-11-04 12:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-29 8:49 [PATCH] org-agenda: add support for category icons Julien Danjou
2010-11-04 12:02 ` [Accepted] " Carsten Dominik
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).