all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* custom-save-variables: pretty-printing long values
@ 2013-04-11 15:51 Adam Spiers
  2013-04-11 16:15 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Adam Spiers @ 2013-04-11 15:51 UTC (permalink / raw)
  To: emacs-devel mailing list

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)



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: custom-save-variables: pretty-printing long values
  2013-04-11 15:51 custom-save-variables: pretty-printing long values Adam Spiers
@ 2013-04-11 16:15 ` Stefan Monnier
  2013-04-11 19:07   ` Adam Spiers
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-04-11 16:15 UTC (permalink / raw)
  To: Adam Spiers; +Cc: emacs-devel mailing list

> 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:

Looks like a good idea.


        Stefan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: custom-save-variables: pretty-printing long values
  2013-04-11 16:15 ` 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
  0 siblings, 1 reply; 6+ messages in thread
From: Adam Spiers @ 2013-04-11 19:07 UTC (permalink / raw)
  To: emacs-devel mailing list

On Thu, Apr 11, 2013 at 12:15:15PM -0400, Stefan Monnier wrote:
> > 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:
> 
> Looks like a good idea.

Thanks - I'll rebase on latest git master and resubmit to
bug-gnu-emacs.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#14187: [PATCH] Pretty-print long values in custom variables
  2013-04-11 19:07   ` Adam Spiers
@ 2013-04-11 19:13     ` Adam Spiers
  2013-04-12  1:55       ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Adam Spiers @ 2013-04-11 19:13 UTC (permalink / raw)
  To: 14187

* cus-edit.el (custom-save-variables): When a custom value is over 60
characters long, insert it using indent-pp-sexp so that the value is
more legible through being split over multiple lines.  This is
particularly useful when `custom-file' is tracked by a version control
system, since then the diffs become much more manageable.
---
 lisp/cus-edit.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index d19e2de..8a018cb 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -4529,7 +4529,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)
-- 
1.8.2.1.347.gbef22ca






^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#14187: [PATCH] Pretty-print long values in custom variables
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-04-12  1:55 UTC (permalink / raw)
  To: Adam Spiers; +Cc: 14187

> * cus-edit.el (custom-save-variables): When a custom value is over 60
> characters long, insert it using indent-pp-sexp so that the value is
> more legible through being split over multiple lines.  This is
> particularly useful when `custom-file' is tracked by a version control
> system, since then the diffs become much more manageable.

Looks good, thank you, please install,


        Stefan





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#14187: [PATCH] Pretty-print long values in custom variables
  2013-04-12  1:55       ` Stefan Monnier
@ 2013-05-08  6:59         ` Glenn Morris
  0 siblings, 0 replies; 6+ messages in thread
From: Glenn Morris @ 2013-05-08  6:59 UTC (permalink / raw)
  To: 14187-done

Version: 24.4

Nothing happened, so I installed this.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-08  6:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-11 15:51 custom-save-variables: pretty-printing long values Adam Spiers
2013-04-11 16:15 ` 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

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.