[elpa] master 494c421 2/3: Derive from js-mode
branch: master commit 494c421bfa6f1b72b577267cb3841b0eff262250 Author: Dmitry Gutov Commit: Dmitry Gutov Derive from js-mode --- js2-mode.el | 68 ++ 1 files changed, 3 insertions(+), 65 deletions(-) diff --git a/js2-mode.el b/js2-mode.el index 2a3d5b8..332e8f8 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -87,16 +87,9 @@ (require 'cl-lib) (require 'imenu) -(require 'cc-cmds) ; for `c-fill-paragraph' (require 'js) (eval-and-compile - (require 'cc-mode) ; (only) for `c-populate-syntax-table' - (require 'cc-engine)) ; for `c-paragraph-start' et. al. - -(defvar electric-layout-rules) - -(eval-and-compile (if (version< emacs-version "25.0") (require 'js2-old-indent) (defvaralias 'js2-basic-offset 'js-indent-level nil) @@ -1223,32 +1216,6 @@ First match-group is the leading whitespace.") (js2-deflocal js2-imenu-recorder nil "Private variable") (js2-deflocal js2-imenu-function-map nil "Private variable") -(defvar js2-paragraph-start - "\\(@[[:alpha:]]+\\>\\|$\\)") - -;; Note that we also set a 'c-in-sws text property in html comments, -;; so that `c-forward-sws' and `c-backward-sws' work properly. -(defvar js2-syntactic-ws-start - "\\s \\|/[*/]\\|[\n\r]\\|[\n\r]\\|\\s!\\|") - -(defvar js2-syntactic-ws-end - "\\s \\|[\n\r/]\\|\\s!") - -(defvar js2-syntactic-eol - (concat "\\s *\\(/\\*[^*\n\r]*" - "\\(\\*+[^*\n\r/][^*\n\r]*\\)*" - "\\*+/\\s *\\)*" - "\\(//\\|/\\*[^*\n\r]*" - "\\(\\*+[^*\n\r/][^*\n\r]*\\)*$" - "\\|$\\|$\\)") - "Copied from `java-mode'. Needed for some cc-engine functions.") - -(defvar js2-comment-prefix-regexp - "//+\\|\\**") - -(defvar js2-comment-start-skip - "\\(//+\\|/\\*+\\)\\s *") - (defvar js2-mode-verbose-parse-p js2-mode-dev-mode-p "Non-nil to emit status messages during parsing.") @@ -11309,19 +11276,14 @@ Selecting an error will jump it to the corresponding source-buffer error. (message msg)) ;;;###autoload -(define-derived-mode js2-mode prog-mode "Javascript-IDE" - ;; FIXME: Should derive from js-mode. +(define-derived-mode js2-mode js-mode "Javascript-IDE" "Major mode for editing JavaScript code." ;; Used by comment-region; don't change it. - (set (make-local-variable 'comment-start) "//") - (set (make-local-variable 'comment-end) "") - (set (make-local-variable 'comment-start-skip) js2-comment-start-skip) (set (make-local-variable 'max-lisp-eval-depth) (max max-lisp-eval-depth 3000)) - (when (fboundp 'js2-indent-line) -(set (make-local-variable 'indent-line-function) #'js2-indent-line)) + (set (make-local-variable 'indent-line-function) #'js2-indent-line) (set (make-local-variable 'indent-region-function) #'js2-indent-region) - (set (make-local-variable 'fill-paragraph-function) #'c-fill-paragraph) + (set (make-local-variable 'syntax-propertize-function) nil) (set (make-local-variable 'comment-line-break-function) #'js2-line-break) (set (make-local-variable 'beginning-of-defun-function) #'js2-beginning-of-defun) (set (make-local-variable 'end-of-defun-function) #'js2-end-of-defun) @@ -11333,30 +11295,6 @@ Selecting an error will jump it to the corresponding source-buffer error. ;; needed for M-x rgrep, among other things (put 'js2-mode 'find-tag-default-function #'js2-mode-find-tag) - (set (make-local-variable 'electric-indent-chars) - (append "{}()[]:;,*." electric-indent-chars)) - (set (make-local-variable 'electric-layout-rules) - '((?\; . after) (?\{ . after) (?\} . before))) - - ;; some variables needed by cc-engine for paragraph-fill, etc. - (setq c-comment-prefix-regexp js2-comment-prefix-regexp -c-comment-start-regexp "/[*/]\\|\\s|" -c-line-comment-starter "//" -c-paragraph-start js2-paragraph-start -c-paragraph-separate "$" -c-syntactic-ws-start js2-syntactic-ws-start -c-syntactic-ws-end js2-syntactic-ws-end -c-syntactic-eol js2-syntactic-eol) - - (let ((c-buffer-is-cc-mode t)) -;; Copied from `js-mode'. Also see Bug#6071. -(make-local-variable 'paragraph-start) -(make-local-variable 'paragraph-separate) -(make-local-variable 'paragraph-ignore-fill-prefix) -(make-local-variable 'adaptive-fill-mode) -(make-local-variable 'adaptive-fill-regexp) -(c-setup-paragraph-variables)) - (setq font-lock-defaults '(nil t)) ;; Experiment: make reparse-delay longer for longer files.
[elpa] master updated (2763c9a -> a7b8100)
dgutov pushed a change to branch master. from 2763c9a Merge commit 'f3a899bb1c36e25e078eed2890eb2fecb22f4175' from js2-mode new 4c02462 Use indentation code from js-mode when we can new 494c421 Derive from js-mode new a7b8100 Merge commit '494c421bfa6f1b72b577267cb3841b0eff262250' from js2-mode Summary of changes: packages/js2-mode/js2-mode.el | 582 --- packages/js2-mode/js2-old-indent.el | 493 + 2 files changed, 549 insertions(+), 526 deletions(-) create mode 100644 packages/js2-mode/js2-old-indent.el
[elpa] master a7b8100 3/3: Merge commit '494c421bfa6f1b72b577267cb3841b0eff262250' from js2-mode
branch: master commit a7b8100b52925d82aa1d6fd8606a537ea88b91b9 Merge: 2763c9a 494c421 Author: Dmitry Gutov Commit: Dmitry Gutov Merge commit '494c421bfa6f1b72b577267cb3841b0eff262250' from js2-mode --- packages/js2-mode/js2-mode.el | 582 --- packages/js2-mode/js2-old-indent.el | 493 + 2 files changed, 549 insertions(+), 526 deletions(-) diff --git a/packages/js2-mode/js2-mode.el b/packages/js2-mode/js2-mode.el index 4a6e733..6ea2461 100644 --- a/packages/js2-mode/js2-mode.el +++ b/packages/js2-mode/js2-mode.el @@ -87,13 +87,14 @@ (require 'cl-lib) (require 'imenu) -(require 'cc-cmds) ; for `c-fill-paragraph' +(require 'js) (eval-and-compile - (require 'cc-mode) ; (only) for `c-populate-syntax-table' - (require 'cc-engine)) ; for `c-paragraph-start' et. al. - -(defvar electric-layout-rules) + (if (version< emacs-version "25.0") + (require 'js2-old-indent) +(defvaralias 'js2-basic-offset 'js-indent-level nil) +(defalias 'js2-proper-indentation 'js--proper-indentation) +(defalias 'js2-indent-line 'js-indent-line))) ;;; Externs (variables presumed to be defined by the host system) @@ -235,78 +236,6 @@ variable with predicate PRED." "An improved JavaScript mode." :group 'languages) -(defcustom js2-basic-offset (if (and (boundp 'c-basic-offset) - (numberp c-basic-offset)) -c-basic-offset - 4) - "Number of spaces to indent nested statements. -Similar to `c-basic-offset'." - :group 'js2-mode - :type 'integer) -(js2-mark-safe-local 'js2-basic-offset 'integerp) - -(defcustom js2-bounce-indent-p nil - "Non-nil to have indent-line function choose among alternatives. -If nil, the indent-line function will indent to a predetermined column -based on heuristic guessing. If non-nil, then if the current line is -already indented to that predetermined column, indenting will choose -another likely column and indent to that spot. Repeated invocation of -the indent-line function will cycle among the computed alternatives. -See the function `js2-bounce-indent' for details. When it is non-nil, -js2-mode also binds `js2-bounce-indent-backwards' to Shift-Tab." - :type 'boolean - :group 'js2-mode) - -(defcustom js2-pretty-multiline-declarations t - "Non-nil to line up multiline declarations vertically: - - var a = 10, - b = 20, - c = 30; - -If the value is t, and the first assigned value in the -declaration is a function/array/object literal spanning several -lines, it won't be indented additionally: - - var o = { var bar = 2, -foo: 3 vs. o = { - },foo: 3 - bar = 2;}; - -If the value is `all', it will always be indented additionally: - - var o = { -foo: 3 - }; - - var o = { -foo: 3 - }, - bar = 2; - -If the value is `dynamic', it will be indented additionally only -if the declaration contains more than one variable: - - var o = { -foo: 3 - }; - - var o = { -foo: 3 - }, - bar = 2;" - :group 'js2-mode - :type 'symbol) -(js2-mark-safe-local 'js2-pretty-multiline-declarations 'symbolp) - -(defcustom js2-indent-switch-body nil - "When nil, case labels are indented on the same level as the -containing switch statement. Otherwise, all lines inside -switch statement body are indented one additional level." - :type 'boolean - :group 'js2-mode) -(js2-mark-safe-local 'js2-indent-case-same-as-switch 'booleanp) - (defcustom js2-idle-timer-delay 0.2 "Delay in secs before re-parsing after user makes changes. Multiplied by `js2-dynamic-idle-timer-adjust', which see." @@ -1185,8 +1114,6 @@ information." (define-key map (kbd "C-c C-o") #'js2-mode-toggle-element) (define-key map (kbd "C-c C-w") #'js2-mode-toggle-warnings-and-errors) (define-key map [down-mouse-3] #'js2-down-mouse-3) -(when js2-bounce-indent-p - (define-key map (kbd "") #'js2-indent-bounce-backwards)) (define-key map [menu-bar javascript] (cons "JavaScript" (make-sparse-keymap "JavaScript"))) @@ -1249,6 +1176,24 @@ information." map) "Keymap used in `js2-mode' buffers.") +(defcustom js2-bounce-indent-p nil + "Non-nil to bind `js2-indent-bounce' and `js2-indent-bounce-backward'. +They will augment the default indent-line behavior with cycling +among several computed alternatives. See the function +`js2-bounce-indent' for details. The above commands will be +bound to TAB and backtab." + :type 'boolean + :group 'js2-mode + :set (lambda (sym value) + (set-default sym value) + (let ((map js2-mode-map)) + (if (not value) + (progn + (define-key map "\t" nil) + (define-key map (kbd "") nil)) + (define-key map "\t" #'js2-indent-bounce) + (defi
[elpa] master 4c02462 1/3: Use indentation code from js-mode when we can
branch: master commit 4c02462944a24085ba4843be29637265423b9fe5 Author: Dmitry Gutov Commit: Dmitry Gutov Use indentation code from js-mode when we can Some options has been left without aliases, even though they have counterparts in js.el, because their values are incompatible: js2-pretty-multiline-declarations -> js-indent-first-init js2-indent-switch-body -> js-switch-indent-offset After upgrading to Emacs 25, the affected users will have to customize them anew. --- js2-mode.el | 524 ++--- js2-old-indent.el | 493 + 2 files changed, 551 insertions(+), 466 deletions(-) diff --git a/js2-mode.el b/js2-mode.el index 14e3b72..2a3d5b8 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -88,6 +88,7 @@ (require 'cl-lib) (require 'imenu) (require 'cc-cmds) ; for `c-fill-paragraph' +(require 'js) (eval-and-compile (require 'cc-mode) ; (only) for `c-populate-syntax-table' @@ -95,6 +96,13 @@ (defvar electric-layout-rules) +(eval-and-compile + (if (version< emacs-version "25.0") + (require 'js2-old-indent) +(defvaralias 'js2-basic-offset 'js-indent-level nil) +(defalias 'js2-proper-indentation 'js--proper-indentation) +(defalias 'js2-indent-line 'js-indent-line))) + ;;; Externs (variables presumed to be defined by the host system) (defvar js2-ecma-262-externs @@ -235,78 +243,6 @@ variable with predicate PRED." "An improved JavaScript mode." :group 'languages) -(defcustom js2-basic-offset (if (and (boundp 'c-basic-offset) - (numberp c-basic-offset)) -c-basic-offset - 4) - "Number of spaces to indent nested statements. -Similar to `c-basic-offset'." - :group 'js2-mode - :type 'integer) -(js2-mark-safe-local 'js2-basic-offset 'integerp) - -(defcustom js2-bounce-indent-p nil - "Non-nil to have indent-line function choose among alternatives. -If nil, the indent-line function will indent to a predetermined column -based on heuristic guessing. If non-nil, then if the current line is -already indented to that predetermined column, indenting will choose -another likely column and indent to that spot. Repeated invocation of -the indent-line function will cycle among the computed alternatives. -See the function `js2-bounce-indent' for details. When it is non-nil, -js2-mode also binds `js2-bounce-indent-backwards' to Shift-Tab." - :type 'boolean - :group 'js2-mode) - -(defcustom js2-pretty-multiline-declarations t - "Non-nil to line up multiline declarations vertically: - - var a = 10, - b = 20, - c = 30; - -If the value is t, and the first assigned value in the -declaration is a function/array/object literal spanning several -lines, it won't be indented additionally: - - var o = { var bar = 2, -foo: 3 vs. o = { - },foo: 3 - bar = 2;}; - -If the value is `all', it will always be indented additionally: - - var o = { -foo: 3 - }; - - var o = { -foo: 3 - }, - bar = 2; - -If the value is `dynamic', it will be indented additionally only -if the declaration contains more than one variable: - - var o = { -foo: 3 - }; - - var o = { -foo: 3 - }, - bar = 2;" - :group 'js2-mode - :type 'symbol) -(js2-mark-safe-local 'js2-pretty-multiline-declarations 'symbolp) - -(defcustom js2-indent-switch-body nil - "When nil, case labels are indented on the same level as the -containing switch statement. Otherwise, all lines inside -switch statement body are indented one additional level." - :type 'boolean - :group 'js2-mode) -(js2-mark-safe-local 'js2-indent-case-same-as-switch 'booleanp) - (defcustom js2-idle-timer-delay 0.2 "Delay in secs before re-parsing after user makes changes. Multiplied by `js2-dynamic-idle-timer-adjust', which see." @@ -1185,8 +1121,6 @@ information." (define-key map (kbd "C-c C-o") #'js2-mode-toggle-element) (define-key map (kbd "C-c C-w") #'js2-mode-toggle-warnings-and-errors) (define-key map [down-mouse-3] #'js2-down-mouse-3) -(when js2-bounce-indent-p - (define-key map (kbd "") #'js2-indent-bounce-backwards)) (define-key map [menu-bar javascript] (cons "JavaScript" (make-sparse-keymap "JavaScript"))) @@ -1249,6 +1183,24 @@ information." map) "Keymap used in `js2-mode' buffers.") +(defcustom js2-bounce-indent-p nil + "Non-nil to bind `js2-indent-bounce' and `js2-indent-bounce-backward'. +They will augment the default indent-line behavior with cycling +among several computed alternatives. See the function +`js2-bounce-indent' for details. The above commands will be +bound to TAB and backtab." + :type 'boolean + :group 'js2-mode + :set (lambda (sym value) + (set-default sym value) +