From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Adam Spiers Newsgroups: gmane.emacs.devel Subject: custom-save-variables: pretty-printing long values Date: Thu, 11 Apr 2013 16:51:29 +0100 Message-ID: <20130411155129.GB6837@pacific.linksys.moosehall> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1365695505 16956 80.91.229.3 (11 Apr 2013 15:51:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Apr 2013 15:51:45 +0000 (UTC) To: emacs-devel mailing list Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 11 17:51:49 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UQJms-0001zb-Ry for ged-emacs-devel@m.gmane.org; Thu, 11 Apr 2013 17:51:46 +0200 Original-Received: from localhost ([::1]:48107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQJms-0001O4-Fm for ged-emacs-devel@m.gmane.org; Thu, 11 Apr 2013 11:51:46 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQJmm-0001HL-EE for emacs-devel@gnu.org; Thu, 11 Apr 2013 11:51:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQJmh-0004nG-IY for emacs-devel@gnu.org; Thu, 11 Apr 2013 11:51:40 -0400 Original-Received: from coral.adamspiers.org ([85.119.82.20]:55243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQJmh-0004mv-C2 for emacs-devel@gnu.org; Thu, 11 Apr 2013 11:51:35 -0400 Original-Received: from localhost (2.d.c.d.2.5.f.b.c.0.4.8.0.1.4.d.0.0.0.0.b.1.4.6.0.b.8.0.1.0.0.2.ip6.arpa [IPv6:2001:8b0:641b:0:d410:840c:bf52:dcd2]) by coral.adamspiers.org (Postfix) with ESMTPSA id C42B558EB3 for ; Thu, 11 Apr 2013 16:51:30 +0100 (BST) Content-Disposition: inline X-OS: GNU/Linux User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 85.119.82.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:158836 Archived-At: 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)