chiark / gitweb /
el/dot-emacs.el (diary-add-to-list): Fix for multiple appointments.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 29 Apr 2016 11:01:54 +0000 (12:01 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 29 Apr 2016 11:01:54 +0000 (12:01 +0100)
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.

el/dot-emacs.el

index a2989fea4eb737f2093801e09fca2c14ba6b0802..5a7f08d41a9c9cffe5643bf47d91d41e707394f7 100644 (file)
@@ -373,24 +373,29 @@ (defadvice org-agenda-list (around mdw-preserve-links activate)
 (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.