From e409fbeff9ebeb6375e05dbdd9b7eb6347717dc3 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 6 Oct 2009 11:59:27 +0200 Subject: [PATCH] Allow limited length prefix format specifier %n.mc --- lisp/ChangeLog | 6 ++++++ lisp/org-agenda.el | 35 +++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 80b08b13e..9d557b584 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2009-10-06 Carsten Dominik + + * org-agenda.el (org-prefix-category-max-length): New variable. + (org-format-agenda-item): Use `org-prefix-category-max-length'. + (org-compile-prefix-format): Set `org-prefix-category-max-length'. + 2009-10-03 Carsten Dominik * org-mobile.el (org-mobile-create-index-file): Improve the diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 7c59b3716..2ab8c8db1 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -4468,6 +4468,8 @@ The flag is set if the currently compiled format contains a `%T'.") The flag is set if the currently compiled format contains a `%e'.") (defvar org-prefix-category-length nil "Used by `org-compile-prefix-format' to remember the category field widh.") +(defvar org-prefix-category-max-length nil + "Used by `org-compile-prefix-format' to remember the category field widh.") (defun org-format-agenda-item (extra txt &optional category tags dotime noprefix remove-re) @@ -4585,15 +4587,19 @@ Any match of REMOVE-RE will be removed from TXT." (t "")) extra (or extra "") category (if (symbolp category) (symbol-name category) category)) - (when (string-match org-bracket-link-regexp category) - (setq l (if (match-end 3) - (- (match-end 3) (match-beginning 3)) - (- (match-end 1) (match-beginning 1)))) - (when (< l (or org-prefix-category-length 0)) - (setq category (copy-sequence category)) - (org-add-props category nil - 'extra-space (make-string - (- org-prefix-category-length l 1) ?\ )))) + (if (string-match org-bracket-link-regexp category) + (progn + (setq l (if (match-end 3) + (- (match-end 3) (match-beginning 3)) + (- (match-end 1) (match-beginning 1)))) + (when (< l (or org-prefix-category-length 0)) + (setq category (copy-sequence category)) + (org-add-props category nil + 'extra-space (make-string + (- org-prefix-category-length l 1) ?\ )))) + (if (and org-prefix-category-max-length + (>= (length category) org-prefix-category-max-length)) + (setq category (substring category 0 (1- org-prefix-category-max-length))))) ;; Evaluate the compiled format (setq rtn (concat (eval org-prefix-format-compiled) txt))) @@ -4701,10 +4707,15 @@ The resulting form is returned and stored in the variable (if (equal var 'time) (setq org-prefix-has-time t)) (if (equal var 'tag) (setq org-prefix-has-tag t)) (if (equal var 'effort) (setq org-prefix-has-effort t)) - (if (equal var 'category) - (setq org-prefix-category-length - (abs (string-to-number (match-string 2 s))))) (setq f (concat "%" (match-string 2 s) "s")) + (when (equal var 'category) + (setq org-prefix-category-length + (floor (abs (string-to-number (match-string 2 s))))) + (setq org-prefix-category-max-length + (let ((x (match-string 2 s))) + (save-match-data + (if (string-match "\\.[0-9]+" x) + (string-to-number (substring (match-string 0 x) 1))))))) (if opt (setq varform `(if (equal "" ,var)