To: vim_dev@googlegroups.com Subject: Patch 8.0.1352 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1352 Problem: Dead URLs in the help go unnoticed. Solution: Add a script to check URLs in the help files. (Christian Brabandt) Files: runtime/doc/Makefile, runtime/doc/test_urls.vim, Filelist *** ../vim-8.0.1351/runtime/doc/Makefile 2017-11-16 17:35:57.076876528 +0100 --- runtime/doc/Makefile 2017-11-24 20:49:13.696003862 +0100 *************** *** 30,35 **** --- 30,36 ---- filetype.txt \ fold.txt \ ft_ada.txt \ + ft_rust.txt \ ft_sql.txt \ gui.txt \ gui_w32.txt \ *************** *** 166,171 **** --- 167,173 ---- filetype.html \ fold.html \ ft_ada.html \ + ft_rust.html \ ft_sql.html \ gui.html \ gui_w32.html \ *************** *** 373,378 **** --- 375,384 ---- perlhtml: tags $(DOCS) ./vim2html.pl tags $(DOCS) + # Check URLs in the help with "curl". + test_urls: + vim -S test_urls.vim + clean: -rm doctags *.html tags.ref *** ../vim-8.0.1351/runtime/doc/test_urls.vim 2017-11-28 14:18:39.117437258 +0100 --- runtime/doc/test_urls.vim 2017-11-28 14:14:26.542649071 +0100 *************** *** 0 **** --- 1,68 ---- + " Test for URLs in help documents. + " + " Opens a new window with all found URLS followed by return code from curl + " (anything other than 0 means unreachable) + " + " Written by Christian Brabandt. + + func Test_check_URLs() + if has("win32") + echoerr "Doesn't work on MS-Windows" + return + endif + if executable('curl') + " Note: does not follow redirects! + let s:command = 'curl --silent --fail --output /dev/null --head ' + elseif executable('wget') + " Note: only allow a couple of redirects + let s:command = 'wget --quiet -S --spider --max-redirect=2 --timeout=5 --tries=2 -O /dev/null ' + else + echoerr 'Only works when "curl" or "wget" is available' + return + endif + + let pat='\(https\?\|ftp\)://[^\t* ]\+' + exe 'helpgrep' pat + helpclose + + let urls = map(getqflist(), 'v:val.text') + " do not use submatch(1)! + let urls = map(urls, {key, val -> matchstr(val, pat)}) + " remove examples like user@host (invalid urls) + let urls = filter(urls, 'v:val !~ "@"') + " Remove example URLs which are invalid + let urls = filter(urls, {key, val -> val !~ '\<\(\(my\|some\)\?host\|machine\|hostname\|file\)\>'}) + new + put =urls + " remove some more invalid items + " empty lines + v/./d + " remove # anchors + %s/#.*$//e + " remove trailing stuff (parenthesis, dot, comma, quotes), but only for HTTP + " links + g/^h/s#[.,)'"/>][:.]\?$## + g#^[hf]t\?tp:/\(/\?\.*\)$#d + silent! g/ftp://,$/d + silent! g/=$/d + let a = getline(1,'$') + let a = uniq(sort(a)) + %d + call setline(1, a) + + " Do the testing. + set nomore + %s/.*/\=TestURL(submatch(0))/ + + " highlight the failures + /.* \([0-9]*[1-9]\|[0-9]\{2,}\)$ + endfunc + + func TestURL(url) + " Relies on the return code to determine whether a page is valid + echom printf("Testing URL: %d/%d %s", line('.'), line('$'), a:url) + call system(s:command . shellescape(a:url)) + return printf("%s %d", a:url, v:shell_error) + endfunc + + call Test_check_URLs() *** ../vim-8.0.1351/Filelist 2017-11-26 17:17:47.595166613 +0100 --- Filelist 2017-11-28 13:34:38.808480676 +0100 *************** *** 584,589 **** --- 584,590 ---- runtime/doc/*.txt \ runtime/doc/Makefile \ runtime/doc/doctags.c \ + runtime/doc/test_urls.vim \ runtime/doc/vim.1 \ runtime/doc/evim.1 \ runtime/doc/vimdiff.1 \ *** ../vim-8.0.1351/src/version.c 2017-11-27 23:24:04.837331762 +0100 --- src/version.c 2017-11-28 14:15:50.134258114 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1352, /**/ -- Light travels faster than sound. This is why some people appear bright until you hear them speak /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///