emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] can I fill-paragraph some org data from the command line?


From: Alan Schmitt
Subject: Re: [O] can I fill-paragraph some org data from the command line?
Date: Wed, 12 Mar 2014 16:44:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin)

Bastien <address@hidden> writes:

> Hi Alan,
>
> Alan Schmitt <address@hidden> writes:
>
>> Do you have tools or an approach using emacs (as a command line tool) to
>> suggest?
>
> I would call emacs in batch mode, applying some Elisp code to fill
> each element.  See `org-forward-element' and `org-fill-paragraph'.

Thanks a lot for the suggestion, it works. I did not use
`org-forward-element' as it does not iterate on sub-items. I simply do
a `forward-line' to go done.

Here is the code, if it's helpful to others.

--8<---------------cut here---------------start------------->8---
#!/usr/local/bin/emacs --script
;;-*- mode: emacs-lisp;-*-

;; Found at http://superuser.com/a/487329/155265 from question
;; 
https://superuser.com/questions/31404/how-to-make-emacs-read-buffer-from-stdin-on-start

(require 'org)

(with-temp-buffer
  (progn
    ; read the file in the temporary buffer
    ; do not add a \n at the end
    (condition-case nil
    (let ((line (read-from-minibuffer "")))
      (insert line)
      (while (setq line (read-from-minibuffer ""))
        (insert "\n")
        (insert line)))
    (error nil))
    ; do what you want here
    (goto-char (point-min))
    (while (< (point) (point-max))
      (org-fill-paragraph)
      (forward-line))
    (princ (buffer-string))))
--8<---------------cut here---------------end--------------->8---

Thanks again,

Alan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]