From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ryan Crum Newsgroups: gmane.emacs.bugs Subject: bug#12634: Patch for pretty-printing in json.el Date: Sat, 17 Nov 2012 12:37:17 -0500 Message-ID: <9E9C89A9-FACE-47A9-BCC7-3AC5ABC64518@gmail.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: multipart/mixed; boundary="Apple-Mail=_B93A5F8F-358D-43B5-ABD5-2FBB43A6C19B" X-Trace: ger.gmane.org 1353177920 16589 80.91.229.3 (17 Nov 2012 18:45:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Nov 2012 18:45:20 +0000 (UTC) Cc: 12634@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Nov 17 19:45:31 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1TZnOS-0002LW-1F for geb-bug-gnu-emacs@m.gmane.org; Sat, 17 Nov 2012 19:45:28 +0100 Original-Received: from localhost ([::1]:53921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZnOI-0002gP-2P for geb-bug-gnu-emacs@m.gmane.org; Sat, 17 Nov 2012 13:45:18 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:44210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZnOB-0002dT-V3 for bug-gnu-emacs@gnu.org; Sat, 17 Nov 2012 13:45:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TZnO8-0005jy-SJ for bug-gnu-emacs@gnu.org; Sat, 17 Nov 2012 13:45:11 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40984) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZnO8-0005jr-Ox for bug-gnu-emacs@gnu.org; Sat, 17 Nov 2012 13:45:08 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TZnOz-0008O5-RC for bug-gnu-emacs@gnu.org; Sat, 17 Nov 2012 13:46:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ryan Crum Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Nov 2012 18:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12634 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12634-submit@debbugs.gnu.org id=B12634.135317795032212 (code B ref 12634); Sat, 17 Nov 2012 18:46:01 +0000 Original-Received: (at 12634) by debbugs.gnu.org; 17 Nov 2012 18:45:50 +0000 Original-Received: from localhost ([127.0.0.1]:51232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TZnOn-0008NV-Pg for submit@debbugs.gnu.org; Sat, 17 Nov 2012 13:45:50 -0500 Original-Received: from mail-gh0-f172.google.com ([209.85.160.172]:47893) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TZmLO-0006rh-CR for 12634@debbugs.gnu.org; Sat, 17 Nov 2012 12:38:16 -0500 Original-Received: by mail-gh0-f172.google.com with SMTP id g10so723429ghb.3 for <12634@debbugs.gnu.org>; Sat, 17 Nov 2012 09:37:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to:x-mailer:x-gm-message-state; bh=e5WYfgIwe230rv57TR1HzTxMJyY0LpnQWxBx0PDmtwI=; b=RQqrNH5gLlj3mOfDExVVpMFYKw8+QRdU9WCvej3hIp6bd0ZNGx8LMoXK53EZvPqxuZ hy8hzfovmrHOuP3Vl615snpWhWYW4NpzXuUnatN70wEfOdtsHAt8cR5/fp+mfm8z2twU GHEl1wh8Ah0Ei/HpZusSqNM95yVvhSbW6CKZmLlGhWw1VeAb2C7gHt+lhg7wxAQhgCcJ Yhwd6eKknX8M5H7yBoKx510tQrL6iEoCWWcQXhqqZUH2um5qJQfsX0UikhCL70DLPp7Y mHwYTe9riM0DLVwB046DE5bCdonXywY6BMyXCYsroztb9X5dpYt++zn5JgVj1zf8VJZK Rg8A== Original-Received: by 10.236.87.208 with SMTP id y56mr7825292yhe.9.1353173839706; Sat, 17 Nov 2012 09:37:19 -0800 (PST) Original-Received: from [192.168.1.55] ([24.49.197.147]) by mx.google.com with ESMTPS id s21sm4845082yhb.5.2012.11.17.09.37.18 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 17 Nov 2012 09:37:18 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.1278) X-Gm-Message-State: ALoCoQkVOED6oMgW2zytAkIO39Krnfneu7ejNrZkqYniO+YdTlAzCOxEOYWJWheNFGRPSOCO5OHO X-Spam-Score: 0.1 (/) X-Mailman-Approved-At: Sat, 17 Nov 2012 13:45:48 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-Spam-Score: -0.7 (/) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:67068 Archived-At: --Apple-Mail=_B93A5F8F-358D-43B5-ABD5-2FBB43A6C19B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi Stefan, I actually have not yet received anything regarding copyright assignment = in the mail, so I resubmitted the questionnaire to assign@gnu.org today. New patch attached. --Apple-Mail=_B93A5F8F-358D-43B5-ABD5-2FBB43A6C19B Content-Disposition: attachment; filename=json-pretty-print.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="json-pretty-print.diff" Content-Transfer-Encoding: quoted-printable ***=20a/json.el=0A---=20b/json.el=0A***************=0A***=203,9=20****=0A= =20=20;;=20Copyright=20(C)=202006-2012=20Free=20Software=20Foundation,=20= Inc.=0A=20=20=0A=20=20;;=20Author:=20Edward=20O'Connor=20= =0A!=20;;=20Version:=201.3=0A=20=20;;=20Keywords:=20= convenience=0A=20=20=0A=20=20;;=20This=20file=20is=20part=20of=20GNU=20= Emacs.=0A---=203,9=20----=0A=20=20;;=20Copyright=20(C)=202006-2012=20= Free=20Software=20Foundation,=20Inc.=0A=20=20=0A=20=20;;=20Author:=20= Edward=20O'Connor=20=0A!=20;;=20Version:=201.4=0A=20=20= ;;=20Keywords:=20convenience=0A=20=20=0A=20=20;;=20This=20file=20is=20= part=20of=20GNU=20Emacs.=0A***************=0A***=2048,53=20****=0A---=20= 48,54=20----=0A=20=20;;=202006-12-29=20-=20XEmacs=20support,=20from=20= Aidan=20Kehoe=20.=0A=20=20;;=202008-02-21=20-=20= Installed=20in=20GNU=20Emacs.=0A=20=20;;=202011-10-17=20-=20Patch=20= `json-alist-p'=20and=20`json-plist-p'=20to=20avoid=20recursion=20-tzz=0A= +=20;;=202012-10-25=20-=20Added=20pretty-printed=20reformatting=20-Ryan=20= Crum=20(ryan@ryancrum.org)=0A=20=20=0A=20=20;;;=20Code:=0A=20=20=0A= ***************=0A***=2099,104=20****=20If=20this=20has=20the=20same=20= value=20as=20`json-false',=20you=20might=20not=20be=20able=20to=0A---=20= 100,122=20----=0A=20=20tell=20the=20difference=20between=20`false'=20and=20= `null'.=20=20Consider=20let-binding=0A=20=20this=20around=20your=20call=20= to=20`json-read'=20instead=20of=20`setq'ing=20it.")=0A=20=20=0A+=20= (defvar=20json-encoding-separator=20","=0A+=20=20=20"Value=20to=20use=20= as=20an=20element=20seperator=20when=20encoding.")=0A+=20=0A+=20(defvar=20= json-encoding-default-indentation=20"=20=20"=0A+=20=20=20"The=20default=20= indentation=20level=20for=20encoding.=0A+=20Used=20only=20when=20= `json-encoding-pretty-print'=20is=20non-nil.")=0A+=20=0A+=20(defvar=20= json--encoding-current-indentation=20"\n"=0A+=20=20=20"Internally=20used=20= to=20keep=20track=20of=20the=20current=20indentation=20level=20of=20= encoding.=0A+=20Used=20only=20when=20`json-encoding-pretty-print'=20is=20= non-nil.")=0A+=20=0A+=20(defvar=20json-encoding-pretty-print=20nil=0A+=20= =20=20"If=20non-nil,=20then=20the=20output=20of=20`json-encode'=20will=20= be=20pretty-printed.")=0A+=20=0A+=20(defvar=20= json-encoding-lisp-style-closings=20nil=0A+=20=20=20"If=20non-nil,=20]=20= and=20}=20closings=20will=20be=20formatted=20lisp-style,=20without=20= indentation.")=0A+=20=0A=20=20=0C=0A=20=20=0A=20=20;;;=20Utilities=0A= ***************=0A***=20124,129=20****=20this=20around=20your=20call=20= to=20`json-read'=20instead=20of=20`setq'ing=20it.")=0A---=20142,155=20= ----=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'not-plist)))=0A=20=20=20=20(null=20list))=0A=20=20=0A+=20(defmacro=20= json--with-indentation=20(body)=0A+=20=20=20`(let=20= ((json--encoding-current-indentation=0A+=20=20=20=20=20=20=20=20=20=20=20= (if=20json-encoding-pretty-print=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(concat=20json--encoding-current-indentation=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= json-encoding-default-indentation)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20"")))=0A+=20=20=20=20=20=20,body))=0A+=20=0A=20=20;;=20Reader=20= utilities=0A=20=20=0A=20=20(defsubst=20json-advance=20(&optional=20n)=0A= ***************=0A***=20402,442=20****=20Please=20see=20the=20= documentation=20of=20`json-object-type'=20and=20`json-key-type'."=0A=20=20= =0A=20=20(defun=20json-encode-hash-table=20(hash-table)=0A=20=20=20=20= "Return=20a=20JSON=20representation=20of=20HASH-TABLE."=0A!=20=20=20= (format=20"{%s}"=0A=20=20=20=20=20=20=20=20=20=20=20=20(json-join=0A=20=20= =20=20=20=20=20=20=20=20=20=20=20(let=20(r)=0A!=20=20=20=20=20=20=20=20=20= =20=20=20=20=20(maphash=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (lambda=20(k=20v)=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (push=20(format=20"%s:%s"=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(json-encode-key=20k)=0A= !=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(json-encode=20v))=0A!=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20r))=0A!=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20hash-table)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20r)=0A!=20=20=20=20=20=20=20=20=20=20=20=20",=20")))=0A=20=20=0A=20=20= ;;=20List=20encoding=20(including=20alists=20and=20plists)=0A=20=20=0A=20= =20(defun=20json-encode-alist=20(alist)=0A=20=20=20=20"Return=20a=20JSON=20= representation=20of=20ALIST."=0A!=20=20=20(format=20"{%s}"=0A!=20=20=20=20= =20=20=20=20=20=20=20(json-join=20(mapcar=20(lambda=20(cons)=0A!=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(format=20"%s:%s"=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(json-encode-key=20(car=20cons))=0A!=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20(json-encode=20(cdr=20cons))))=0A!=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20alist)=0A!=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20",=20")))=0A= =20=20=0A=20=20(defun=20json-encode-plist=20(plist)=0A=20=20=20=20= "Return=20a=20JSON=20representation=20of=20PLIST."=0A=20=20=20=20(let=20= (result)=0A!=20=20=20=20=20(while=20plist=0A!=20=20=20=20=20=20=20(push=20= (concat=20(json-encode-key=20(car=20plist))=0A!=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20":"=0A!=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(json-encode=20(cadr=20plist)))=0A!=20=20= =20=20=20=20=20=20=20=20=20=20=20result)=0A!=20=20=20=20=20=20=20(setq=20= plist=20(cddr=20plist)))=0A!=20=20=20=20=20(concat=20"{"=20(json-join=20= (nreverse=20result)=20",=20")=20"}")))=0A=20=20=0A=20=20(defun=20= json-encode-list=20(list)=0A=20=20=20=20"Return=20a=20JSON=20= representation=20of=20LIST.=0A---=20428,497=20----=0A=20=20=0A=20=20= (defun=20json-encode-hash-table=20(hash-table)=0A=20=20=20=20"Return=20a=20= JSON=20representation=20of=20HASH-TABLE."=0A!=20=20=20(format=20"{%s%s}"=0A= =20=20=20=20=20=20=20=20=20=20=20=20(json-join=0A=20=20=20=20=20=20=20=20= =20=20=20=20=20(let=20(r)=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (json--with-indentation=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (maphash=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(lambda=20(k=20= v)=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(push=20= (format=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(if=20json-encoding-pretty-print=0A!=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20"%s%s:=20%s"=0A= !=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20"%s%s:%s")=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20json--encoding-current-indentation=0A!=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (json-encode-key=20k)=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(json-encode=20v))=0A!=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20r))=0A!=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20hash-table))=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20r)=0A!=20=20=20=20=20=20=20=20=20=20=20=20= json-encoding-separator)=0A!=20=20=20=20=20=20=20=20=20=20=20(if=20(or=20= (not=20json-encoding-pretty-print)=0A!=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20json-encoding-lisp-style-closings)=0A!=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20""=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20= json--encoding-current-indentation)))=0A=20=20=0A=20=20;;=20List=20= encoding=20(including=20alists=20and=20plists)=0A=20=20=0A=20=20(defun=20= json-encode-alist=20(alist)=0A=20=20=20=20"Return=20a=20JSON=20= representation=20of=20ALIST."=0A!=20=20=20(format=20"{%s%s}"=0A!=20=20=20= =20=20=20=20=20=20=20=20(json-join=0A!=20=20=20=20=20=20=20=20=20=20=20=20= (json--with-indentation=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20= (mapcar=20(lambda=20(cons)=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(format=20(if=20json-encoding-pretty-print=0A!=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20"%s%s:=20%s"=0A!=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "%s%s:%s")=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20json--encoding-current-indentation=0A!=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20(json-encode-key=20(car=20cons))=0A!=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (json-encode=20(cdr=20cons))))=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20alist))=0A!=20=20=20=20=20=20=20=20=20=20=20=20= json-encoding-separator)=0A!=20=20=20=20=20=20=20=20=20=20=20(if=20(or=20= (not=20json-encoding-pretty-print)=0A!=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20json-encoding-lisp-style-closings)=0A!=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20""=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20= json--encoding-current-indentation)))=0A=20=20=0A=20=20(defun=20= json-encode-plist=20(plist)=0A=20=20=20=20"Return=20a=20JSON=20= representation=20of=20PLIST."=0A=20=20=20=20(let=20(result)=0A!=20=20=20=20= =20(json--with-indentation=0A!=20=20=20=20=20=20=20(while=20plist=0A!=20=20= =20=20=20=20=20=20=20(push=20(concat=0A!=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20json--encoding-current-indentation=0A!=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(json-encode-key=20(car=20plist))=0A!=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(if=20json-encoding-pretty-print=0A= !=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20":=20"=0A!=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20":")=0A!=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(json-encode=20(cadr=20plist)))=0A!=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20result)=0A!=20=20=20=20=20=20=20=20= =20(setq=20plist=20(cddr=20plist))))=0A!=20=20=20=20=20(concat=20"{"=0A!=20= =20=20=20=20=20=20=20=20=20=20=20=20(json-join=20(nreverse=20result)=20= json-encoding-separator)=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20(if=20= (and=20json-encoding-pretty-print=0A!=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20(not=20json-encoding-lisp-style-closings))=0A= !=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= json--encoding-current-indentation=0A!=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20"")=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20"}")))=0A=20=20=0A= =20=20(defun=20json-encode-list=20(list)=0A=20=20=20=20"Return=20a=20= JSON=20representation=20of=20LIST.=0A***************=0A***=20475,481=20= ****=20become=20JSON=20objects."=0A=20=20=0A=20=20(defun=20= json-encode-array=20(array)=0A=20=20=20=20"Return=20a=20JSON=20= representation=20of=20ARRAY."=0A!=20=20=20(concat=20"["=20(mapconcat=20= 'json-encode=20array=20",=20")=20"]"))=0A=20=20=0A=20=20=0C=0A=20=20=0A= ---=20530,551=20----=0A=20=20=0A=20=20(defun=20json-encode-array=20= (array)=0A=20=20=20=20"Return=20a=20JSON=20representation=20of=20ARRAY."=0A= !=20=20=20(if=20(and=20json-encoding-pretty-print=0A!=20=20=20=20=20=20=20= =20=20=20=20=20(>=20(length=20array)=200))=0A!=20=20=20=20=20=20=20= (concat=0A!=20=20=20=20=20=20=20=20(json--with-indentation=0A!=20=20=20=20= =20=20=20=20=20=20(concat=20(format=20"[%s"=20= json--encoding-current-indentation)=0A!=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20(json-join=20(mapcar=20'json-encode=20array)=0A!=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(format=20"%s%s"=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= json-encoding-separator=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= json--encoding-current-indentation))))=0A!=20=20=20=20=20=20=20=20= (format=20"%s]"=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(if=20= json-encoding-lisp-style-closings=0A!=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20""=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20json--encoding-current-indentation)))=0A!=20=20=20=20=20(concat=20= "["=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20(mapconcat=20'json-encode=20= array=20json-encoding-separator)=0A!=20=20=20=20=20=20=20=20=20=20=20=20=20= "]")))=0A=20=20=0A=20=20=0C=0A=20=20=0A***************=0A***=20542,547=20= ****=20Advances=20point=20just=20past=20JSON=20object."=0A---=20612,644=20= ----=0A=20=20=20=20=20=20=20=20=20=20((listp=20object)=20=20=20=20=20=20=20= =20(json-encode-list=20object))=0A=20=20=20=20=20=20=20=20=20=20(t=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(signal=20= 'json-error=20(list=20object)))))=0A=20=20=0A+=20;;=20Pretty=20printing=0A= +=20=0A+=20(defun=20json-pretty-print-buffer=20()=0A+=20=20=20= "Pretty-print=20current=20buffer."=0A+=20=20=20(interactive)=0A+=20=20=20= (let*=20((json-encoding-pretty-print=20t)=0A+=20=20=20=20=20=20=20=20=20=20= (json-string=20(json-encode=20(json-read-from-string=20= (buffer-string))))=0A+=20=20=20=20=20=20=20=20=20=20(buf=20= (current-buffer)))=0A+=20=20=20=20=20(with-current-buffer=20buf=0A+=20=20= =20=20=20=20=20(erase-buffer)=0A+=20=20=20=20=20=20=20(insert=20= json-string))))=0A+=20=0A+=20(defun=20json-pretty-print=20()=0A+=20=20=20= "Pretty-print=20selected=20region."=0A+=20=20=20(interactive)=0A+=20=20=20= (unless=20mark-active=0A+=20=20=20=20=20(error=20"No=20region=20= selected."))=0A+=20=20=20(let=20((begin=20(region-beginning))=0A+=20=20=20= =20=20=20=20=20=20(end=20(region-end))=0A+=20=20=20=20=20=20=20=20=20= (json-encoding-pretty-print=20t))=0A+=20=20=20=20=20(kill-region=20begin=20= end)=0A+=20=20=20=20=20(condition-case-unless-debug=20err=0A+=20=20=20=20= =20=20=20=20=20(insert=20(json-encode=20(json-read-from-string=20= (current-kill=200))))=0A+=20=20=20=20=20=20=20(error=0A+=20=20=20=20=20=20= =20=20=20(insert=20(current-kill=200))=0A+=20=20=20=20=20=20=20=20=20= (error=20"Unable=20to=20parse=20JSON.")))))=0A+=20=0A=20=20(provide=20= 'json)=0A=20=20=0A=20=20;;;=20json.el=20ends=20here=0A= --Apple-Mail=_B93A5F8F-358D-43B5-ABD5-2FBB43A6C19B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Nov 14, 2012, at 8:56 PM, Stefan Monnier wrote: > Use a "json--" prefix, since it's a convention we use to express that > something is internal. Fixed. > The first line of a docstring should "stand on it own", i.e. it > shouldn't end in the middle of a sentence. > Try C-u M-x checkdoc-current-buffer. Ah, cool feature. Fixed. >=20 >> (defun json-encode-hash-table (hash-table) >> "Return a JSON representation of HASH-TABLE." >> - (format "{%s}" >> + (format (if json-encoding-pretty-print "{%s%s}" "{%s}") >=20 > Hmm... if json-encoding-pretty-print is nil, we still pass 2 args, and > the second is always "", so we can always use "{%s%s}", right? Not exactly, since json--encoding-current-indentation defaults to = newline. I've tweaked this part to shift the complexity down into the = second clause, however, instead of specifying 2 formats with a = potentially unused second argument. >> - (concat "[" (mapconcat 'json-encode array ", ") "]")) >> + (if (and json-encoding-pretty-print >> + (> (length array) 0)) >> + (concat >> + (let ((json-encoding-current-indentation >> + (concat json-encoding-current-indentation >> + json-encoding-default-indentation))) >=20 > Use json--with-indentation here (even if it performs an extra = redundant > test of json-encoding-pretty-print). Agreed, fixed. I've also added an error handling clause to fix a bug I noticed where if = you attempt to `json-pretty-print' some invalid JSON your text gets = killed but formatting fails and it doesn't get replaced. Is there a more = idiomatic way of doing this? I considered using copy-region-as-kill and = then only killing the text if the call to json-encode succeeds, but that = seemed more awkward. Thanks for your help! -Ryan= --Apple-Mail=_B93A5F8F-358D-43B5-ABD5-2FBB43A6C19B--