all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Is there something between `prin1-to-string' and `princ'?
@ 2013-09-25 10:33 Thorsten Jolitz
  0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Jolitz @ 2013-09-25 10:33 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

using `prin1-to-string' on a property list gives me:

,-------------------------------------------------------------
| ... :CATEGORY "tmp2" :title (#("C2 " 0 3 (:parent nil))) ...
`-------------------------------------------------------------

using `princ' gives me:

,-----------------------------------
| ... :CATEGORY tmp2 :title (C2) ...
`-----------------------------------

but what I want is either

,-----------------------------------
| ... :CATEGORY "tmp2" :title (C2) ...
`-----------------------------------

or even better

,-----------------------------------
| ... :CATEGORY "tmp2" :title ("C2") ...
`-----------------------------------

but there seems to be no print command or configuration option that
gives me strings quoted, but text without properties at the same time?

PS
this is not about `buffer-substring-no-properties' or so, its about how
to print out a *given* property list in a certain format.

-- 
cheers,
Thorsten





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

* Re: Is there something between `prin1-to-string' and `princ'?
       [not found] <mailman.2838.1380105265.10748.help-gnu-emacs@gnu.org>
@ 2013-09-25 13:06 ` Pascal J. Bourguignon
  2013-09-25 13:23   ` Thorsten Jolitz
  2013-09-25 14:59   ` Thorsten Jolitz
  0 siblings, 2 replies; 4+ messages in thread
From: Pascal J. Bourguignon @ 2013-09-25 13:06 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Hi List, 
> or even better
>
> ,-----------------------------------
> | ... :CATEGORY "tmp2" :title ("C2") ...
> `-----------------------------------
>
> but there seems to be no print command or configuration option that
> gives me strings quoted, but text without properties at the same time?

I'm afraid, you'll have to strip the properties before printing.
cf.:   substring-no-properties

(defun sexp-remove-string-properties (sexp)
   (cond
      ((stringp sexp) (substring-no-properties sexp))
      ((atom sexp) sexp)
      (t (cons (sexp-remove-string-properties (car sexp))
               (sexp-remove-string-properties (cdr sexp))))))

(prin1-to-string
  (sexp-remove-string-properties    
    '(:category "tmp2" :title (#("C2 " 0 3 (:parent nil))))))
--> "(:category \"tmp2\" :title (\"C2 \"))"

-- 
__Pascal Bourguignon__
http://www.informatimago.com/


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

* Re: Is there something between `prin1-to-string' and `princ'?
  2013-09-25 13:06 ` Is there something between `prin1-to-string' and `princ'? Pascal J. Bourguignon
@ 2013-09-25 13:23   ` Thorsten Jolitz
  2013-09-25 14:59   ` Thorsten Jolitz
  1 sibling, 0 replies; 4+ messages in thread
From: Thorsten Jolitz @ 2013-09-25 13:23 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> Hi List, 
>> or even better
>>
>> ,-----------------------------------
>> | ... :CATEGORY "tmp2" :title ("C2") ...
>> `-----------------------------------
>>
>> but there seems to be no print command or configuration option that
>> gives me strings quoted, but text without properties at the same time?
>
> I'm afraid, you'll have to strip the properties before printing.
> cf.:   substring-no-properties
>
> (defun sexp-remove-string-properties (sexp)
>    (cond
>       ((stringp sexp) (substring-no-properties sexp))
>       ((atom sexp) sexp)
>       (t (cons (sexp-remove-string-properties (car sexp))
>                (sexp-remove-string-properties (cdr sexp))))))
>
> (prin1-to-string
>   (sexp-remove-string-properties    
>     '(:category "tmp2" :title (#("C2 " 0 3 (:parent nil))))))
> --> "(:category \"tmp2\" :title (\"C2 \"))"

Exactly what I need, thank you!

-- 
cheers,
Thorsten




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

* Re: Is there something between `prin1-to-string' and `princ'?
  2013-09-25 13:06 ` Is there something between `prin1-to-string' and `princ'? Pascal J. Bourguignon
  2013-09-25 13:23   ` Thorsten Jolitz
@ 2013-09-25 14:59   ` Thorsten Jolitz
  1 sibling, 0 replies; 4+ messages in thread
From: Thorsten Jolitz @ 2013-09-25 14:59 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> (defun sexp-remove-string-properties (sexp)
>    (cond
>       ((stringp sexp) (substring-no-properties sexp))
>       ((atom sexp) sexp)
>       (t (cons (sexp-remove-string-properties (car sexp))
>                (sexp-remove-string-properties (cdr sexp))))))
>
> (prin1-to-string
>   (sexp-remove-string-properties    
>     '(:category "tmp2" :title (#("C2 " 0 3 (:parent nil))))))
> --> "(:category \"tmp2\" :title (\"C2 \"))"

A classic solution, but - unfortunately - applied to a (not even very
big) real world Org-mode parse-tree the debugger is entered immediately
(without showing a backtrace really). I think recursion becomes to deep
and max number of allowed symbols is exceeded rapidly.

Although this asks for a recursive solution, I would need one that works
on really big sexp's (like parse-trees of moderate to big .org files). 

Is that possible, or do I de facto need some kind of iterative solution
here for the real world? 

-- 
cheers,
Thorsten




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

end of thread, other threads:[~2013-09-25 14:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2838.1380105265.10748.help-gnu-emacs@gnu.org>
2013-09-25 13:06 ` Is there something between `prin1-to-string' and `princ'? Pascal J. Bourguignon
2013-09-25 13:23   ` Thorsten Jolitz
2013-09-25 14:59   ` Thorsten Jolitz
2013-09-25 10:33 Thorsten Jolitz

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.