emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master 20eb60d: * json-mode/json-mode.el: Add which-func support


From: Stefan Monnier
Subject: [elpa] master 20eb60d: * json-mode/json-mode.el: Add which-func support
Date: Wed, 22 Jul 2020 13:41:11 -0400 (EDT)

branch: master
commit 20eb60d951347e81541b5474bd360d6366898f8e
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * json-mode/json-mode.el: Add which-func support
    
    (json--which-func): New function.
    (json-mode): Use it.
    (json-mode--keywords): New var.
    (json-mode-font-lock-keywords): Use it instead of the obsolete
    `json-keywords`.
---
 packages/json-mode/json-mode.el | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/packages/json-mode/json-mode.el b/packages/json-mode/json-mode.el
index 4c87a81..6f71836 100644
--- a/packages/json-mode/json-mode.el
+++ b/packages/json-mode/json-mode.el
@@ -1,6 +1,6 @@
 ;;; json-mode.el --- Major mode for editing JSON files  -*- lexical-binding: 
t; -*-
 
-;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2020 Free Software Foundation, Inc.
 
 ;; Author: Simen Heggestøyl <simenheg@gmail.com>
 ;; Maintainer: Simen Heggestøyl <simenheg@gmail.com>
@@ -78,9 +78,12 @@
     (modify-syntax-entry ?\n ">" st)
     st))
 
+(defconst json-mode--keywords '("true" "false" "null")
+  "List of JSON keywords.")
+
 (defvar json-mode-font-lock-keywords
   `(;; Constants
-    (,(concat "\\<" (regexp-opt json-keywords) "\\>")
+    (,(concat "\\<" (regexp-opt json-mode--keywords) "\\>")
      (0 font-lock-constant-face))))
 
 (defun json-mode--string-is-object-name-p (startpos)
@@ -126,13 +129,13 @@ JSON object members will be sorted alphabetically by 
their keys."
     (if (use-region-p)
         (funcall
          (if alphabetical
-             'json-pretty-print-ordered
-           'json-pretty-print)
+             #'json-pretty-print-ordered
+           #'json-pretty-print)
          (region-beginning) (region-end))
       (funcall
        (if alphabetical
-           'json-pretty-print-buffer-ordered
-         'json-pretty-print-buffer)))))
+           #'json-pretty-print-buffer-ordered
+         #'json-pretty-print-buffer)))))
 
 (defun json-mode-show-path ()
   "Show the path to the JSON value under point.
@@ -150,6 +153,15 @@ The value is also copied to the kill ring."
           (kill-new formatted-path))
       (message "Not a JSON value"))))
 
+(defun json--which-func ()
+  (let ((path (plist-get (json-path-to-position (point)) :path)))
+    (when path
+      ;; There's not much space in the modeline, so this needs
+      ;; to be more compact than what `json-mode--format-path' produces.
+      ;; FIXME: Even in this more compact form it can easily get too long
+      ;; for comfort.  Add some way to shorten it.
+      (mapconcat (lambda (key) (format "%s" key)) path ";"))))
+
 (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
@@ -170,6 +182,7 @@ integers."
       . json-font-lock-syntactic-face-function)))
   ;; JSON has no comment syntax, but we set this to keep SMIE happy.
   ;; Also, some JSON extensions allow comments.
+  (add-hook 'which-func-functions #'json--which-func nil t)
   (setq-local comment-start "// ")
   (setq-local comment-end "")
   (smie-setup json-mode--smie-grammar #'json-mode--smie-rules))



reply via email to

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