forked from magnars/expand-region.el
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature-mode-expansions.el
68 lines (53 loc) · 2.55 KB
/
feature-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
56
57
58
59
60
61
62
63
64
65
66
67
68
;;; feature-mode-expansions.el --- cucumber-specific expansions for expand-region -*- lexical-binding: t; -*-
;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Raimon Grau
;; Based on js-mode-expansions by: Raimon Grau <raimonster@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:
;; expanders to mark feature semantic objects like step or scenario
;;
;; Expansions:
;;
;;
;; er/mark-feature-scenario
;; er/mark-feature-step
(require 'expand-region-core)
(defun er--block-between-keywords (start-keywords-regexp &optional end-keywords-regexp)
(let* ((start-key-words (concat "^\\( \\)*" start-keywords-regexp))
(end-key-words (concat "^\\( \\)*" (or end-keywords-regexp start-keywords-regexp))))
(when (looking-at-p "[^\\s-]")
(skip-syntax-forward "w."))
(if (looking-at-p start-keywords-regexp)
(progn (beginning-of-line)
(exchange-point-and-mark))
(re-search-backward start-key-words)
(set-mark (point))
(re-search-forward start-key-words))
(unless (re-search-forward end-key-words (point-max) t)
(goto-char (point-max)))
(forward-line 0)
(exchange-point-and-mark)))
(defun er/mark-feature-scenario ()
(interactive)
(er--block-between-keywords "\\(Background:\\|Scenario:\\|Feature:\\)"))
(defun er/mark-feature-step ()
(interactive)
(er--block-between-keywords "\\(And\\|Given\\|When\\|Then\\)" "\\(And\\|Given\\|When\\|Then\\|Scenario:\\)"))
(defun er/add-feature-mode-expansions ()
"Adds cucumber-specific expansions for buffers in feature-mode"
(set (make-local-variable 'er/try-expand-list) (append
er/try-expand-list
'(er/mark-feature-scenario
er/mark-feature-step))))
(er/enable-mode-expansions 'feature-mode #'er/add-feature-mode-expansions)
(provide 'feature-mode-expansions)