all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* What happens with text properties in batch mode?
@ 2018-12-07  7:56 Marcin Borkowski
  2018-12-07  8:42 ` tomas
  2018-12-07  9:05 ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Marcin Borkowski @ 2018-12-07  7:56 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hi all,

it seems that when I `princ' something with text properties (e.g.,
colored faces) in batch mode, the colors disappear.  Is it documented
anywhere?  Can I disable this behavior?

I found this: https://github.com/Lindydancer/e2ansi, and its existence
suggests that outputting colored stuff (using ANSI codes) is
non-trivial.  Am I right?

TIA,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: What happens with text properties in batch mode?
  2018-12-07  7:56 What happens with text properties in batch mode? Marcin Borkowski
@ 2018-12-07  8:42 ` tomas
  2018-12-08 19:28   ` Marcin Borkowski
  2018-12-07  9:05 ` Eli Zaretskii
  1 sibling, 1 reply; 8+ messages in thread
From: tomas @ 2018-12-07  8:42 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]

On Fri, Dec 07, 2018 at 08:56:23AM +0100, Marcin Borkowski wrote:
> Hi all,
> 
> it seems that when I `princ' something with text properties (e.g.,
> colored faces) in batch mode, the colors disappear.

From a quick test here (which may be flawed, mind you), I can confirm
that princ removes the properties from strings.

> Is it documented anywhere?  Can I disable this behavior?

I don't know about that. A cursory look at "print.c", and there, the C
functions `print' and `print_object' suggest that yes, it's intentional,
and it's pretty deeply rooted.

> I found this: https://github.com/Lindydancer/e2ansi, and its existence
> suggests that outputting colored stuff (using ANSI codes) is
> non-trivial.  Am I right?

I think this is only relevant if you are trying to colorize the output
to an ANSI terminal (or more probably to an ANSI terminal emulator, like
an Xterm or the Linux console, unless you're working at a computer
museum, these days). Probably not relevant in your case, since `princ'
outputs most of the time to some buffer-like thingy, but can be trained
to do almost everything...

What are you trying to achieve?

Cheers
-- tomás

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: What happens with text properties in batch mode?
  2018-12-07  7:56 What happens with text properties in batch mode? Marcin Borkowski
  2018-12-07  8:42 ` tomas
@ 2018-12-07  9:05 ` Eli Zaretskii
  2018-12-08 19:29   ` Marcin Borkowski
  1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2018-12-07  9:05 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Marcin Borkowski <mbork@mbork.pl>
> Date: Fri, 07 Dec 2018 08:56:23 +0100
> 
> it seems that when I `princ' something with text properties (e.g.,
> colored faces) in batch mode, the colors disappear.  Is it documented
> anywhere?  Can I disable this behavior?

princ is for human consumption, so the text properties are not
displayed.  There's prin1, which is for the Lisp reader, so it keeps
the properties, but in the form a Lisp reader can read and apply to
the string.

You need to use 'format' if you want to keep text properties on the
produced string.  princ and prin1 are the wrong tool for the job.



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

* Re: What happens with text properties in batch mode?
       [not found] <mailman.5310.1544169515.1284.help-gnu-emacs@gnu.org>
@ 2018-12-08 18:31 ` andlind
  2018-12-08 20:08   ` Marcin Borkowski
  0 siblings, 1 reply; 8+ messages in thread
From: andlind @ 2018-12-08 18:31 UTC (permalink / raw)
  To: help-gnu-emacs

On Friday, 7 December 2018 08:58:38 UTC+1, Marcin Borkowski  wrote:

> it seems that when I `princ' something with text properties (e.g.,
> colored faces) in batch mode, the colors disappear.  Is it documented
> anywhere?  Can I disable this behavior?

Can you tell me what you are trying to accomplish? Simply printing a highlighted text stdout and expecting it to be shown with colors doesn't work.


> I found this: https://github.com/Lindydancer/e2ansi, and its existence
> suggests that outputting colored stuff (using ANSI codes) is
> non-trivial.  Am I right?

It is non-trivial, I can assure you, I spent many months writing it.

One problem is that even though strings have face properties in batch mode, the faces themselves often fail to specify anything useful in batch mode. e2ansi contains a system for playing the "what if" game by allowing you to query things like "what would face X look like when in a gui with 16 millions colors, or in a black-and-white tty". (This part is placed in a stand alone library "face-explorer", along with tons of useful tools.)

The second problem is to translate the face information to ANSI. Note that Emacs internal system for rendering things in terminal mode is not available to elisp, so I had to implement everything from scratch.

Fortunately, you can use e2ansi as a library in your own packages. For example `e2ansi-string-to-ansi' converts a string with face information to ANSI. See `face-explorer-number-of-colors' and friends to control which features of ANSI will be used. (They have sane defaults, though.)

    -- Anders Lindgren


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

* Re: What happens with text properties in batch mode?
  2018-12-07  8:42 ` tomas
@ 2018-12-08 19:28   ` Marcin Borkowski
  2018-12-08 22:02     ` tomas
  0 siblings, 1 reply; 8+ messages in thread
From: Marcin Borkowski @ 2018-12-08 19:28 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs


On 2018-12-07, at 09:42, tomas@tuxteam.de wrote:

> On Fri, Dec 07, 2018 at 08:56:23AM +0100, Marcin Borkowski wrote:
>> Hi all,
>> 
>> it seems that when I `princ' something with text properties (e.g.,
>> colored faces) in batch mode, the colors disappear.
>
> From a quick test here (which may be flawed, mind you), I can confirm
> that princ removes the properties from strings.
>
>> Is it documented anywhere?  Can I disable this behavior?
>
> I don't know about that. A cursory look at "print.c", and there, the C
> functions `print' and `print_object' suggest that yes, it's intentional,
> and it's pretty deeply rooted.

OK, thanks.

>> I found this: https://github.com/Lindydancer/e2ansi, and its existence
>> suggests that outputting colored stuff (using ANSI codes) is
>> non-trivial.  Am I right?
>
> I think this is only relevant if you are trying to colorize the output
> to an ANSI terminal (or more probably to an ANSI terminal emulator, like
> an Xterm or the Linux console, unless you're working at a computer
> museum, these days). Probably not relevant in your case, since `princ'
> outputs most of the time to some buffer-like thingy, but can be trained
> to do almost everything...
>
> What are you trying to achieve?

Well, quite relevant - if I run Emacs in batch mode, princ and friends
output to stdout.

Thanks,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: What happens with text properties in batch mode?
  2018-12-07  9:05 ` Eli Zaretskii
@ 2018-12-08 19:29   ` Marcin Borkowski
  0 siblings, 0 replies; 8+ messages in thread
From: Marcin Borkowski @ 2018-12-08 19:29 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


On 2018-12-07, at 10:05, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Marcin Borkowski <mbork@mbork.pl>
>> Date: Fri, 07 Dec 2018 08:56:23 +0100
>> 
>> it seems that when I `princ' something with text properties (e.g.,
>> colored faces) in batch mode, the colors disappear.  Is it documented
>> anywhere?  Can I disable this behavior?
>
> princ is for human consumption, so the text properties are not
> displayed.  There's prin1, which is for the Lisp reader, so it keeps
> the properties, but in the form a Lisp reader can read and apply to
> the string.
>
> You need to use 'format' if you want to keep text properties on the
> produced string.  princ and prin1 are the wrong tool for the job.

Actually, I don't - I was just curious why princ does TRT for me, and
couldn't find it documented.

Best,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: What happens with text properties in batch mode?
  2018-12-08 18:31 ` andlind
@ 2018-12-08 20:08   ` Marcin Borkowski
  0 siblings, 0 replies; 8+ messages in thread
From: Marcin Borkowski @ 2018-12-08 20:08 UTC (permalink / raw)
  To: andlind@gmail.com; +Cc: help-gnu-emacs


On 2018-12-08, at 19:31, andlind@gmail.com <andlind@gmail.com> wrote:

> On Friday, 7 December 2018 08:58:38 UTC+1, Marcin Borkowski  wrote:
>
>> it seems that when I `princ' something with text properties (e.g.,
>> colored faces) in batch mode, the colors disappear.  Is it documented
>> anywhere?  Can I disable this behavior?
>
> Can you tell me what you are trying to accomplish? Simply printing a highlighted text stdout and expecting it to be shown with colors doesn't work.

I was just curious what happens to the properties after princ.

>> I found this: https://github.com/Lindydancer/e2ansi, and its existence
>> suggests that outputting colored stuff (using ANSI codes) is
>> non-trivial.  Am I right?
>
> It is non-trivial, I can assure you, I spent many months writing it.
>
> One problem is that even though strings have face properties in batch mode, the faces themselves often fail to specify anything useful in batch mode. e2ansi contains a system for playing the "what if" game by allowing you to query things like "what would face X look like when in a gui with 16 millions colors, or in a black-and-white tty". (This part is placed in a stand alone library "face-explorer", along with tons of useful tools.)
>
> The second problem is to translate the face information to ANSI. Note that Emacs internal system for rendering things in terminal mode is not available to elisp, so I had to implement everything from scratch.
>
> Fortunately, you can use e2ansi as a library in your own packages. For example `e2ansi-string-to-ansi' converts a string with face information to ANSI. See `face-explorer-number-of-colors' and friends to control which features of ANSI will be used. (They have sane defaults, though.)

Thanks a lot for the details (and for e2ansi)!  I'll try to look into it some day.

Best,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: What happens with text properties in batch mode?
  2018-12-08 19:28   ` Marcin Borkowski
@ 2018-12-08 22:02     ` tomas
  0 siblings, 0 replies; 8+ messages in thread
From: tomas @ 2018-12-08 22:02 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 449 bytes --]

On Sat, Dec 08, 2018 at 08:28:26PM +0100, Marcin Borkowski wrote:
> 
> On 2018-12-07, at 09:42, tomas@tuxteam.de wrote:

[...]

> > What are you trying to achieve?
> 
> Well, quite relevant - if I run Emacs in batch mode, princ and friends
> output to stdout.

Well, you've found the better expert in Anders, but by now I guess
you see that the answer is, more or less "it depends on where stdout
is going to" :-)

Cheers
-- tomás

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

end of thread, other threads:[~2018-12-08 22:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-07  7:56 What happens with text properties in batch mode? Marcin Borkowski
2018-12-07  8:42 ` tomas
2018-12-08 19:28   ` Marcin Borkowski
2018-12-08 22:02     ` tomas
2018-12-07  9:05 ` Eli Zaretskii
2018-12-08 19:29   ` Marcin Borkowski
     [not found] <mailman.5310.1544169515.1284.help-gnu-emacs@gnu.org>
2018-12-08 18:31 ` andlind
2018-12-08 20:08   ` Marcin Borkowski

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.