unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: ndame <emacsuser@freemail.hu>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: Shouldn't emacs print long lists with newlines?
Date: Wed, 07 Aug 2019 06:51:25 -0400	[thread overview]
Message-ID: <jwva7clfekv.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87muglxxns.fsf@web.de> (Michael Heerdegen's message of "Wed, 07 Aug 2019 09:05:59 +0200")

>> Shouldn't the printing code be smarter and print long lists with
>> newlines, every item in a separate line, to avoid the long line
>> issue?

[ My minibuffer is exactly 1-line tall (and it's a separate frame, so
  Emacs is not allowed to grow it), so spreading the output on several
  lines is not always a good solution.  ]

> If it should depends on the use case.  It should be able to do so when
> the user wants that - especially pretty printing (pp).  So far this has
> been discussed here and there, but so far nobody has implemented it.

I don't think Edebug tries to pretty print this, currently.

But if we want to improve the pretty printer to fold such "parenthesis
deserts", we can try a patch like the one below,


        Stefan


diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index de4cbfc0e1..21de326421 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -50,6 +50,33 @@ pp-to-string
     (pp-buffer)
     (buffer-string)))
 
+(defun pp--long-line ()
+  "Cut the line before point and before `fill-column' if needed."
+  ;; FIXME: This still leaves lines longer than fill-column because
+  ;; When pp-buffer calls us, the text is flush-left rather than
+  ;; properly indented, so (current-column) is not the real column at
+  ;; which the text will end up.
+  (let ((end (point)))
+    (when (> (current-column) fill-column)
+      (forward-line 0)
+      (let ((last nil))
+        (while (progn
+                 (skip-syntax-forward "^\"< \\")
+                 (skip-syntax-forward " ")
+                 (and (< (point) end)
+                      (or (< (current-column) fill-column)
+                          (null last))))
+          (setq last (point))
+          (pcase (char-syntax (char-after))
+            (?\\ (forward-char 2))
+            (?\" (forward-sexp 1))
+            (?\< (end-of-line))))
+        (when last
+          (goto-char last)
+          (skip-syntax-backward " ")
+          (delete-region (point) last)
+          (insert "\n"))))))
+
 ;;;###autoload
 (defun pp-buffer ()
   "Prettify the current buffer with printed representation of a Lisp object."
@@ -58,6 +85,7 @@ pp-buffer
     ;; (message "%06d" (- (point-max) (point)))
     (cond
      ((ignore-errors (down-list 1) t)
+      (pp--long-line)
       (save-excursion
         (backward-char 1)
         (skip-chars-backward "'`#^")
@@ -67,6 +95,7 @@ pp-buffer
            (progn (skip-chars-backward " \t\n") (point)))
           (insert "\n"))))
      ((ignore-errors (up-list 1) t)
+      (pp--long-line)
       (skip-syntax-forward ")")
       (delete-region
        (point)




  reply	other threads:[~2019-08-07 10:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-05 20:05 Shouldn't emacs print long lists with newlines? ndame
2019-08-07  7:05 ` Michael Heerdegen
2019-08-07 10:51   ` Stefan Monnier [this message]
2019-08-07 12:04     ` martin rudalics
2019-08-28 17:23       ` Stefan Monnier
2019-08-29  7:46         ` martin rudalics
2019-08-07 12:43   ` ndame
2019-08-07 14:28     ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwva7clfekv.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=emacsuser@freemail.hu \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).