sishen (owner)

Revisions

  • ee23ac sishen Tue Oct 27 06:33:46 -0700 2009
gist: 219559 Download_button fork
public
Public Clone URL: git://gist.github.com/219559.git
Embed All Files: show embed
cucumber: feature-mode.el.patch #
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
diff --git b/cucumber/feature-mode.el a/cucumber/feature-mode.el
index 06b5667..9f37685 100644
--- b/cucumber/feature-mode.el
+++ a/cucumber/feature-mode.el
@@ -57,7 +57,7 @@
   (list
    '("^ *Feature:" (0 font-lock-keyword-face) (".*" nil nil (0 font-lock-type-face t)))
    '("^ *Background:$" (0 font-lock-keyword-face))
- '("^ *Scenario\\(?: Outline\\)?:" (0 font-lock-keyword-face) (".*" nil nil (0 font-lock-function-name-face t)))
+ '("^ *Scenarios?\\(?: Outline\\)?:" (0 font-lock-keyword-face) (".*" nil nil (0 font-lock-function-name-face t)))
    '("^ *Given" . font-lock-keyword-face)
    '("^ *When" . font-lock-keyword-face)
    '("^ *Then" . font-lock-keyword-face)
@@ -99,6 +99,32 @@
 (unless feature-mode-syntax-table
   (setq feature-mode-syntax-table (make-syntax-table)))
 
+;; Constants
+
+(defconst feature-blank-line-re "^[ \t]*$"
+ "Regexp matching a line containing only whitespace.")
+
+(defconst feature-feature-re "^ *Feature:"
+ "Regexp matching the feature statement.")
+
+(defconst feature-scenario-re "^ *Scenarios?\\(?: Outline\\)?:"
+ "Regexp matching the scenario statement.")
+
+(defconst feature-given-re "^ *Given"
+ "Regexp matching the Given statement.")
+
+(defconst feature-when-re "^ *When"
+ "Regexp matching the When statement.")
+
+(defconst feature-then-re "^ *Then"
+ "Regexp matching the Then statement.")
+
+(defconst feature-and-re "^ *And"
+ "Regexp matching the And statement.")
+
+(defconst feature-but-re "^ *But"
+ "Regexp matching the But statement.")
+
 ;;
 ;; Variables
 ;;
@@ -110,6 +136,43 @@
   "Indentation of feature statements"
   :type 'integer :group 'feature)
 
+(defcustom feature-indent-offset 2
+ "*Amount of offset per level of indentation."
+ :type 'integer :group 'feature)
+
+(defun feature-compute-indentation ()
+ "Calculate the maximum sensible indentation for the current line."
+ (save-excursion
+ (beginning-of-line)
+ (if (bobp) 10
+ (forward-line -1)
+ (while (and (looking-at feature-blank-line-re)
+ (> (point) (point-min)))
+ (forward-line -1))
+ (+ (current-indentation)
+ (if (or (looking-at feature-feature-re)
+ (looking-at feature-scenario-re))
+ feature-indent-offset 0)))))
+
+(defun feature-indent-line ()
+ "Indent the current line.
+The first time this command is used, the line will be indented to the
+maximum sensible indentation. Each immediately subsequent usage will
+back-dent the line by `feature-indent-offset' spaces. On reaching column
+0, it will cycle back to the maximum sensible indentation."
+ (interactive "*")
+ (let ((ci (current-indentation))
+ (cc (current-column))
+ (need (feature-compute-indentation)))
+ (save-excursion
+ (beginning-of-line)
+ (delete-horizontal-space)
+ (if (and (equal last-command this-command) (/= ci 0))
+ (indent-to (* (/ (- ci 1) feature-indent-offset) feature-indent-offset))
+ (indent-to need)))
+ (if (< (current-column) (current-indentation))
+ (forward-to-indentation 0))))
+
 (defun feature-mode-variables ()
   (set-syntax-table feature-mode-syntax-table)
   (setq require-final-newline t)
@@ -117,6 +180,8 @@
   (setq comment-start-skip "#+ *")
   (setq comment-end "")
   (setq parse-sexp-ignore-comments t)
+ (set (make-local-variable 'indent-tabs-mode) 'nil)
+ (set (make-local-variable 'indent-line-function) 'feature-indent-line)
   (set (make-local-variable 'font-lock-defaults) '((feature-font-lock-keywords) nil nil))
   (set (make-local-variable 'font-lock-keywords) feature-font-lock-keywords))