- Timestamp:
- 08/05/08 17:39:40 (4 months ago)
- Files:
-
- 1 modified
-
lang/vim/ruby/mixi.vim (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/vim/ruby/mixi.vim
r17076 r17102 1 1 command! Mixi :call <SID>MixiStart() 2 command! MixiEcho :call <SID>MixiEchoStart() 2 command! MixiEcho :call <SID>MixiStartEcho() 3 command! MixiEchoGet :call <SID>MixiStartEchoAndGetMessage() 3 4 4 5 function! s:MixiStart() … … 7 8 endfunction 8 9 9 function! s:Mixi EchoStart()10 function! s:MixiStartEcho() 10 11 set nonu 11 12 ruby mixi_run_echo 13 endfunction 14 15 function! s:MixiStartEchoAndGetMessage() 16 set nonu 17 ruby mixi_run_echo_getmessage 12 18 endfunction 13 19 … … 88 94 end 89 95 96 def get_latest_echo 97 page = @agent.get 'http://mixi.jp/recent_echo.pl' 98 line = [] 99 10.downto(1) do |i| 100 buf = '' 101 buf << (page/("div#echo_nickname_" + i.to_s)).first.to_plain_text.toutf8 102 buf << ":" 103 buf << (page/("div#echo_body_" + i.to_s)).first.to_plain_text.toutf8 104 line.push buf 105 end 106 line 107 end 108 90 109 def self.magic_body(body) 91 110 body.gsub(/^( )+/) {|i| ' '.toeuc * (i.length/2) } … … 116 135 end 117 136 118 def mixi_run 119 vim = VIM::Buffer.current 120 return if VIM.evaluate('confirm("really?")') == 0 121 122 endline = VIM.evaluate %[line("$")] 123 title = VIM.evaluate %[getline(1)] 124 body = VIM.evaluate(%[join(getline(2, #{endline}), "\n")]).split "\n" 125 126 images = body.reverse.inject([]) {|r, l| r.unshift l[4..-1] if l =~ /^img:/; r } 127 body = body[0..-(images.length + 1)].join "\n" 128 137 def create_mixi_instance 129 138 # ~/.mixi 130 139 # line1: input your email 131 140 # line2: input your password 132 141 # line3: input "premium" if you are premium 133 m =134 142 if File.exist?(File.expand_path('~/.mixi')) 135 143 mixi_config = File.read(File.expand_path('~/.mixi')) … … 141 149 # if you are mixi premium member: 142 150 # m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD', true 151 end 152 153 def mixi_run 154 vim = VIM::Buffer.current 155 return if VIM.evaluate('confirm("really?")') == 0 156 157 endline = VIM.evaluate %[line("$")] 158 title = VIM.evaluate %[getline(1)] 159 body = VIM.evaluate(%[join(getline(2, #{endline}), "\n")]).split "\n" 160 161 images = body.reverse.inject([]) {|r, l| r.unshift l[4..-1] if l =~ /^img:/; r } 162 body = body[0..-(images.length + 1)].join "\n" 163 164 m = create_mixi_instance; 165 143 166 m.post title.toeuc, body.toeuc, images 144 167 m.get_latest.each do |line| … … 154 177 message = VIM.evaluate %[getline('.')] 155 178 156 # ~/.mixi 157 # line1: input your email 158 # line2: input your password 159 # line3: input "premium" if you are premium 160 m = 161 if File.exist?(File.expand_path('~/.mixi')) 162 mixi_config = File.read(File.expand_path('~/.mixi')) 163 email, password, premium = mixi_config.split(/\r?\n/) 164 Mixi.new email, password, (premium == 'premium') 165 else 166 m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD' 167 end 168 # if you are mixi premium member: 169 # m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD', true 179 m = create_mixi_instance; 180 170 181 fork { 171 182 m.post_echo message.toeuc … … 173 184 end 174 185 186 def mixi_run_echo_getmessage 187 vim = VIM::Buffer.current 188 # If you need: 189 # return if VIM.evaluate('confirm("really?")') == 0 190 191 message = VIM.evaluate %[getline(1)] 192 193 m = create_mixi_instance; 194 195 m.post_echo message.toeuc 196 m.get_latest_echo.each do |line| 197 vim.append(1, line) 198 end 199 end 200 201 175 202 EOF
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)