* Easily re-indent the #+OPTIONS lines
@ 2008-01-16 22:34 Bastien
2008-01-17 9:09 ` Phil Jackson
0 siblings, 1 reply; 3+ messages in thread
From: Bastien @ 2008-01-16 22:34 UTC (permalink / raw)
To: emacs-orgmode
Hi folks,
I often fiddle around #+AUTHOR, #+TITLE, and other such lines. But
having to re-align them so that it looks better is time-consuming.
This function does it automatically:
(defun bzg-org-indent-options ()
"Indent option lines correctly."
(interactive)
(save-excursion
(goto-char (point-min))
(let ((max-length 0))
(while (re-search-forward "^#\\+\\([A-Z_]+\\)" nil t)
(if (> (length (match-string 1)) max-length)
(setq max-length (length (match-string 1)))))
(goto-char (point-min))
(while (re-search-forward "^#\\+\\([A-Z_]+\\):[ \t]*\\(.+\\)$" nil t)
(replace-match
(concat "#+" (match-string 1) ":"
(make-string (1+ (- max-length (length (match-string 1)))) 32)
(match-string 2)) t t)))))
For example, it converts this:
#+TITLE: Test file
#+STARTUP: hidestars
#+AUTHOR: Bastien Guerry
#+EMAIL: bzg AT altern DOT org
#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:t -:t f:t
#+SEQ_TODO: TODO NEXT FEEDBACK VERIFY DONE
#+COLUMNS: %66ITEM %8TODO %10SCHEDULED %3PRIORITY %1TAGS
into this:
#+TITLE: Test file
#+STARTUP: hidestars
#+AUTHOR: Bastien Guerry
#+EMAIL: bzg AT altern DOT org
#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:t -:t f:t
#+SEQ_TODO: TODO NEXT FEEDBACK VERIFY DONE
#+COLUMNS: %66ITEM %8TODO %10SCHEDULED %3PRIORITY %1TAGS
--
Bastien
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Easily re-indent the #+OPTIONS lines
2008-01-16 22:34 Easily re-indent the #+OPTIONS lines Bastien
@ 2008-01-17 9:09 ` Phil Jackson
2008-01-17 17:51 ` Adam Spiers
0 siblings, 1 reply; 3+ messages in thread
From: Phil Jackson @ 2008-01-17 9:09 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
Hey Bastien,
Bastien <bzg@altern.org> writes:
> I often fiddle around #+AUTHOR, #+TITLE, and other such lines. But
> having to re-align them so that it looks better is time-consuming.
>
> This function does it automatically:
>
> (defun bzg-org-indent-options ()
> "Indent option lines correctly."
> (interactive)
> (save-excursion
> (goto-char (point-min))
> (let ((max-length 0))
> (while (re-search-forward "^#\\+\\([A-Z_]+\\)" nil t)
> (if (> (length (match-string 1)) max-length)
> (setq max-length (length (match-string 1)))))
> (goto-char (point-min))
> (while (re-search-forward "^#\\+\\([A-Z_]+\\):[ \t]*\\(.+\\)$" nil t)
> (replace-match
> (concat "#+" (match-string 1) ":"
> (make-string (1+ (- max-length (length (match-string 1)))) 32)
> (match-string 2)) t t)))))
Thanks, really handy. BTW did you know about align-regexp?
,----
| (align-regexp (point-min) (point-max) "^#\\+[A-Z_]+:\\( +\\)" 1 5)
`----
Dare I say will have a similar affect.
Cheers,
Phil
--
Phil Jackson
http://www.shellarchive.co.uk
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Easily re-indent the #+OPTIONS lines
2008-01-17 9:09 ` Phil Jackson
@ 2008-01-17 17:51 ` Adam Spiers
0 siblings, 0 replies; 3+ messages in thread
From: Adam Spiers @ 2008-01-17 17:51 UTC (permalink / raw)
To: emacs-orgmode
On Thu, Jan 17, 2008 at 09:09:07AM +0000, Phil Jackson wrote:
> Bastien <bzg@altern.org> writes:
> > I often fiddle around #+AUTHOR, #+TITLE, and other such lines. But
> > having to re-align them so that it looks better is time-consuming.
>
> ,----
> | (align-regexp (point-min) (point-max) "^#\\+[A-Z_]+:\\( +\\)" 1 5)
> `----
`align-regexp' comes from align.el which also provides
`align-rules-list', a customizable variable which defines how the
DWIM `align' function behaves. Therefore it would be even nicer if
org-mode automatically ensured that `align-rules-list' contained the
right settings for attaining this! The following works for me when
included in `align-rules-list':
'(org-in-buffer-settings
(regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
(modes '(org-mode)))
When I select the region and do M-x align, it does the right thing.
So the code could check whether there is an entry with this title
`org-in-buffer-settings' in the list, and if not, add it - thereby
allowing personal customization to override the automatically provided
default.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-01-17 17:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-16 22:34 Easily re-indent the #+OPTIONS lines Bastien
2008-01-17 9:09 ` Phil Jackson
2008-01-17 17:51 ` Adam Spiers
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.