From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastien Vauban Subject: Re: [RFC] Change property drawer syntax Date: Wed, 12 Nov 2014 12:01:06 +0100 Message-ID: <86zjbwlm31.fsf@example.com> References: <87oatek909.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org To: emacs-orgmode-mXXj517/zsQ@public.gmane.org Hello Nicolas, Nicolas Goaziou wrote: > As discussed previously, I would like to modify property drawers > syntax. [...] > > However, it will break some Org documents. In particular, TODO-states > changes are usually logged before any drawer, including properties > drawers. The following function repairs them. > > (defun org-repair-property-drawers () > "Fix properties drawers in current buffer. > Ignore non Org buffers." > (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 > (re-search-forward org-property-drawer-re end t))) > (insert (delete-and-extract-region > (match-beginning 0) > (min (1+ (match-end 0)) end))) > (unless (bolp) (insert "\n")))))))))))) After heavy testing (on all my Org files, I mean) of the above function, it works perfectly except for the following corner-case (when there are Org properties in "quote" blocks): --8<---------------cut here---------------start------------->8--- * Reference Example of Custom ID: #+begin_verse ,* Some title :PROPERTIES: :CUSTOM_ID: SomeTitle :END: Lorem ipsum #+end_verse --8<---------------cut here---------------end--------------->8--- will be converted to: --8<---------------cut here---------------start------------->8--- * Reference :PROPERTIES: :CUSTOM_ID: SomeTitle :END: Example of Custom ID: #+begin_verse ,* Some title Lorem ipsum #+end_verse --8<---------------cut here---------------end--------------->8--- upon execution of `org-repair-property-drawers'. PS- I did not retest (yet) the same thing in #+begin/end_src blocks... as playing with that example files makes my Emacs eat 100% of the CPU (infloop?). I've restarted Emacs 5 or 6 times before being able to write this ECM... Best regards, Seb -- Sebastien Vauban