1

When saving changes using customize Emacs serializes lists space separated. This makes for example the package-selected-packages variable extremely long and hard to scan over.

Is it possible to make Emacs serialize lists more like it does with alists (like package-archives below)? That is, one element per line?

Basically, I want this:

;;;; Custom mode ;;;;
(custom-set-variables
 …
 '(package-archives
   '(("gnu" . "http://elpa.gnu.org/packages/")
     ("melpa" . "http://melpa.org/packages/")
     ("melpa-stable" . "http://stable.melpa.org/packages/")))
 '(package-quickstart t)
 '(package-selected-packages '(ace-jump-mode add-node-modules-path  …  yaml-mode yatemplate))
 '(projectile-keymap-prefix "p")
 …
)

… to turn into this:

;;;; Custom mode ;;;;
(custom-set-variables
 …
 '(package-archives
   '(("gnu" . "http://elpa.gnu.org/packages/")
     ("melpa" . "http://melpa.org/packages/")
     ("melpa-stable" . "http://stable.melpa.org/packages/")))
 '(package-quickstart t)
 '(package-selected-packages 
   '(ace-jump-mode
     add-node-modules-path
     …
     yaml-mode
     yatemplate))
 '(projectile-keymap-prefix "p")
 …
)
Mattias Bengtsson
  • 1,300
  • 1
  • 11
  • 18

1 Answers1

2

The function that does this serializing (printing to your custom-file or init file) is custom-save-variables.

You would need to redefine or advise that function, to have it use pretty-printing (functions from library pp.el, such as pp-to-string and pp-display-expression) instead of regular printing.

For example, (pp-display-expression auto-mode-alist SOME-BUFFER) pretty-prints the value of auto-mode-alist, inserting newlines etc.


(You might also want to file an enhancement request, to have Emacs do this by default. To do that, use M-x report-emacs-bug.)

Drew
  • 77,472
  • 10
  • 114
  • 243
  • 1
    I don't think pp inserts newlines when printing long lists – rpluim Nov 27 '20 at 09:33
  • @rpluim: Yes, I didn't mean function pp itself but various functions in pp.el. I've replaced pp.el with "functions from library pp.el, such as pp-to-string and pp-display-expression". Function pp does include newlines, but you might not see them, depending on what you do with its return value. – Drew Dec 03 '20 at 17:13
  • pp-display-expression takes two arguments. Did you mean pp-to-string? – rpluim Dec 04 '20 at 10:13
  • @rpluim: Yes, I added a BUFFER arg. And the answer already mentioned pp-to-string (as well as pp-display-expression). The point is to pretty-print, using functions from pp.el. There is more than one way to pretty-print a Lisp value. – Drew Dec 04 '20 at 18:09
  • Sorry for the late reply, I forgot about this question after writing it! :D Thanks for the answer. It sounds like an interesting evening hack. I'll see if I can put something together at some point. – Mattias Bengtsson Dec 08 '20 at 13:27