Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 116 lines (98 sloc) 3.691 kb
7f4dc408 » mbriggs
2012-01-28 missed a js in the readme >.>
1 ;;; ruby-mode-expansions.el --- ruby-specific expansions for expand-region
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
2
3 ;; Copyright (C) 2011 Magnar Sveen
4
5 ;; Author: Matt Briggs
6 ;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
7 ;; Keywords: marking region
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24
25 ;; Idiomatic ruby has a lot of nested blocks, and its function marking seems a bit buggy.
26 ;;
27 ;; Expansions:
28 ;;
29 ;;
37a060c5 » magnars
2012-06-28 Revert botched ruby-mode updates (pull request #36 and #37)
30 ;; er/mark-ruby-block
31 ;; er/mark-ruby-function
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
32
33 ;;; Code:
1be37698 » magnars
2012-02-27 Loosen dependency between core and mode expansions.
34
35 (require 'expand-region-core)
36
37a060c5 » magnars
2012-06-28 Revert botched ruby-mode updates (pull request #36 and #37)
37 (defun er/mark-ruby-block ()
27561477 » Le Wang
2012-06-27 Fix previous botched commit for PR.
38 (interactive)
37a060c5 » magnars
2012-06-28 Revert botched ruby-mode updates (pull request #36 and #37)
39 (forward-line 1)
40 (beginning-of-line)
41 (ruby-beginning-of-block)
42 (set-mark (point))
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
43 (ruby-end-of-block)
37a060c5 » magnars
2012-06-28 Revert botched ruby-mode updates (pull request #36 and #37)
44 (end-of-line)
45 (exchange-point-and-mark))
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
46
ca212f6a » magnars
2012-07-04 Add support for expanding to ruby symbols, eg. :symbol
47 (defun er/mark-ruby-symbol ()
48 "Mark the entire symbol around or in front of point."
49 (interactive)
50 (let ((symbol-regexp ":\\|\\s_\\|\\sw"))
51 (when (or (looking-at symbol-regexp)
52 (looking-back symbol-regexp))
53 (while (looking-at symbol-regexp)
54 (forward-char))
55 (set-mark (point))
56 (while (looking-back symbol-regexp)
57 (backward-char)))))
58
5e4bfda4 »
2012-08-15 Adding a crude start at choose-your-own-quotes style matching. It cur…
59 (defun er/search-forward-for-closed-nesting (open close)
60 "A helper function for matching nested constructs."
61 (while (and (not (looking-at (regexp-quote close)))
62 (< (point) (point-max)))
63 (cond ((looking-at (regexp-quote open))
64 (forward-char)
65 (er/search-forward-for-closed-nesting open close))
66 (t (forward-char))))
67 (if (looking-at (regexp-quote close)) (forward-char)))
68
69 (defun er/mark-ruby-choose-your-own-quotes ()
70 "Mark choose-your-own-quotes style string, arrays, regexen, etc."
71 (interactive)
72 (let ((quote_start)
73 (quote_end))
74 (save-excursion
75 (while (and (not (looking-back "%[qQwWr]{"))
76 (> (point) (point-min)))
77 (backward-char))
78 (when (looking-back "%[qQwWr]{")
79 (setq quote_start (- (point) 3))
80 (er/search-forward-for-closed-nesting "{" "}")
81 (when (looking-back "}")
82 (setq quote_end (point)))))
83 (when (and quote_start
84 quote_end
85 (<= quote_start (point))
86 (>= quote_end (point)))
87 (set-mark quote_end)
88 (goto-char quote_start))))
89
37a060c5 » magnars
2012-06-28 Revert botched ruby-mode updates (pull request #36 and #37)
90 (defun er/mark-ruby-function ()
91 "Mark the current Ruby function."
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
92 (interactive)
37a060c5 » magnars
2012-06-28 Revert botched ruby-mode updates (pull request #36 and #37)
93 (condition-case nil
94 (forward-char 3)
95 (error nil))
96 (let ((ruby-method-regex "^[\t ]*def\\_>"))
97 (word-search-backward ruby-method-regex)
98 (while (syntax-ppss-context (syntax-ppss))
99 (word-search-backward ruby-method-regex)))
100 (set-mark (point))
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
101 (ruby-end-of-block)
37a060c5 » magnars
2012-06-28 Revert botched ruby-mode updates (pull request #36 and #37)
102 (end-of-line)
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
103 (exchange-point-and-mark))
104
105 (defun er/add-ruby-mode-expansions ()
106 "Adds Ruby-specific expansions for buffers in ruby-mode"
5e4bfda4 »
2012-08-15 Adding a crude start at choose-your-own-quotes style matching. It cur…
107 (set (make-local-variable 'er/try-expand-list)
108 (append er/try-expand-list
109 '(er/mark-ruby-symbol
110 er/mark-ruby-choose-your-own-quotes
111 er/mark-ruby-block
112 er/mark-ruby-function))))
dd95c219 » mbriggs
2012-01-28 adds ruby-mode expansions
113
114 (add-hook 'ruby-mode-hook 'er/add-ruby-mode-expansions)
115
116 (provide 'ruby-mode-expansions)
Something went wrong with that request. Please try again.