From 348e6eee2a453892c6e1f1dea417f505300d3943 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Thu, 11 Jun 2009 18:52:57 -0400 Subject: [PATCH] some basic utf-8 support --HG-- branch : pmacs2 --- application.py | 2 +- method/utf8.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 method/utf8.py diff --git a/application.py b/application.py index 9ef1c21..ec0e7e8 100755 --- a/application.py +++ b/application.py @@ -104,7 +104,7 @@ class Application(object): 'method', 'method.svn', 'method.cvs', 'method.search', 'method.buffers', 'method.move', 'method.shell', 'method.introspect', 'method.help', 'method.numbers', - 'method.spell', 'method.hg', + 'method.spell', 'method.hg', 'method.utf8', ) for name in names: exec("import %s" % name) diff --git a/method/utf8.py b/method/utf8.py new file mode 100644 index 0000000..a009f1d --- /dev/null +++ b/method/utf8.py @@ -0,0 +1,29 @@ +import os, commands, re, tempfile +from subprocess import Popen, PIPE, STDOUT + +import buffer, default, dirutil, lex, regex, util, window +from point import Point + +from method import Method, Argument, arg + +class Utf8Get(Method): + def _execute(self, w, **vargs): + p = w.logical_cursor() + c = w.buffer.get_substring(p, p.add(1, 0)) + w.set_error(repr(c)) + +class Utf8Describe(Method): + def _execute(self, w, **vargs): + w.set_error("not implemented") + +class Utf8Insert(Method): + '''insert the specified UTF-8 character into the buffer''' + args = [arg("data", t=type(""), p="Data: ", + h="the UTF-8 escaped data to use to use")] + def _execute(self, w, **vargs): + s = "u'" + vargs['data'] + "'" + try: + u = eval(s, {}, {}) + w.insert_string_at_cursor(u) + except: + w.set_error("invalid: %s" % vargs['data'])