Make ruby-electric play nicely with smartparens-mode.

* misc/ruby-electric.el (ruby-electric-space-can-be-expanded-p):
  Return nil to avoid "end" insertion when in smartparens-mode
  that is configured to insert "end" for the same keyword.

* misc/ruby-electric.el (ruby-electric-keywords): New custom
  variable to replace `ruby-electric-simple-keywords-re` with.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2013-10-07 14:47:32 +00:00
Родитель ae8870e9e0
Коммит 1189b5fe99
2 изменённых файлов: 67 добавлений и 22 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Mon Oct 7 22:52:45 2013 Akinori MUSHA <knu@iDaemons.org>
* misc/ruby-electric.el (ruby-electric-space-can-be-expanded-p):
Return nil to avoid "end" insertion when in smartparens-mode
that is configured to insert "end" for the same keyword.
* misc/ruby-electric.el (ruby-electric-keywords): New custom
variable to replace `ruby-electric-simple-keywords-re` with.
Mon Oct 7 22:52:16 2013 Akinori MUSHA <knu@iDaemons.org> Mon Oct 7 22:52:16 2013 Akinori MUSHA <knu@iDaemons.org>
* misc/ruby-additional.el: Use preceding-char/following-char * misc/ruby-additional.el: Use preceding-char/following-char

Просмотреть файл

@ -54,9 +54,6 @@
"Minor mode providing electric editing commands for ruby files" "Minor mode providing electric editing commands for ruby files"
:group 'ruby) :group 'ruby)
(defconst ruby-electric-expandable-do-re
"do\\s-$")
(defconst ruby-electric-expandable-bar (defconst ruby-electric-expandable-bar
"\\s-\\(do\\|{\\)\\s-+|") "\\s-\\(do\\|{\\)\\s-+|")
@ -67,10 +64,39 @@
(?\` . ?\`) (?\` . ?\`)
(?\" . ?\"))) (?\" . ?\")))
(defcustom ruby-electric-simple-keywords-re (defvar ruby-electric-expandable-do-re)
(regexp-opt '("def" "if" "class" "module" "unless" "case" "while" "do" "until" "for" "begin") t)
"*Regular expresion matching keywords for which closing 'end' (defvar ruby-electric-expandable-keyword-re)
is to be inserted."
(defcustom ruby-electric-keywords
'("begin"
"case"
"class"
"def"
"do"
"for"
"if"
"module"
"unless"
"until"
"while")
"List of keywords for which closing 'end' is to be inserted
after typing a space."
:type '(repeat string)
:set (lambda (sym val)
(set sym val)
(setq ruby-electric-expandable-do-re
(and (member "do" val)
"\\S-\\s-+\\(do\\)\\s-?$")
ruby-electric-expandable-keyword-re
(concat "^\\s-*"
(regexp-opt (remove "do" val) t)
"\\s-?$")))
:group 'ruby-electric)
(defcustom ruby-electric-simple-keywords-re nil
"Obsolete and ignored. Customize `ruby-electric-keywords'
instead."
:type 'regexp :group 'ruby-electric) :type 'regexp :group 'ruby-electric)
(defcustom ruby-electric-expand-delimiters-list '(all) (defcustom ruby-electric-expand-delimiters-list '(all)
@ -103,9 +129,10 @@ mode.
When Ruby Electric mode is enabled, an indented 'end' is When Ruby Electric mode is enabled, an indented 'end' is
heuristicaly inserted whenever typing a word like 'module', heuristicaly inserted whenever typing a word like 'module',
'class', 'def', 'if', 'unless', 'case', 'until', 'for', 'begin', 'class', 'def', 'if', 'unless', 'case', 'until', 'for', 'begin',
'do'. Simple, double and back quotes as well as braces are paired 'do' followed by a space. Single, double and back quotes as well
auto-magically. Expansion does not occur inside comments and as braces are paired auto-magically. Expansion does not occur
strings. Note that you must have Font Lock enabled." inside comments and strings. Note that you must have Font Lock
enabled."
;; initial value. ;; initial value.
nil nil
;;indicator for the mode line. ;;indicator for the mode line.
@ -166,18 +193,27 @@ strings. Note that you must have Font Lock enabled."
(defun ruby-electric-space-can-be-expanded-p() (defun ruby-electric-space-can-be-expanded-p()
(if (ruby-electric-code-at-point-p) (if (ruby-electric-code-at-point-p)
(let* ((ruby-electric-keywords-re (cond ((and ruby-electric-expandable-do-re
(concat ruby-electric-simple-keywords-re "\\s-$")) (looking-back ruby-electric-expandable-do-re))
(ruby-electric-single-keyword-in-line-re (not (ruby-electric-space--sp-has-pair-p "do")))
(concat "\\s-*" ruby-electric-keywords-re))) ((looking-back ruby-electric-expandable-keyword-re)
(save-excursion (not (ruby-electric-space--sp-has-pair-p (match-string 1)))))))
(backward-word 1)
(or (looking-at ruby-electric-expandable-do-re) (defun ruby-electric-space--sp-has-pair-p(keyword)
(and (looking-at ruby-electric-keywords-re) (and (boundp 'smartparens-mode)
(not (string= "do" (match-string 1))) smartparens-mode
(progn (let ((plist (sp-get-pair keyword)))
(beginning-of-line) (and plist
(looking-at ruby-electric-single-keyword-in-line-re)))))))) ;; Check for :actions '(insert)
(memq 'insert (plist-get plist :actions))
;; Check for :when '(("SPC" "RET" "<evil-ret>"))
(let ((x (plist-get plist :when)) when-space)
(while (and x
(not (let ((it (car x)))
(setq when-space (and (listp it)
(member "SPC" it))))))
(setq x (cdr x)))
when-space)))))
(defun ruby-electric-cua-replace-region-maybe() (defun ruby-electric-cua-replace-region-maybe()
(let ((func (key-binding [remap self-insert-command]))) (let ((func (key-binding [remap self-insert-command])))