diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-23 02:03:24 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-23 02:03:24 +0000 |
commit | 43326170323f735820f64ca1413b01183da606b0 (patch) | |
tree | db4c3c4f17d7bd3cd55f2e7876214a2d2efcef3d /misc | |
parent | 506c6f52b950c131b305456cf72fe8f84a2a8f5f (diff) | |
download | ruby-43326170323f735820f64ca1413b01183da606b0.tar.gz |
ruby-additional.el: ruby-encode-unicode
* misc/ruby-additional.el (ruby-encode-unicode): convert non-ascii
string to \\u{} form.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'misc')
-rw-r--r-- | misc/ruby-additional.el | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/misc/ruby-additional.el b/misc/ruby-additional.el index c06003d6da..0a191cda71 100644 --- a/misc/ruby-additional.el +++ b/misc/ruby-additional.el @@ -106,6 +106,18 @@ Emacs to Ruby." (t (when ruby-insert-encoding-magic-comment (insert "# -*- coding: " coding-system " -*-\n")))))))) + (define-key ruby-mode-map "\C-c\C-u" 'ruby-encode-unicode) + + (defun ruby-encode-unicode (beg end) + "Convert non-ascii string in the given region to \\u{} form." + (interactive "r") + (goto-char beg) + (while (and (< (point) end) + (re-search-forward "\\Ca+" end t)) + (let ((u (mapconcat (lambda (c) (format "%x" c)) (match-string-no-properties 0) " "))) + (delete-region (match-beginning 0) (match-end 0)) + (insert "\\u{" u "}")) + )) )) (provide 'ruby-additional) |