If a day has multiple appointments, we want to reformat them all.
Iterate over the various transformations until convergence. The
substitutions have been carefully (re-)designed to avoid gratuitous
matching.
(defadvice diary-add-to-list (before mdw-trim-leading-space activate)
"Trim leading space from the diary entry string."
(save-match-data
(defadvice diary-add-to-list (before mdw-trim-leading-space activate)
"Trim leading space from the diary entry string."
(save-match-data
- (let ((str (ad-get-arg 1)))
- (ad-set-arg 1
- (cond ((null str) nil)
+ (let ((str (ad-get-arg 1))
+ (done nil) old)
+ (while (not done)
+ (setq old str)
+ (setq str (cond ((null str) nil)
+ ((string-match "\\(^\\|\n\\)[ \t]+" str)
+ (replace-match "\\1" nil nil str))
((and mdw-diary-for-org-mode-p
(string-match (concat
((and mdw-diary-for-org-mode-p
(string-match (concat
"\\(" diary-time-regexp
"\\(-" diary-time-regexp "\\)?"
"\\(" diary-time-regexp
"\\(-" diary-time-regexp "\\)?"
+ "\\)"
+ "\\(\t[ \t]*\\| [ \t]+\\)")
- (replace-match "\\1 " nil nil str))
- ((string-match "^[ \t]+" str)
- (replace-match "" nil nil str))
+ (replace-match "\\1\\2 " nil nil str))
((and (not mdw-diary-for-org-mode-p)
(string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
str))
(replace-match "\\1" nil nil str))
((and (not mdw-diary-for-org-mode-p)
(string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
str))
(replace-match "\\1" nil nil str))
+ (t str)))
+ (if (equal str old) (setq done t)))
+ (ad-set-arg 1 str))))
;; Fighting with Org-mode's evil key maps.
;; Fighting with Org-mode's evil key maps.