>From 1e3bbf2c236039462a679bb69ea93f4ba1aa44ee Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Tue, 22 Aug 2017 21:12:14 -0500 Subject: [PATCH 2/2] org-agenda: Minor refactoring and tiny bug fix * lisp/org-agenda.el (org-agenda--insert-overriding-header): Use propertize instead of org-add-props. (org-agenda-list): Replace nested if with cond. (org-todo-list): Replace mapc-lambda with cl-loop. (org-todo-list): Fix bug by using window-width instead of frame-width. --- lisp/org-agenda.el | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 0cb462e..b349bc5 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -2074,10 +2074,9 @@ evaluate to a string." `(pcase org-agenda-overriding-header ("" nil) ; Don't insert a header if set to empty string ;; Insert user-specified string - ((pred stringp) (insert - (org-add-props (copy-sequence org-agenda-overriding-header) - nil 'face 'org-agenda-structure) - "\n")) + ((pred stringp) (insert (propertize org-agenda-overriding-header + 'face 'org-agenda-structure) + "\n")) ;; When nil, make string automatically and insert it ((pred null) (insert ,default)))) @@ -4179,11 +4178,12 @@ items if they have an hour specification like [h]h:mm." (org-agenda--insert-overriding-header :default (concat (org-agenda-span-name span) "-agenda" - (if (< (- d2 d1) 350) - (if (= w1 w2) - (format " (W%02d)" w1) - (format " (W%02d-W%02d)" w1 w2)) - "") + ;; Format week number span + (cond ((< (- d2 d1) 350) + (if (= w1 w2) + (format " (W%02d)" w1) + (format " (W%02d-W%02d)" w1 w2))) + (t "")) ":\n"))) (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure 'org-date-line t)) @@ -4704,15 +4704,16 @@ for a keyword. A numeric prefix directly selects the Nth keyword in org-select-this-todo-keyword)) (setq pos (point)) (unless org-agenda-multi + ;; Insert TODO-keyword-selection key menu (insert (substitute-command-keys "Available with \ `N \\[org-agenda-redo]': (0)[ALL]")) - (let ((n 0) s) - (mapc (lambda (x) - (setq s (format "(%d)%s" (setq n (1+ n)) x)) - (if (> (+ (current-column) (string-width s) 1) (frame-width)) - (insert "\n ")) - (insert " " s)) - kwds)) + (cl-loop for keyword in kwds + and num from 1 + for string = (format "(%d)%s" num keyword) + when (> (+ (current-column) (string-width string) 1) + (window-width)) + do (insert "\n ") + do (insert " " string)) (insert "\n")) (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)) (buffer-string))) -- 2.7.4