Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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