Re: [O] A tidy file maketh a tidy mind?
Hi Mash, 'Mash mash...@toshine.net writes: I just want to know if there is there exists a 'tidy' module/command that can be run on a file to tidy it? People differ in the way they think their org files are clean. Maybe you can start a list of tidyfication routines you use reguarily, then if we all agree on the core routines that many people use, we can have a useful function for this -- certainly in org-hacks.org first. Thanks, -- Bastien
Re: [O] A tidy file maketh a tidy mind?
'Mash mash...@toshine.net 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
Re: [O] A tidy file maketh a tidy mind?
On 2012-08-14 07:10-0600, Eric Schulte wrote: 'Mash mash...@toshine.net 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. Thanks, I need to spend some time to look at rules. But my most common clean-up is really just adding some spacing/padding for example. Would be handy to implement in a save-hook along with org-sort. --- cluttered --- * Lorem ipsum dolor sit amet ** TODO consectetuer adipiscing elit Sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. SCHEDULED: 2012-08-09 Thu 20:30 ** TODO quis nostrud exerci tation ullamcorper SCHEDULED: 2012-08-08 Wed 10:30 Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. ** TODO Ut wisi enim ad minim veniam... --- tidier --- * Lorem ipsum dolor sit amet ** TODO quis nostrud exerci tation ullamcorper SCHEDULED: 2012-08-08 Wed 10:30 Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. ** TODO consectetuer adipiscing elit SCHEDULED: 2012-08-09 Thu 20:30 Sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. ** TODO Ut wisi enim ad minim veniam...
Re: [O] A tidy file maketh a tidy mind?
Eric Schulte eric.schu...@gmx.com writes: 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. One useful clean up operation, also illustrated in 'Mash's example, is to put time-stamps (i.e. SCHEDULED: lines etc.) where they belong, right after the headline. Is there any taker for such a function? It would be a nice addition to org-hacks.org! -- Bastien