all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Messages - Avoiding newlines
@ 2020-12-08 12:51 pietru
  2020-12-08 13:29 ` Stefan Möding
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: pietru @ 2020-12-08 12:51 UTC (permalink / raw)
  To: Help Gnu Emacs

I would like to print some values but I am getting a new-line
after (pp bounds).  Haw may I avoid it?

(message "Bounds: %s [%s, %s]" (pp bounds) $ma $mb)

Result:

Bounds: (78 . 84)
 [78, 84]






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

* Re: Messages - Avoiding newlines
  2020-12-08 12:51 Messages - Avoiding newlines pietru
@ 2020-12-08 13:29 ` Stefan Möding
  2020-12-08 13:47   ` 2QdxY4RzWzUUiLuE
                     ` (2 more replies)
  2020-12-08 15:32 ` Michael Heerdegen
  2020-12-15  3:34 ` Tim Landscheidt
  2 siblings, 3 replies; 7+ messages in thread
From: Stefan Möding @ 2020-12-08 13:29 UTC (permalink / raw)
  To: help-gnu-emacs

pietru@caramail.com writes:

> I would like to print some values but I am getting a new-line
> after (pp bounds).  Haw may I avoid it?

You could remove the trailing newlines returned by pp:

(message "Bounds: %s [%s, %s]"
         (replace-regexp-in-string "\n+$" "" (pp bounds)) $ma $mb)

pp (Pretty Print) is meant to be used interactively so the newline make
sense when showing the output on a terminal.

-- 
Stefan



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

* Re: Messages - Avoiding newlines
  2020-12-08 13:29 ` Stefan Möding
@ 2020-12-08 13:47   ` 2QdxY4RzWzUUiLuE
  2020-12-08 13:47   ` pietru
  2020-12-08 14:23   ` pietru
  2 siblings, 0 replies; 7+ messages in thread
From: 2QdxY4RzWzUUiLuE @ 2020-12-08 13:47 UTC (permalink / raw)
  To: help-gnu-emacs

On 2020-12-08 at 14:29:20 +0100,
Stefan Möding <s.moeding@gmail.com> wrote:

> pietru@caramail.com writes:
> 
> > I would like to print some values but I am getting a new-line
> > after (pp bounds).  Haw may I avoid it?
> 
> You could remove the trailing newlines returned by pp:
> 
> (message "Bounds: %s [%s, %s]"
>          (replace-regexp-in-string "\n+$" "" (pp bounds)) $ma $mb)

A regular expression is a heavyweight solution to this problem.  Try a
substring containing all but the trailing newline:

    (substring (pp bounds t) 0 -1)

> pp (Pretty Print) is meant to be used interactively so the newline
> make sense when showing the output on a terminal.

Note also that by passing a second argument to pp, you can suppress pp's
output and make it just return the string.

HTH,
Dan



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

* Re: Messages - Avoiding newlines
  2020-12-08 13:29 ` Stefan Möding
  2020-12-08 13:47   ` 2QdxY4RzWzUUiLuE
@ 2020-12-08 13:47   ` pietru
  2020-12-08 14:23   ` pietru
  2 siblings, 0 replies; 7+ messages in thread
From: pietru @ 2020-12-08 13:47 UTC (permalink / raw)
  To: Stefan Möding; +Cc: help-gnu-emacs


> Sent: Tuesday, December 08, 2020 at 2:29 PM
> From: "Stefan Möding" <s.moeding@gmail.com>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Messages - Avoiding newlines
>
> pietru@caramail.com writes:
> 
> > I would like to print some values but I am getting a new-line
> > after (pp bounds).  Haw may I avoid it?
> 
> You could remove the trailing newlines returned by pp:
> 
> (message "Bounds: %s [%s, %s]"
>          (replace-regexp-in-string "\n+$" "" (pp bounds)) $ma $mb)
> 
> pp (Pretty Print) is meant to be used interactively so the newline make
> sense when showing the output on a terminal.

Thusly I can simply use 

(message "Bounds: %s %s %s" bounds $ma $mb)

 
> -- 
> Stefan
> 
>



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

* Re: Messages - Avoiding newlines
  2020-12-08 13:29 ` Stefan Möding
  2020-12-08 13:47   ` 2QdxY4RzWzUUiLuE
  2020-12-08 13:47   ` pietru
@ 2020-12-08 14:23   ` pietru
  2 siblings, 0 replies; 7+ messages in thread
From: pietru @ 2020-12-08 14:23 UTC (permalink / raw)
  To: Stefan Möding; +Cc: help-gnu-emacs

When using 

(message "\nBounds: %s | $ma $mb [%s,%s] |"
   (replace-regexp-in-string "\n+$" "" (pp bounds)) $ma $mb)

I get

-------- result --------
(78 . 84)


Bounds: (78 . 84) | $ma $mb [78,84] |
------ result --------


> Sent: Tuesday, December 08, 2020 at 2:29 PM
> From: "Stefan Möding" <s.moeding@gmail.com>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Messages - Avoiding newlines
>
> pietru@caramail.com writes:
> 
> > I would like to print some values but I am getting a new-line
> > after (pp bounds).  Haw may I avoid it?
> 
> You could remove the trailing newlines returned by pp:
> 
> (message "Bounds: %s [%s, %s]"
>          (replace-regexp-in-string "\n+$" "" (pp bounds)) $ma $mb)
> 
> pp (Pretty Print) is meant to be used interactively so the newline make
> sense when showing the output on a terminal.
> 
> -- 
> Stefan
> 
>



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

* Re: Messages - Avoiding newlines
  2020-12-08 12:51 Messages - Avoiding newlines pietru
  2020-12-08 13:29 ` Stefan Möding
@ 2020-12-08 15:32 ` Michael Heerdegen
  2020-12-15  3:34 ` Tim Landscheidt
  2 siblings, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2020-12-08 15:32 UTC (permalink / raw)
  To: help-gnu-emacs

pietru@caramail.com writes:

> I would like to print some values but I am getting a new-line
> after (pp bounds).  Haw may I avoid it?
>
> (message "Bounds: %s [%s, %s]" (pp bounds) $ma $mb)

`pp' prints the output by itself.  You want `pp-to-string' when you want
to use the result(s) in `message'.  But yes: for simple values using
`pp' doesn't make a difference.  All it does is more or less adding some
newlines to make large structures more readable.

Michael.




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

* Re: Messages - Avoiding newlines
  2020-12-08 12:51 Messages - Avoiding newlines pietru
  2020-12-08 13:29 ` Stefan Möding
  2020-12-08 15:32 ` Michael Heerdegen
@ 2020-12-15  3:34 ` Tim Landscheidt
  2 siblings, 0 replies; 7+ messages in thread
From: Tim Landscheidt @ 2020-12-15  3:34 UTC (permalink / raw)
  To: help-gnu-emacs

pietru@caramail.com wrote:

> I would like to print some values but I am getting a new-line
> after (pp bounds).  Haw may I avoid it?

> (message "Bounds: %s [%s, %s]" (pp bounds) $ma $mb)

> Result:

> Bounds: (78 . 84)
>  [78, 84]

Not strictly what you ask for, but for "simple" data struc-
tures, the "%S" format might fit your requirements:

| ELISP> (let*
|            ((bounds '(78 . 84))
|             ($ma (car bounds))
|             ($mb (cdr bounds)))
|          (message "Bounds: %S [%s, %s]" bounds $ma $mb))
                             ^^
| "Bounds: (78 . 84) [78, 84]"
| ELISP>

In this specific case, it is equivalent to "%s"; but this is
different when for example you are printing (structures con-
taining) strings.

Tim




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

end of thread, other threads:[~2020-12-15  3:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-08 12:51 Messages - Avoiding newlines pietru
2020-12-08 13:29 ` Stefan Möding
2020-12-08 13:47   ` 2QdxY4RzWzUUiLuE
2020-12-08 13:47   ` pietru
2020-12-08 14:23   ` pietru
2020-12-08 15:32 ` Michael Heerdegen
2020-12-15  3:34 ` Tim Landscheidt

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.