emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* can I fill-paragraph some org data from the command line?
@ 2014-03-12 12:25 Alan Schmitt
  2014-03-12 15:11 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Schmitt @ 2014-03-12 12:25 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I'm playing with manipulating some data in org-mode format from the
command line (OK, I admit that I'm playing with acme).

I'm wondering if there is a tool, or a way to call emacs, to do the
following:

- get some data in org-mode format from stdin
- nicely format the text
- spit the result on stdout

I tried using "pandoc -t org" but the results are not satisfactory,
especially in the presence of lists inside lists. For instance, I would
like to convert:

#+begin_example
- This is a very long line. This is a very long line. This is a very long line. This is a very long line.
  - This is a very long line. This is a very long line. This is a very long line. This is a very long line.
  - This is a yet another very long line. This is a very long line. This is a very long line. This is a very long line.
#+end_example

into this

#+begin_example
- This is a very long line. This is a very long line. This is a very
  long line. This is a very long line.
  - This is a very long line. This is a very long line. This is a very
    long line. This is a very long line.
  - This is a yet another very long line. This is a very long line. This
    is a very long line. This is a very long line.
#+end_example

Do you have tools or an approach using emacs (as a command line tool) to
suggest?

Thanks,

Alan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: can I fill-paragraph some org data from the command line?
  2014-03-12 12:25 can I fill-paragraph some org data from the command line? Alan Schmitt
@ 2014-03-12 15:11 ` Bastien
  2014-03-12 15:44   ` Alan Schmitt
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2014-03-12 15:11 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

Hi Alan,

Alan Schmitt <alan.schmitt@polytechnique.org> 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'.

HTH,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: can I fill-paragraph some org data from the command line?
  2014-03-12 15:11 ` Bastien
@ 2014-03-12 15:44   ` Alan Schmitt
  2014-03-12 16:11     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Schmitt @ 2014-03-12 15:44 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bastien <bzg@gnu.org> writes:

> Hi Alan,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: can I fill-paragraph some org data from the command line?
  2014-03-12 15:44   ` Alan Schmitt
@ 2014-03-12 16:11     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2014-03-12 16:11 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

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

Thanks for sharing this!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-12 16:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-12 12:25 can I fill-paragraph some org data from the command line? Alan Schmitt
2014-03-12 15:11 ` Bastien
2014-03-12 15:44   ` Alan Schmitt
2014-03-12 16:11     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).