(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
- "^[ \t]*"
+ "\\(^\\|\n\\)"
"\\(" diary-time-regexp
"\\(-" diary-time-regexp "\\)?"
- "\\)[ \t]+")
+ "\\)"
+ "\\(\t[ \t]*\\| [ \t]+\\)")
str))
- (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))
- (t str))))))
+ (t str)))
+ (if (equal str old) (setq done t)))
+ (ad-set-arg 1 str))))
;; Fighting with Org-mode's evil key maps.