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)