[前][次][番号順一覧][スレッド一覧]

ruby-changes:33594

From: nobu <ko1@a...>
Date: Wed, 23 Apr 2014 11:03:31 +0900 (JST)
Subject: [ruby-changes:33594] nobu:r45675 (trunk): ruby-additional.el: ruby-encode-unicode

nobu	2014-04-23 11:03:24 +0900 (Wed, 23 Apr 2014)

  New Revision: 45675

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45675

  Log:
    ruby-additional.el: ruby-encode-unicode
    
    * misc/ruby-additional.el (ruby-encode-unicode): convert non-ascii
      string to \\u{} form.

  Modified files:
    trunk/misc/ruby-additional.el
Index: misc/ruby-additional.el
===================================================================
--- misc/ruby-additional.el	(revision 45674)
+++ misc/ruby-additional.el	(revision 45675)
@@ -106,6 +106,18 @@ Emacs to Ruby." https://github.com/ruby/ruby/blob/trunk/misc/ruby-additional.el#L106
                      (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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]