From 52d62129ab4e42802cbd7aea19a5ec979e073a6e Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 8 Mar 2010 13:44:28 +0900 Subject: [PATCH] anchorize URL. --- zencoding.vim | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/zencoding.vim b/zencoding.vim index 4ce162f..62f8e22 100644 --- a/zencoding.vim +++ b/zencoding.vim @@ -94,6 +94,8 @@ for item in [ \ {'mode': 'n', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTagNormal', 'func': ':call zen_splitJoinTag()'}, \ {'mode': 'i', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': ':call zen_removeTag()a'}, \ {'mode': 'n', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': ':call zen_removeTag()'}, +\ {'mode': 'i', 'var': 'user_zen_anchorizeurl_key', 'key': 'a', 'plug': 'ZenCodingAnchorizeURL', 'func': ':call zen_anchorizeURL()a'}, +\ {'mode': 'n', 'var': 'user_zen_anchorizeurl_key', 'key': 'a', 'plug': 'ZenCodingAnchorizeURL', 'func': ':call zen_anchorizeURL()'}, \] if !hasmapto(''.item.plug, item.mode) @@ -1437,6 +1439,34 @@ function! s:zen_balanceTag(flag) endif endfunction +function! s:zen_anchorizeURL() + let pos = getpos('.') + let mx = 'https\=:\/\/[-!#$%&*+,./:;=?@0-9a-zA-Z_~]\+' + let pos1 = searchpos(mx, 'bcnW') + let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) + let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]] + if !s:cursor_in_region(block) + return + endif + + silent! split ______FETCHTITLE______ + silent! exec '0r!curl -s -L "'.substitute(content, '#.*', '', '').'"' + if executable('nkf') + if &enc == 'utf-8' + silent! %!nkf -X8 + elseif &enc == 'cp932' + silent! %!nkf -Xs + endif + endif + silent! %join! + silent! %g/^\s*$/d _ + silent! %s/^.\{-}]*>\([^<]\+\)<\/title[^>]*>.*/\1/i + let ret = getline('.') + silent! bw! + let format = '%s' + call s:change_content(block, printf(format, content, ret)) +endfunction + function! ZenExpand(abbr, type, orig) let items = s:zen_parseIntoTree(a:abbr, a:type).child let expand = ''