]> git.eshelyaron.com Git - emacs.git/commitdiff
Try harder to keep lines short in pp-emacs-lisp-code
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 4 Nov 2021 22:32:51 +0000 (23:32 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 4 Nov 2021 22:32:51 +0000 (23:32 +0100)
* lisp/emacs-lisp/pp.el (pp--insert): Try harder to keep lines short.

lisp/emacs-lisp/pp.el

index df837fa691e6d6ad35e3c48631a09e82abe99e3a..ffaa2aeb93a58bb1c021fe55a3a6c0aaf5065222 100644 (file)
@@ -333,7 +333,17 @@ Ignores leading comment characters."
       (save-excursion
         (goto-char start)
         (unless (looking-at "[ \t]+$")
-          (insert "\n"))))))
+          (insert "\n"))
+        (pp--indent-buffer)
+        (goto-char (point-max))
+        ;; If we're still too wide, then go up one step and try to
+        ;; insert a newline there.
+        (when (> (current-column) (window-width))
+          (condition-case ()
+              (backward-up-list 1)
+            (:success (when (looking-back " " 2)
+                        (insert "\n")))
+            (error nil)))))))
 
 (defun pp--indent-buffer ()
   (goto-char (point-min))