diff options
Diffstat (limited to 'lisp/progmodes/js.el')
-rw-r--r-- | lisp/progmodes/js.el | 86 |
1 files changed, 35 insertions, 51 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index cdf6536fc7e..c2481f6095a 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -282,7 +282,7 @@ Match group 1 is the name of the macro.") "continue" "debugger" "default" "delete" "do" "else" "enum" "export" "extends" "final" "finally" "for" "function" "goto" "if" "implements" "import" "in" - "instanceof" "interface" "native" "new" "package" + "instanceof" "interface" "native" "new" "of" "package" "private" "protected" "public" "return" "static" "super" "switch" "synchronized" "throw" "throws" "transient" "try" "typeof" "var" "void" "let" @@ -427,22 +427,19 @@ Match group 1 is the name of the macro.") (defcustom js-indent-level 4 "Number of spaces for each indentation step in `js-mode'." :type 'integer - :safe 'integerp - :group 'js) + :safe 'integerp) (defcustom js-expr-indent-offset 0 "Number of additional spaces for indenting continued expressions. The value must be no less than minus `js-indent-level'." :type 'integer - :safe 'integerp - :group 'js) + :safe 'integerp) (defcustom js-paren-indent-offset 0 "Number of additional spaces for indenting expressions in parentheses. The value must be no less than minus `js-indent-level'." :type 'integer :safe 'integerp - :group 'js :version "24.1") (defcustom js-square-indent-offset 0 @@ -450,7 +447,6 @@ The value must be no less than minus `js-indent-level'." The value must be no less than minus `js-indent-level'." :type 'integer :safe 'integerp - :group 'js :version "24.1") (defcustom js-curly-indent-offset 0 @@ -458,7 +454,6 @@ The value must be no less than minus `js-indent-level'." The value must be no less than minus `js-indent-level'." :type 'integer :safe 'integerp - :group 'js :version "24.1") (defcustom js-switch-indent-offset 0 @@ -466,26 +461,22 @@ The value must be no less than minus `js-indent-level'." The value must not be negative." :type 'integer :safe 'integerp - :group 'js :version "24.4") (defcustom js-flat-functions nil "Treat nested functions as top-level functions in `js-mode'. This applies to function movement, marking, and so on." - :type 'boolean - :group 'js) + :type 'boolean) (defcustom js-indent-align-list-continuation t "Align continuation of non-empty ([{ lines in `js-mode'." :version "26.1" :type 'boolean - :safe 'booleanp - :group 'js) + :safe 'booleanp) (defcustom js-comment-lineup-func #'c-lineup-C-comments "Lineup function for `cc-mode-style', for C comments in `js-mode'." - :type 'function - :group 'js) + :type 'function) (defcustom js-enabled-frameworks js--available-frameworks "Frameworks recognized by `js-mode'. @@ -493,30 +484,27 @@ To improve performance, you may turn off some frameworks you seldom use, either globally or on a per-buffer basis." :type (cons 'set (mapcar (lambda (x) (list 'const x)) - js--available-frameworks)) - :group 'js) + js--available-frameworks))) (defcustom js-js-switch-tabs (and (memq system-type '(darwin)) t) "Whether `js-mode' should display tabs while selecting them. This is useful only if the windowing system has a good mechanism for preventing Firefox from stealing the keyboard focus." - :type 'boolean - :group 'js) + :type 'boolean) (defcustom js-js-tmpdir - "~/.emacs.d/js/js" + (locate-user-emacs-file "js/js") "Temporary directory used by `js-mode' to communicate with Mozilla. This directory must be readable and writable by both Mozilla and Emacs." :type 'directory - :group 'js) + :version "28.1") (defcustom js-js-timeout 5 "Reply timeout for executing commands in Mozilla via `js-mode'. The value is given in seconds. Increase this value if you are getting timeout messages." - :type 'integer - :group 'js) + :type 'integer) (defcustom js-indent-first-init nil "Non-nil means specially indent the first variable declaration's initializer. @@ -557,8 +545,7 @@ don't indent the first one's initializer; otherwise, indent it. bar = 2;" :version "25.1" :type '(choice (const nil) (const t) (const dynamic)) - :safe 'symbolp - :group 'js) + :safe 'symbolp) (defcustom js-chain-indent nil "Use \"chained\" indentation. @@ -571,8 +558,7 @@ then the \".\"s will be lined up: " :version "26.1" :type 'boolean - :safe 'booleanp - :group 'js) + :safe 'booleanp) (defcustom js-jsx-detect-syntax t "When non-nil, automatically detect whether JavaScript uses JSX. @@ -581,8 +567,7 @@ t. The detection strategy can be customized by adding elements to `js-jsx-regexps', which see." :version "27.1" :type 'boolean - :safe 'booleanp - :group 'js) + :safe 'booleanp) (defcustom js-jsx-syntax nil "When non-nil, parse JavaScript with consideration for JSX syntax. @@ -600,8 +585,7 @@ When `js-mode' is already enabled, you should call It is set to be buffer-local (and t) when in `js-jsx-mode'." :version "27.1" :type 'boolean - :safe 'booleanp - :group 'js) + :safe 'booleanp) (defcustom js-jsx-align->-with-< t "When non-nil, “>” will be indented to the opening “<” in JSX. @@ -625,8 +609,7 @@ When this is disabled, JSX indentation looks like this: />" :version "27.1" :type 'boolean - :safe 'booleanp - :group 'js) + :safe 'booleanp) (defcustom js-jsx-indent-level nil "When non-nil, indent JSX by this value, instead of like JS. @@ -655,8 +638,7 @@ indentation looks like this (different): :version "27.1" :type '(choice integer (const :tag "Not Set" nil)) - :safe (lambda (x) (or (null x) (integerp x))) - :group 'js) + :safe (lambda (x) (or (null x) (integerp x)))) ;; This is how indentation behaved out-of-the-box until Emacs 27. JSX ;; indentation was controlled with `sgml-basic-offset', which defaults ;; to 2, whereas `js-indent-level' defaults to 4. Users who had the @@ -685,8 +667,7 @@ indentation looks like this: This variable is like `sgml-attribute-offset'." :version "27.1" :type 'integer - :safe 'integerp - :group 'js) + :safe 'integerp) ;;; KeyMap @@ -1079,7 +1060,7 @@ Return the pitem of the function we went to the beginning of." (t (js--beginning-of-defun-nested)))))) -(defun js--flush-caches (&optional beg ignored) +(defun js--flush-caches (&optional beg _ignored) "Flush the `js-mode' syntax cache after position BEG. BEG defaults to `point-min', meaning to flush the entire cache." (interactive) @@ -1359,7 +1340,6 @@ LIMIT defaults to point." (defun js--end-of-defun-nested () "Helper function for `js-end-of-defun'." - (message "test") (let* (pitem (this-end (save-excursion (and (setq pitem (js--beginning-of-defun-nested)) @@ -1493,11 +1473,10 @@ LIMIT defaults to point." "Helper function for building `js--font-lock-keywords'. Create a byte-compiled function for matching a concatenation of REGEXPS, but only if FRAMEWORK is in `js-enabled-frameworks'." - (setq regexps (apply #'concat regexps)) - (byte-compile - `(lambda (limit) - (when (memq (quote ,framework) js-enabled-frameworks) - (re-search-forward ,regexps limit t))))) + (let ((regexp (apply #'concat regexps))) + (lambda (limit) + (when (memq framework js-enabled-frameworks) + (re-search-forward regexp limit t))))) (defvar-local js--tmp-location nil) @@ -2881,7 +2860,11 @@ return nil." ((nth 3 parse-status) 0) ; inside string ((when (and js-jsx-syntax (not js-jsx--indent-col)) (save-excursion (js-jsx--indentation parse-status)))) - ((eq (char-after) ?#) 0) + ((and (eq (char-after) ?#) + (save-excursion + (forward-char 1) + (looking-at-p cpp-font-lock-keywords-source-directives))) + 0) ((save-excursion (js--beginning-of-macro)) 4) ;; Indent array comprehension continuation lines specially. ((let ((bracket (nth 1 parse-status)) @@ -3719,8 +3702,7 @@ Otherwise, use the current value of `process-mark'." Strings and numbers are JSON-encoded. Lists (including nil) are made into JavaScript array literals and their contents encoded with `js--js-encode-value'." - (cond ((stringp x) (json-encode-string x)) - ((numberp x) (json-encode-number x)) + (cond ((or (stringp x) (numberp x)) (json-encode x)) ((symbolp x) (format "{objid:%S}" (symbol-name x))) ((js--js-handle-p x) @@ -4198,8 +4180,9 @@ browser, respectively." "style" "") cmds))) - (eval (list 'with-js - (cons 'js-list (nreverse cmds)))))) + (eval `(with-js + (js-list ,@(nreverse cmds))) + t))) (command-hook () @@ -4410,7 +4393,8 @@ If one hasn't been set, or if it's stale, prompt for a new one." (with-temp-buffer (insert js--js-inserter) (insert "(") - (insert (json-encode-list defun-info)) + (let ((standard-output (current-buffer))) + (json--print-list defun-info)) (insert ",\n") (insert defun-body) (insert "\n)") @@ -4674,4 +4658,4 @@ one of the aforementioned options instead of using this mode." (provide 'js) -;; js.el ends here +;;; js.el ends here |