all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Adam Spiers <emacs-devel@adamspiers.org>
To: emacs-devel mailing list <emacs-devel@gnu.org>
Subject: custom-save-variables: pretty-printing long values
Date: Thu, 11 Apr 2013 16:51:29 +0100	[thread overview]
Message-ID: <20130411155129.GB6837@pacific.linksys.moosehall> (raw)

This simple tweak to cus-edit ensures that custom variable values
which are over 60 bytes long get written to `custom-file' using
`indent-pp-sexp'.  For example:

    (custom-set-variables
     ;; custom-set-variables was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
[snipped]
     '(c-default-style
       (quote
        ((c-mode . "linux")
         (java-mode . "java")
         (awk-mode . "awk")
         (other . "gnu"))))

This not only makes the file much easier to read, but is particularly
useful when the file is tracked by a version control system, since
then the diffs become much more manageable.  For example, my setting
for `org-agenda-custom-commands' is 349 lines long (14989 characters).
When I recustomise that variable, the output of `git diff' is
almost completely illegible.

Are there any problems with this approach?  

Thanks!
Adam


diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 4ed72be..673ea44 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -4590,7 +4590,15 @@ This function does not save the buffer."
 	    (princ " '(")
 	    (prin1 symbol)
 	    (princ " ")
-	    (prin1 (car value))
+	    (let ((val (prin1-to-string (car value))))
+	      (if (< (length val) 60)
+		  (insert val)
+		(newline-and-indent)
+		(let ((beginning-of-val (point)))
+		  (insert val)
+		  (save-excursion
+		    (goto-char beginning-of-val)
+		    (indent-pp-sexp 1)))))
 	    (when (or now requests comment)
 	      (princ " ")
 	      (prin1 now)



             reply	other threads:[~2013-04-11 15:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 15:51 Adam Spiers [this message]
2013-04-11 16:15 ` custom-save-variables: pretty-printing long values Stefan Monnier
2013-04-11 19:07   ` Adam Spiers
2013-04-11 19:13     ` bug#14187: [PATCH] Pretty-print long values in custom variables Adam Spiers
2013-04-12  1:55       ` Stefan Monnier
2013-05-08  6:59         ` Glenn Morris

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

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

  git send-email \
    --in-reply-to=20130411155129.GB6837@pacific.linksys.moosehall \
    --to=emacs-devel@adamspiers.org \
    --cc=emacs-devel@gnu.org \
    /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 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.