]> git.donarmstrong.com Git - lib.git/commitdiff
add function to repair property drawers
authorDon Armstrong <don@donarmstrong.com>
Tue, 23 Feb 2016 23:41:43 +0000 (17:41 -0600)
committerDon Armstrong <don@donarmstrong.com>
Tue, 23 Feb 2016 23:41:43 +0000 (17:41 -0600)
emacs_el/configuration/org-mode-configuration.el

index 59219fcf4492af158dfd5d7e1e76f9d30536c6f6..973e00257177f5c0573457c1715623d06871e5b0 100644 (file)
@@ -1000,4 +1000,35 @@ same directory as the org-buffer and insert a link to this file."
   (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
   (org-display-inline-images))
 
+; from http://orgmode.org/Changes.html
+(defun my/org-repair-property-drawers ()
+  "Fix properties drawers in current buffer.
+ Ignore non Org buffers."
+  (interactive)
+  (when (eq major-mode 'org-mode)
+    (org-with-wide-buffer
+     (goto-char (point-min))
+     (let ((case-fold-search t)
+           (inline-re (and (featurep 'org-inlinetask)
+                           (concat (org-inlinetask-outline-regexp)
+                                   "END[ \t]*$"))))
+       (org-map-entries
+        (lambda ()
+          (unless (and inline-re (org-looking-at-p inline-re))
+            (save-excursion
+              (let ((end (save-excursion (outline-next-heading) (point))))
+                (forward-line)
+                (when (org-looking-at-p org-planning-line-re) (forward-line))
+                (when (and (< (point) end)
+                           (not (org-looking-at-p org-property-drawer-re))
+                           (save-excursion
+                             (and (re-search-forward org-property-drawer-re end t)
+                                  (eq (org-element-type
+                                       (save-match-data (org-element-at-point)))
+                                      'drawer))))
+                  (insert (delete-and-extract-region
+                           (match-beginning 0)
+                           (min (1+ (match-end 0)) end)))
+                  (unless (bolp) (insert "\n"))))))))))))
+
 (provide 'org-mode-configuration)