json-emacs / json-mode

Major mode for editing JSON files with emacs
314 stars 66 forks source link

forward-sexp stops at decimal point on numbers #58

Closed mkrauss closed 1 year ago

mkrauss commented 6 years ago

I would think that a number should be an atom for purposes of *-sexp functions, but they treat them as two separate sexps separated by a period. This behavior makes it near impossible to use keyboard macros to operate on values regardless of whether they are scalar data or complex sub-objects.

taku0 commented 1 year ago

It would make sense, but do you know of any modes that treat floats as atoms?

mkrauss commented 1 year ago

That's the ones I can come up with in a couple minutes. Admittedly, not most, but some of the best - json-mode would be joining good company.

taku0 commented 1 year ago

Sorry, I mistakenly thought you meant M-f (forward-word) but not C-M-f (forward-sexp).

I have surveyed the behavior of each mode:

c-mode:
  Inside strings:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
  Inside comments:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
  Float literal:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
  Dot operator/symbol with dot:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
js2-mode:
  Inside strings:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
  Inside comments:
    forward-sexp: exits from the comment.
    forward-word: stops at dot.
  Float literal:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Dot operator/symbol with dot:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
python-mode:
  Inside strings:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
  Inside comments:
    forward-sexp: stops at dot.
    forward-word: stops at dot.
  Float literal:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Dot operator/symbol with dot:
    forward-sexp: skips whole expression.
    forward-word: stops at dot.
emacs-lisp-mode:
  Inside strings:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Inside comments:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Float literal:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Dot operator/symbol with dot:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
shell-script-mode:
  Inside strings:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Inside comments:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Float literal:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.
  Dot operator/symbol with dot:
    forward-sexp: skips whole literal.
    forward-word: stops at dot.

python-mode seems to be the most sophisticated.

I will implement a function for forward-sexp-function as follows:

taku0 commented 1 year ago

Fixed via https://github.com/json-emacs/json-mode/commit/481d5d9f4003fc14d116bf31d1bf71d14960d7d9