emacs-devel
[Top][All Lists]
Advanced

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

Re: [elpa] master ba07fd7: New package: json-mode


From: Stefan Monnier
Subject: Re: [elpa] master ba07fd7: New package: json-mode
Date: Sun, 11 Dec 2016 12:03:50 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> +(defvar json-mode-syntax-table

Would it make sense to inherit some things (such as the syntax-table)
from js-mode?

> +    ;; Object names
> +    ("\\(\"[^\"]*\"\\)[[:blank:]]*:"
> +     (1 'json-mode-object-name-face))
> +    ;; Strings
> +    ("\"\\(\\\\.\\|[^\"]\\)*\""
> +     (0 font-lock-string-face))))

Are these meant to match strings that span several lines?
If no, the regexps are wrong (because they can match multiple lines).
If yes, this will fail in various circumstances
(see (info "(elisp)Font Lock Multiline") for more details).

> +(defun json-font-lock-syntactic-face-function (state)
> +  "Highlight comments only.
> +Strings are handled by `json-mode-font-lock-keywords', since we
> +want to highlight object name strings differently from ordinary
> +strings."
> +  (when (nth 4 state) font-lock-comment-face))

Why not do something like

     (cond
      ((nth 4 state) font-lock-comment-face)
      ((and (nth 3 state)
            (json-string-is-object-name-p (nth 8 state)))
       'json-mode-object-name-face)
      (t font-lock-string-face))

Where json-string-is-object-name-p could look like

    (defun json-string-is-object-name-p (startpos)
      (save-excursion
        (goto-char startpos)
        (and (eq (char-after) ?\")
             (condition-case nil
                 (progn (forward-sexp 1) t)
               (scan-error nil))
             (looking-at "[[:blank:]]*:"))))
                   

-- Stefan



reply via email to

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