mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improve ruby-electric-mode.
* misc/ruby-electric.el (ruby-electric-hash): New electric function that expands a hash sign inside a string or regexp to "#{}". * misc/ruby-electric.el (ruby-electric-curlies): Do not insert spaces inside when the curly brace is a delimiter of %r, %w, etc. * misc/ruby-electric.el (ruby-electric-curlies): Insert another space before a closing curly brace when ruby-electric-newline-before-closing-bracket is nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
14e72b1cde
commit
59eacb45e5
2 changed files with 81 additions and 21 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
Sun Apr 7 01:40:39 2013 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* misc/ruby-electric.el (ruby-electric-hash): New electric
|
||||
function that expands a hash sign inside a string or regexp to
|
||||
"#{}".
|
||||
|
||||
* misc/ruby-electric.el (ruby-electric-curlies): Do not insert
|
||||
spaces inside when the curly brace is a delimiter of %r, %w,
|
||||
etc.
|
||||
|
||||
* misc/ruby-electric.el (ruby-electric-curlies): Insert another
|
||||
space before a closing curly brace when
|
||||
ruby-electric-newline-before-closing-bracket is nil.
|
||||
|
||||
Sun Apr 7 01:01:26 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* strftime.c (rb_strftime_with_timespec): Test yday range.
|
||||
|
|
|
@ -84,7 +84,8 @@ inserted. The word 'all' will do all insertions."
|
|||
(const :tag "Quote" ?\' )
|
||||
(const :tag "Double quote" ?\" )
|
||||
(const :tag "Back quote" ?\` )
|
||||
(const :tag "Vertical bar" ?\| ))
|
||||
(const :tag "Vertical bar" ?\| )
|
||||
(const :tag "Hash" ?\# ))
|
||||
:group 'ruby-electric)
|
||||
|
||||
(defcustom ruby-electric-newline-before-closing-bracket nil
|
||||
|
@ -119,7 +120,8 @@ strings. Note that you must have Font Lock enabled."
|
|||
(define-key ruby-mode-map "[" 'ruby-electric-matching-char)
|
||||
(define-key ruby-mode-map "\"" 'ruby-electric-matching-char)
|
||||
(define-key ruby-mode-map "\'" 'ruby-electric-matching-char)
|
||||
(define-key ruby-mode-map "|" 'ruby-electric-bar))
|
||||
(define-key ruby-mode-map "|" 'ruby-electric-bar)
|
||||
(define-key ruby-mode-map "#" 'ruby-electric-hash))
|
||||
|
||||
(defun ruby-electric-space (arg)
|
||||
(interactive "P")
|
||||
|
@ -140,6 +142,18 @@ strings. Note that you must have Font Lock enabled."
|
|||
(and ruby-electric-mode
|
||||
(consp (memq 'font-lock-string-face (text-properties-at (point))))))
|
||||
|
||||
(defun ruby-electric-escaped-p()
|
||||
(let ((f nil))
|
||||
(save-excursion
|
||||
(while (char-equal ?\\ (preceding-char))
|
||||
(backward-char 1)
|
||||
(setq f (not f))))
|
||||
f))
|
||||
|
||||
(defun ruby-electric-command-char-expandable-punct-p(char)
|
||||
(or (memq 'all ruby-electric-expand-delimiters-list)
|
||||
(memq char ruby-electric-expand-delimiters-list)))
|
||||
|
||||
(defun ruby-electric-is-last-command-char-expandable-punct-p()
|
||||
(or (memq 'all ruby-electric-expand-delimiters-list)
|
||||
(memq last-command-event ruby-electric-expand-delimiters-list)))
|
||||
|
@ -178,25 +192,57 @@ strings. Note that you must have Font Lock enabled."
|
|||
|
||||
(defun ruby-electric-curlies(arg)
|
||||
(interactive "P")
|
||||
(ruby-electric-insert arg
|
||||
(if (ruby-electric-is-last-command-char-expandable-punct-p)
|
||||
(cond ((ruby-electric-code-at-point-p)
|
||||
(insert " ")
|
||||
(save-excursion
|
||||
(if ruby-electric-newline-before-closing-bracket
|
||||
(progn
|
||||
(newline)
|
||||
(insert "}")
|
||||
(ruby-indent-line t))
|
||||
(insert "}"))))
|
||||
((ruby-electric-string-at-point-p)
|
||||
(if (eq last-command-event ?{)
|
||||
(save-excursion
|
||||
(backward-char 1)
|
||||
(or (char-equal ?\# (preceding-char))
|
||||
(insert "#"))
|
||||
(forward-char 1)
|
||||
(insert "}"))))))))
|
||||
(ruby-electric-insert
|
||||
arg
|
||||
(if (ruby-electric-is-last-command-char-expandable-punct-p)
|
||||
(cond
|
||||
((ruby-electric-code-at-point-p)
|
||||
(insert "}")
|
||||
(backward-char 1)
|
||||
(redisplay)
|
||||
(cond
|
||||
((ruby-electric-string-at-point-p) ; %w{}, %r{}, etc.
|
||||
t)
|
||||
(ruby-electric-newline-before-closing-bracket
|
||||
(insert " ")
|
||||
(save-excursion
|
||||
(newline)
|
||||
(ruby-indent-line t)))
|
||||
(t
|
||||
(insert " ")
|
||||
(backward-char 1))))
|
||||
((ruby-electric-string-at-point-p)
|
||||
(save-excursion
|
||||
(backward-char 1)
|
||||
(cond
|
||||
((char-equal ?\# (preceding-char))
|
||||
(unless (save-excursion
|
||||
(backward-char 1)
|
||||
(ruby-electric-escaped-p))
|
||||
(forward-char 1)
|
||||
(insert "}")))
|
||||
((ruby-electric-command-char-expandable-punct-p ?\#)
|
||||
t) ; no need for the following if ruby-electric-hash is enabled
|
||||
((ruby-electric-escaped-p)
|
||||
t)
|
||||
(t
|
||||
(insert "#")
|
||||
(forward-char 1)
|
||||
(insert "}")))))))))
|
||||
|
||||
(defun ruby-electric-hash(arg)
|
||||
(interactive "P")
|
||||
(ruby-electric-insert
|
||||
arg
|
||||
(and (ruby-electric-is-last-command-char-expandable-punct-p)
|
||||
(ruby-electric-string-at-point-p)
|
||||
(or (looking-at "'") ; likely to be in ''
|
||||
(save-excursion
|
||||
(backward-char 1)
|
||||
(ruby-electric-escaped-p))
|
||||
(progn
|
||||
(insert "{}")
|
||||
(backward-char 1))))))
|
||||
|
||||
(defun ruby-electric-matching-char(arg)
|
||||
(interactive "P")
|
||||
|
|
Loading…
Reference in a new issue