dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

feature-mode-expansions.el (2586B)


      1 ;;; feature-mode-expansions.el --- cucumber-specific expansions for expand-region
      2 
      3 ;; Copyright (C) 2012-2020  Free Software Foundation, Inc
      4 
      5 ;; Author: Raimon Grau
      6 ;; Based on js-mode-expansions by: Raimon Grau <raimonster@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 ;; expanders to mark feature semantic objects like step or scenario
     26 ;;
     27 ;; Expansions:
     28 ;;
     29 ;;
     30 ;;  er/mark-feature-scenario
     31 ;;  er/mark-feature-step
     32 
     33 (require 'expand-region-core)
     34 
     35 (defun er--block-between-keywords (start-keywords-regexp &optional end-keywords-regexp)
     36   (let* ((start-key-words (concat "^\\( \\)*" start-keywords-regexp))
     37          (end-key-words (concat "^\\( \\)*" (or end-keywords-regexp start-keywords-regexp))))
     38     (when (looking-at-p "[^\\s-]")
     39       (skip-syntax-forward "w."))
     40     (if (looking-at-p start-keywords-regexp)
     41         (progn (beginning-of-line)
     42                (exchange-point-and-mark))
     43       (re-search-backward start-key-words)
     44       (set-mark (point))
     45       (re-search-forward start-key-words))
     46     (unless (re-search-forward end-key-words (point-max) t)
     47       (goto-char (point-max)))
     48    (forward-line 0)
     49    (exchange-point-and-mark)))
     50 
     51 (defun er/mark-feature-scenario ()
     52   (interactive)
     53   (er--block-between-keywords "\\(Background:\\|Scenario:\\|Feature:\\)"))
     54 
     55 (defun er/mark-feature-step ()
     56   (interactive)
     57   (er--block-between-keywords "\\(And\\|Given\\|When\\|Then\\)"  "\\(And\\|Given\\|When\\|Then\\|Scenario:\\)"))
     58 
     59 (defun er/add-feature-mode-expansions ()
     60   "Adds cucumber-specific expansions for buffers in feature-mode"
     61   (set (make-local-variable 'er/try-expand-list) (append
     62                                                   er/try-expand-list
     63                                                   '(er/mark-feature-scenario
     64                                                     er/mark-feature-step))))
     65 
     66 (er/enable-mode-expansions 'feature-mode 'er/add-feature-mode-expansions)
     67 
     68 (provide 'feature-mode-expansions)