bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#21798: 25.0.50; [PATCH] Add support for retrieving paths to JSON ele


From: Simen Heggestøyl
Subject: bug#21798: 25.0.50; [PATCH] Add support for retrieving paths to JSON elements
Date: Sun, 01 Nov 2015 20:52:33 +0100

Hi Dmitry, thanks for the feedback!

On Sat, Oct 31, 2015 at 3:23 PM, Dmitry Gutov <dgutov@yandex.ru> wrote:
The video looks great, but the inline patch lacks indentation, and doesn't apply (dunno if the former is the cause of the latter). Please resend it as an attachment.

Ah, yes, it appear that the whitespace got lost in the email for some
reason. I'll try attaching it to this email.

To test it, I've been using the following interactive function:

  (defun json-mode-show-path ()
    "Show the path to the JSON value under point."
    (interactive)
    (let ((path (json-path-to-position (point))))
      (if path
          (let ((formatted-path
                 (json-mode--format-path (plist-get path :path))))
            (pulse-momentary-highlight-region
             (plist-get path :match-start)
             (plist-get path :match-end))
            (message formatted-path)
            (kill-new formatted-path))
        (message "Not a JSON value"))))
  
  (defun json-mode--format-path (path)
    "Return PATH formatted as a JSON data selector.
  PATH should be a list of keys, which can be either strings or
  integers."
    (mapconcat (lambda (key) (format "[%S]" key)) path ""))

It's also included it in json-mode.el:
http://folk.uio.no/simenheg/json-mode.el.

Without trying it, my main concern would be any performance regression to json-read (it's not particularly fast already). Have you done any benchmarking?

I agree that would be bad. I'll try to produce some benchmarks when
I've got some free time on my hands!

-- Simen

Attachment: 0001-Add-support-for-retrieving-paths-to-JSON-elements.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]