branch: externals/ruby-end commit cf55eff3f8a367f3a74d530988e36194148e9aa0 Merge: 8b2aaf6467 19037b0c8c Author: Johan Andersson <johan.rej...@gmail.com> Commit: Johan Andersson <johan.rej...@gmail.com>
Merge branch 'last-command' --- features/ruby-end.feature | 21 +++++++++++++++++++++ features/step-definitions/ruby-end-steps.el | 9 +++++++++ features/support/env.el | 3 ++- ruby-end.el | 9 +++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/features/ruby-end.feature b/features/ruby-end.feature index d3919bd2fc..566516b99a 100644 --- a/features/ruby-end.feature +++ b/features/ruby-end.feature @@ -180,3 +180,24 @@ Feature: Insert end Proc.new do """ + + Scenario: Do not expand when the last command was not insertion + Given I restrict expansion to only after insertion + When I press "i" + And I press "f" + And I press "<left>" + And I press "<right>" + And I press "SPC" + Then I should see "if " + And end should not be insterted + + Scenario: Expand when the last command was insertion + Given I restrict expansion to only after insertion + When I type "if" interactively + And I press "SPC" + Then I should see: + """ + if + + end + """ diff --git a/features/step-definitions/ruby-end-steps.el b/features/step-definitions/ruby-end-steps.el index ae9ab7fdc8..3349d7d901 100644 --- a/features/step-definitions/ruby-end-steps.el +++ b/features/step-definitions/ruby-end-steps.el @@ -45,3 +45,12 @@ (Given "I disable expand on return" (lambda () (setq ruby-end-expand-on-ret nil))) + +(Given "^I type \"\\([^\"]+\\)\" interactively" + (lambda (str) + (When "I type \"%s\"" str) + (setq this-command 'self-insert-command))) + +(Given "I restrict expansion to only after insertion" + (lambda () + (setq ruby-end-expand-only-for-last-commands '(self-insert-command)))) diff --git a/features/support/env.el b/features/support/env.el index 636e6eff37..0cedd2a14b 100644 --- a/features/support/env.el +++ b/features/support/env.el @@ -10,7 +10,8 @@ (Before (setq ruby-end-insert-newline t) - (setq ruby-end-expand-on-ret t)) + (setq ruby-end-expand-on-ret t) + (setq ruby-end-expand-only-for-last-commands nil)) (require 'ruby-end) (require 'espuds) diff --git a/ruby-end.el b/ruby-end.el index c9310e8c45..d453b60405 100644 --- a/ruby-end.el +++ b/ruby-end.el @@ -76,6 +76,13 @@ :type 'boolean :group 'ruby) +(defcustom ruby-end-expand-only-for-last-commands '(self-insert-command) + "List of `last-command' values to restrict expansion to, or nil. + +When nil, any `last-command' will do." + :type '(repeat function) + :group 'ruby) + (defconst ruby-end-expand-postfix-modifiers-before-re "\\(?:if\\|unless\\|while\\)" "Regular expression matching statements before point.") @@ -147,6 +154,8 @@ ruby-end-expand-prefix-re) ruby-end-expand-postfix-modifiers-before-re))) (and + (or (not ruby-end-expand-only-for-last-commands) + (memq last-command ruby-end-expand-only-for-last-commands)) (ruby-end-code-at-point-p) (or (looking-back ruby-end-expand-statement-modifiers-before-re)