coLinux ä¸ã® Emacs ã® kill-ring ã®å 容ãWindowsã®ã¯ãªãããã¼ãã¨åæãã by Perl
Emacs ã Meadow ããã㦠coLinux ä¸ã®ãã®ã PuTTY çµç±ã§ä½¿ãããã«ãããã§ãããEmacs 㧠killing ã«ããããã®ã Windows ã§ãã¼ã¹ãããããã¨æã£ãã¨ãã« Meadow ã§ãããªãã§ãããããã§ããã«ã¡ãã£ã¨ã¹ãã¬ã¹ã«ãªã£ã¦ã¾ããããããªæã
Great Job! ããããã®ã Hack ã£ã¦ãããã§ããããªããããããPython ! ããã¯ãã£ã¡ã Perl ã§ã
ã¾ã Windows å´ã«ç«ã¦ããµã¼ãã¼ãå®è£ ããã
- ActivePerl + ppm 㧠POE 㨠PoCo::Server::IKC ããããªãå ¥ã£ãã®ã§ããã使ãã
- ã¯ãªãããã¼ãã¸ã®ç»é²ã¯ä¸æ¹åã®éåæã¡ãã»ã¼ã¸ã³ã°ãªã®ã§ãIKC::ClientLite ã使ãã°ç°¡åããªã¨æãã
- åãåã£ãããã¹ãã®ã¯ãªãããã¼ãã¸ã®ç»é²ã¯ Win32::Cilpboard ã§ã
#!perl use strict; use warnings; use Win32::Clipboard; use POE qw/Session Component::IKC::Server Component::TSTP Sugar::Args/; POE::Component::IKC::Server->spawn( port => 10080, ip => '192.168.100.1', name => 'ClipBoardServer', ); POE::Component::TSTP->create; POE::Session->create( inline_states => { _start => \&setup_service, update => \&update, } ); POE::Kernel->run; exit(0); sub setup_service { my $poe = sweet_args; $poe->heap->{clip} = Win32::Clipboard(); $poe->kernel->alias_set('clipboard_server'); $poe->kernel->call( IKC => publish => clipboard_server => [qw/update/], ); } sub update { my $poe = sweet_args; $poe->heap->{clip}->Set($poe->args->[0]); } 1;
ãããé©å½ãªã¨ããã«ç½®ãã¦ããã¦ã³ãã³ãããã³ããããèµ·åããã(ã¨ããã§ããèµ·åããã¨ãªããå²ãè¾¼ã¿å¹ããªããã ãã©ãªãã§ã¸ã£ãã) èµ·åæã«ç«ã¡ä¸ããããã«ã¨ãã¯ã¾ããã¨ã§ã
次㫠coLinux å´ã§èµ·åããã¯ã©ã¤ã¢ã³ãã
- PoCo::IKC::ClientLite 㧠post ãã
- æ¥æ¬èªãæååãããªãããã« Encode ã§å¦çã
- 端æ«ã®èªåå¤å®ã¯ Term::Encoding ã§èªåå¤å®ã
- Emacs ã¨ã®é£æºä»¥å¤ã§ã使ããããã«å ¥å㯠<> ã§å¦çã
cbcopy ã¨ããååã«ãã¾ãã
#!/usr/local/bin/perl use strict; use warnings; use POE qw/Component::IKC::ClientLite/; use Encode qw/from_to/; use Term::Encoding qw/term_encoding/; sub error ($) { my $message = shift; die sprintf( "[error] %s %s", $message, $POE::Component::IKC::ClientLite::error ); } local $/; my $text = <>; $text or exit 0; from_to($text, term_encoding, 'cp932'); my $remote = POE::Component::IKC::ClientLite::create_ikc_client( port => 10080, ip => '192.168.100.1', name => sprintf("ClipBoardClient_%d", $$), timeout => 5, ); error "Couldn't connect to the server" unless $remote; $remote->post('clipboard_server/update' => $text) or error "Couldn't post to the server";
ããã§
% cat /etc/motd | cbcopy
ã¨ãããã¨ã/etc/motd ã®å 容ã Windows ã®ã¯ãªãããã¼ãã«å ¥ãããã«ãªãã¾ãã
ã§ãæçµç®çã® Emacs ã¨ã®é£æºã®é¨å㯠id:odz ããä½ã® #1 ã®ãã®ãæåãcl-sync-command ã cbcopy ã«å¤ããã ãã
;; cbcopy ;; http://d.hatena.ne.jp/odz/20061125/1164433815 (defvar cl-sync-command "cbcopy" "*The command for clipboard sync") (defun cl-sync (beg end) (interactive "r") (call-process-region beg end shell-file-name nil nil nil shell-command-switch cl-sync-command)) (defadvice copy-region-as-kill (before clipboard-sync (beg end) activate) (cl-sync beg end)) (defadvice kill-region (before clipboard-sync (beg end) activate) (cl-sync beg end))
ãã¾ãåãã¾ãããã¤ããã¤ã
ãã ãå¤å Perl ã®èµ·åæéã®ãã㧠Emacs 㧠killing ã«ãªããç»é²ããã¨ãã®åãããã£ããããããã¯ã¼ã¯ã§ãããã¯ãããªãããã« POE 使ã£ãã®ã«æå³ãªããxml-rpc.el ã«ã¯éåæã¢ã¼ããããã¿ããã ãããã§ããã®ããã£ã±ãããã£ã½ãã§ããããµã¼ãã¼å´ã PoCo::Server::XMLRPC ã«ããããã«æ¹é ãã¦ã¿ã¾ãã(Python 使ãã°ããã®ã«ï½)
追è¨
XML-RPC çã®ãµã¼ãã
#!perl use strict; use warnings; use POE qw/Session Component::Server::XMLRPC Component::TSTP Sugar::Args/; use Win32::Clipboard; use Encode qw/encode/; POE::Component::TSTP->create; POE::Component::Server::XMLRPC->new(alias => 'xmlrpc', port => 10080); POE::Session->create ( inline_states => { _start => sub { my $poe = sweet_args; $poe->heap->{clip} = Win32::Clipboard(); $poe->kernel->alias_set("cbserver"); $poe->kernel->post(xmlrpc => publish => cbserver => 'clipboard.set'); }, _shutdown => sub { my $poe = sweet_args; $poe->post(xmlrpc => rescind => cbserver => "clipboard.set" ); }, 'clipboard.set' => sub { my $poe = sweet_args; my $rpc = $poe->args->[0]; my $text = $rpc->params->[0] or return $rpc->return(0); $poe->heap->{clip}->Set(encode('cp932', $text)); $rpc->return(1); }, }, ); POE::Kernel->run; exit 0;
å®ç¨çãªé度ã«ãªã£ããid:odz ãã thanks!
# ãã¨ã¯ *Messages* ãããã¡ã« Reading [text/xml]... 137 bytes of 130 bytes (105%) ã¨ãåºãã®ãæ¢ããã¨ããã®ã TODO.
追è¨ã®è¿½è¨
url.el ã®ã¡ãã»ã¼ã¸ãæ¶ãã«ã¯ã
(setq url-show-status nil)
㧠OK