unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* `print' inside Emacs vs `print' to stdout (with Emacsclient)
@ 2013-10-23  7:49 Thorsten Jolitz
  2013-10-23 10:24 ` Thorsten Jolitz
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Jolitz @ 2013-10-23  7:49 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

this is the parse-tree of a minimal Org file

#+begin_src org
* A
B
#+end_src

as found in the *Messages* buffer after printing with 

#+begin_src emacs-lisp
(let ((org-cycle-silently t)
      (print-escape-newlines t)
      (print-circle t))
  (with-temp-buffer
    (insert-file-contents-literally
     "/path/to/tmp.org")
    (org-mode)
    (print
     (org-element-parse-buffer))))
#+end_src

#+begin_src emacs-lisp
#2=(org-data nil #1=(headline (:raw-value "A" :begin 1 :end 7 :pre-blank
0 :hiddenp outline :contents-begin 5 :contents-end 7 :level 1 :priority
nil :tags nil :todo-keyword nil :todo-type nil :post-blank
0 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp
nil :CATEGORY nil :title (#("A" 0 1 (:parent #1#))) :parent #2#) #3=(section
(:begin 5 :end 7 :contents-begin 5 :contents-end 7 :post-blank
0 :parent #1#) #4=(paragraph (:begin 5 :end 7 :contents-begin 5 :contents-end
7 :post-blank 0 :post-affiliated 5 :parent #3#) #("B\n" 0 2 (:parent #4#))))))
#+end_src

Now when I use the exactly same print commands as arguments for an emacsclient
call

#+begin_src sh
  $ emacsclient -s my-server -e "(let ((org-cycle-silently
  t)(print-escape-newlines t)(print-circle t)) (with-temp-buffer
  (insert-file-contents-literally
  \"/path/to/tmp.org\") (org-mode) (print
  (org-element-parse-buffer))))"
#+end_src  

I see this output on the console, i.e. (print-circle t) does not seem in
effect anymore. 
 
#+begin_src emacs-lisp
  (org-data nil (headline (:raw-value "A" :begin 1 :end
  7 :pre-blank 0 :hiddenp outline :contents-begin 5 :contents-end
  7 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type
  nil :post-blank 0 :footnote-section-p nil :archivedp
  nil :commentedp nil :quotedp nil :CATEGORY nil :title (#("A" 0
  1 (:parent #1))) :parent #0) (section (:begin 5 :end
  7 :contents-begin 5 :contents-end 7 :post-blank 0 :parent
  #1) (paragraph (:begin 5 :end 7 :contents-begin 5 :contents-end
  7 :post-blank 0 :post-affiliated 5 :parent #2) #("B\n" 0
  2 (:parent #3))))))
#+end_src

Actually, what I really see is this

#+begin_src sh
(org-data nil
          (headline
           (:raw-value "A" :begin 1 :end 7 :pre-blank 0 :hiddenp outline :contents-begin 5 :contents-end 7 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil :CATEGORY nil :title
                       (#("A" 0 1
                          (:parent #1)))
                       :parent #0)
           (section
            (:begin 5 :end 7 :contents-begin 5 :contents-end 7 :post-blank 0 :parent #1)
            (paragraph
             (:begin 5 :end 7 :contents-begin 5 :contents-end 7 :post-blank 0 :post-affiliated 5 :parent #2)
             #("B\n" 0 2
               (:parent #3))))))
#+end_src

and it seems, when this output is received as input by another program, that
not only the 'circular list' print-syntax is lost, but new redundant
line-breaks are introduced that are not related to the original Org file. 

But I need those 'circular' labels and references, and would rather not have
those random linebreaks.

The only way to get the 'circular' labels seems converting the whole structure
to a string while or before printing (with `(print (format ...))' or
`prin1-to-string' e.g.), but that causes other problems w.r.t. escaping
special chars and (unwanted) surrounding double quotes.

What I would really need is being able to just `print' a structure to
stdout in an emacsclient call and receive as input of another program on
stdin exactly what would be printed in the Emacs *Messages* buffer when
evaluating the print commands in an emacs-lisp-mode buffer.

Is there any way to achieve this?

-- 
cheers,
Thorsten




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

* Re: `print' inside Emacs vs `print' to stdout (with Emacsclient)
  2013-10-23  7:49 `print' inside Emacs vs `print' to stdout (with Emacsclient) Thorsten Jolitz
@ 2013-10-23 10:24 ` Thorsten Jolitz
  0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Jolitz @ 2013-10-23 10:24 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@gmail.com> writes:

Hi List, 

> What I would really need is being able to just `print' a structure to
> stdout in an emacsclient call and receive as input of another program on
> stdin exactly what would be printed in the Emacs *Messages* buffer when
> evaluating the print commands in an emacs-lisp-mode buffer.
>
> Is there any way to achieve this?

following up to my own post, I wonder how printing does work in the
*Messages* buffer?

Looking at the examples below, I see that - with `print-circle' set to t
- `print' and `(message "%S" ...)' produce the output I want to receive
in another program. And what I want is the first part of the output, the
unquoted lisp structure, not the second (string) part. 

I wonder how this first part (the return value of
`org-element-parse-buffer' I would guess) is captured and printed
unquoted in the *Messages* buffer _with_ the 'circular' labels and
references?

To send something via stdout to another program, one must print
something, so what I receive in the other program is always the the
output - either unquoted but without the 'circular' labels and
references, or quoted and including them.

How can I send the raw lisp structure with print-circle information
to another program (instead of a string)?

###################################

    ,-------------------------------
    | (print 
    |  (org-element-parse-buffer))))
    `-------------------------------

#2=(org-data nil #1=(headline (:raw-value "A" :begin 1 :end 7 :pre-blank
 0 :hiddenp outline :contents-begin 5 :contents-end 7 :level 1 :priority
 nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0
 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil
 :CATEGORY nil :title (#("A" 0 1 (:parent #1#))) :parent #2#)
 #3=(section (:begin 5 :end 7 :contents-begin 5 :contents-end 7
 :post-blank 0 :parent #1#) #4=(paragraph (:begin 5 :end 7
 :contents-begin 5 :contents-end 7 :post-blank 0 :post-affiliated 5
 :parent #3#) #("B\n" 0 2 (:parent #4#))))))

(org-data nil (headline (:raw-value "A" :begin 1 :end 7 :pre-blank 0
:hiddenp outline :contents-begin 5 ...) (section (:begin 5 :end 7
:contents-begin 5 :contents-end 7 :post-blank 0 :parent #1) (paragraph
... #("B " 0 2 ...)))))

##################################

    ,-------------------------------
    | (message "%S"
    |  (org-element-parse-buffer))))
    `-------------------------------

#2=(org-data nil #1=(headline (:raw-value "A" :begin 1 :end 7 :pre-blank
 0 :hiddenp outline :contents-begin 5 :contents-end 7 :level 1 :priority
 nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0
 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil
 :CATEGORY nil :title (#("A" 0 1 (:parent #1#))) :parent #2#)
 #3=(section (:begin 5 :end 7 :contents-begin 5 :contents-end 7
 :post-blank 0 :parent #1#) #4=(paragraph (:begin 5 :end 7
 :contents-begin 5 :contents-end 7 :post-blank 0 :post-affiliated 5
 :parent #3#) #("B\n" 0 2 (:parent #4#))))))

"#2=(org-data nil #1=(headline (:raw-value \"A\" :begin 1 :end 7
:pre-blank 0 :hiddenp outline :contents-begin 5 :contents-end 7 :level 1
:priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0
:footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil
:CATEGORY nil :title (#(\"A\" 0 1 (:parent #1#))) :parent #2#)
#3=(section (:begin 5 :end 7 :contents-begin 5 :contents-end 7
:post-blank 0 :parent #1#) #4=(paragraph (:begin 5 :end 7
:contents-begin 5 :contents-end 7 :post-blank 0 :post-affiliated 5
:parent #3#) #(\"B\\n\" 0 2 (:parent #4#))))))"


##################################

    ,-------------------------------
    | (message "%s"
    |  (org-element-parse-buffer))))
    `-------------------------------

#2=(org-data nil #1=(headline (:raw-value A :begin 1 :end 7 :pre-blank 0
:hiddenp outline :contents-begin 5 :contents-end 7 :level 1 :priority
nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0
:footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil
:CATEGORY nil :title (A) :parent #2#) #3=(section (:begin 5 :end 7
:contents-begin 5 :contents-end 7 :post-blank 0 :parent #1#)
#4=(paragraph (:begin 5 :end 7 :contents-begin 5 :contents-end 7
:post-blank 0 :post-affiliated 5 :parent #3#) B ))))

"#2=(org-data nil #1=(headline (:raw-value A :begin 1 :end 7 :pre-blank
0 :hiddenp outline :contents-begin 5 :contents-end 7 :level 1 :priority
nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0
:footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil
:CATEGORY nil :title (A) :parent #2#) #3=(section (:begin 5 :end 7
:contents-begin 5 :contents-end 7 :post-blank 0 :parent #1#)
#4=(paragraph (:begin 5 :end 7 :contents-begin 5 :contents-end 7
:post-blank 0 :post-affiliated 5 :parent #3#) B ))))"

####################################

-- 
cheers,
Thorsten




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

end of thread, other threads:[~2013-10-23 10:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23  7:49 `print' inside Emacs vs `print' to stdout (with Emacsclient) Thorsten Jolitz
2013-10-23 10:24 ` Thorsten Jolitz

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).