forked from magnars/expand-region.el
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js2-mode-expansions.el
55 lines (41 loc) · 1.89 KB
/
js2-mode-expansions.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;;; js2-mode-expansions.el --- Additional expansions for js2-mode
;; Copyright (C) 2011 Magnar Sveen
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Extra expansions specifically for js2-mode, since it has
;; a semantic parser.
;;
;; Feel free to contribute any other expansions for JavaScript at
;;
;; https://github.com/magnars/expand-region.el
;;; Code:
(require 'expand-region-core)
(defun js2-mark-parent-statement ()
(interactive)
(let* ((parent-statement (if (not (looking-back ";"))
(js2-node-parent-stmt (js2-node-at-point))
(forward-char -1)
(js2-node-at-point)))
(beg (js2-node-abs-pos parent-statement))
(end (+ beg (js2-node-len parent-statement))))
(goto-char beg)
(set-mark end)))
(defun er/add-js2-mode-expansions ()
"Adds expansions for buffers in js2-mode"
(set (make-local-variable 'er/try-expand-list) (append
er/try-expand-list
'(js2-mark-parent-statement))))
(er/enable-mode-expansions 'js2-mode 'er/add-js2-mode-expansions)
(provide 'js2-mode-expansions)
;; js2-mode-expansions.el ends here