summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2024-03-22 16:46:28 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2024-03-22 16:46:28 -0400
commit7269a2f1586733bd03b569608bd77112b2e6487f (patch)
tree9acfc5c656863bf6ce482f32e1ca273929e83a59 /lisp/emacs-lisp
parentaccd79c93935b50dddfcd6fe7fb6912c80bcddb1 (diff)
downloademacs-7269a2f1586733bd03b569608bd77112b2e6487f.tar.gz
emacs-7269a2f1586733bd03b569608bd77112b2e6487f.tar.bz2
emacs-7269a2f1586733bd03b569608bd77112b2e6487f.zip
(pp-fill): Cut before parens and dots
The `pp-fill` code sometimes end up generating things like: (foo . bar) instead of (foo . bar) so make sure we cut before rather than after the dot (and open parens while we're at it). * lisp/emacs-lisp/pp.el (pp-fill): Cut before parens and dots. * test/lisp/emacs-lisp/pp-tests.el (pp-tests--dimensions): New function. (pp-tests--cut-before): New test.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/pp.el14
1 files changed, 9 insertions, 5 deletions
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index de7468b3e38..b48f44545bf 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -193,11 +193,15 @@ it inserts and pretty-prints that arg at point."
(and
(save-excursion
(goto-char beg)
- (if (save-excursion (skip-chars-backward " \t({[',")
- (bolp))
- ;; The sexp was already on its own line.
- nil
- (skip-chars-backward " \t")
+ ;; We skip backward over open parens because cutting
+ ;; the line right after an open paren does not help
+ ;; reduce the indentation depth.
+ ;; Similarly, we prefer to cut before a "." than after
+ ;; it because it reduces the indentation depth.
+ (skip-chars-backward " \t({[',.")
+ (if (bolp)
+ ;; The sexp already starts on its own line.
+ (progn (goto-char beg) nil)
(setq beg (copy-marker beg t))
(if paired (setq paired (copy-marker paired t)))
;; We could try to undo this insertion if it