From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: A tidy file maketh a tidy mind? Date: Tue, 14 Aug 2012 07:10:17 -0600 Message-ID: <874no57gtn.fsf@gmx.com> References: <50204522.8030402@neilsmithline.com> <50208208.3080300@neilsmithline.com> <87sjbzxc49.fsf_-_@gnu.org> <16161.1344344832@alphaville> <87txwdi94q.fsf@gmail.com> <87boij423l.fsf@altern.org> <20120813115601.21602lsob8q1dpwk@webmail.tuffmail.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:55224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1HKM-00023o-Gz for emacs-orgmode@gnu.org; Tue, 14 Aug 2012 09:38:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1HKH-0002BR-KG for emacs-orgmode@gnu.org; Tue, 14 Aug 2012 09:38:34 -0400 Received: from mailout-us.gmx.com ([74.208.5.67]:34214) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1T1HKH-0002BE-DA for emacs-orgmode@gnu.org; Tue, 14 Aug 2012 09:38:29 -0400 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@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: 'Mash Cc: emacs-orgmode@gnu.org 'Mash writes: > Morning, > > I just want to know if there is there exists a 'tidy' module/command > that can be run on a file to tidy it? > > I often find myself going back and adding extra line breaks and > padding, and wondering if there exists something that can do this for > me? > While this doesn't exist currently, it should be fairly easy to implement a set of rules which operate over the parsed file representation generated by org-element. This may be used to convert an Org-mode buffer into an elisp list, manipulate the list, and then insert the results as text back into a new buffer. The code could look something like the following ;; -*- emacs-lisp -*- (let ((buf (org-element-parse-buffer))) ;; convert current buffer to ELisp (dolist (rule cleanup-rules) ;; run cleanup transformations on the buffer (setq buf (funcall rule buf))) (delete-region (point-min) (point-max)) ;; replace the buffer contents (insert (org-element-interpret-data buf))) ;; with the cleaned results The only catch would be deciding what to add to the cleanup-rules. Also, since Org-mode is plain text, I bet a couple of lines of sed or perl could get you most of the way to a clean buffer. Best, -- Eric Schulte http://cs.unm.edu/~eschulte