From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: save-excursion doesn't restore point with json-pretty-print Date: Fri, 01 Feb 2019 20:14:45 +0100 Message-ID: <87munfxqvu.fsf@gnu.org> References: <87lg2z7t23.fsf@gnu.org> <20190201095516.GB19478@tuxteam.de> <83r2cryg1p.fsf@gnu.org> <83o97vy7rx.fsf@gnu.org> <874l9nl74g.fsf@gnu.org> <835zu3xrry.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="167301"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 01 20:15:15 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpeHS-000hKk-8m for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Feb 2019 20:15:14 +0100 Original-Received: from localhost ([127.0.0.1]:60279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeHR-0001jx-7S for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Feb 2019 14:15:13 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeH3-0001jr-9d for help-gnu-emacs@gnu.org; Fri, 01 Feb 2019 14:14:50 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:48493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeH3-00085k-4H for help-gnu-emacs@gnu.org; Fri, 01 Feb 2019 14:14:49 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:58043) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1gpeH3-0004E3-0T; Fri, 01 Feb 2019 14:14:49 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 53CE621990; Fri, 1 Feb 2019 14:14:48 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 01 Feb 2019 14:14:48 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrjeekgdduvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufhffjg fkfgggtgesthdtredttdertdenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhs ughhsehgnhhurdhorhhgqeenucfkphepleefrddvfeeirdduvdelrdehvdenucfrrghrrg hmpehmrghilhhfrhhomhepthhhohhrnhdomhgvshhmthhprghuthhhphgvrhhsohhnrghl ihhthidqkeeijeefkeejkeegqdeifeehvdelkedqthhsughhpeepghhnuhdrohhrghesfh grshhtmhgrihhlrdhfmhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Original-Received: from thinkpad-t440p (p5dec8134.dip0.t-ipconnect.de [93.236.129.52]) by mail.messagingengine.com (Postfix) with ESMTPA id EA32B100E5; Fri, 1 Feb 2019 14:14:46 -0500 (EST) In-Reply-To: <835zu3xrry.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 01 Feb 2019 20:55:29 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:119192 Archived-At: Eli Zaretskii writes: >> > json-read-from-string uses a temporary buffer anyway, so a couple of >> > trivial changes in json-pretty-print should do the trick. >> >> Is this what you have in mind? Seems to work well. > > Yes. Ok, great. Do you think it would make sense to extract the mechanics of narrowing, extracting from the narrowed source buffer, and injecting (transformed) into the temporary buffer with which to replace the source region into some function (replace-region-contents beg end extract-fn inject-fn) That way, `json-pretty-print' would look like. --8<---------------cut here---------------start------------->8--- (defun json-pretty-print (begin end) "Pretty-print selected region." (interactive "r") (atomic-change-group (replace-region-contents begin end (lambda () (let ((json-encoding-pretty-print t) ;; Distinguish an empty objects from 'null' (json-null :json-null) ;; Ensure that ordering is maintained (json-object-type 'alist)) (json-read))) (lambda (json-obj) (json-encode json-obj))))) --8<---------------cut here---------------end--------------->8--- If so, where should I put it? subr.el? >> I'm just not sure if the save-excursion should be in >> `json-pretty-print' itself. I'd always want to have it but maybe >> there are use-cases where it would be wrong. > > Good question. I don't know the answer either. Then let's keep it the current way until someone complains which will probably never happen. Bye, Tassilo