Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Simplified tags -> hyperlinks conversion hack

The longer I use publish.vim the more I start to push the boundaries of
its current implementation. This necessitated the following changes:

 * Recently the plug-in started crashing Vim with a segmentation fault.
   It turned out the plug-in was generating a corrupt regular expression
   because of tags containing unescaped [ characters:
   http://groups.google.com/group/vim_dev/browse_frm/thread/3c705d4ab811c979

 * After fixing the above bug Vim started throwing "E339: Pattern too
   long" errors which were apparently caused by the complexity (not the
   length) of the generated regular expression so I had to remove the
   ignore_html() hack and replace it with a much simpler hack: Slightly
   tweak Vim's syntax highlighting before running 2html.vim so that all
   tags appear literally in the output of 2html.vim.
  • Loading branch information...
commit 459b8293a2a85885872603765699a210fe72fb74 1 parent 5df4c3d
Peter Odding authored September 05, 2010

Showing 2 changed files with 18 additions and 28 deletions. Show diff stats Hide diff stats

  1. 39  autoload.vim
  2. 7  publish.vim
39  autoload.vim
@@ -92,43 +92,36 @@ function! publish#create_subst_cmd(tags_to_publish) " {{{1
92 92
   " Generate a :substitute command that, when executed, replaces tags with
93 93
   " hyperlinks using a callback. This is complicated somewhat by the fact that
94 94
   " tag names won't always appear literally in the output of 2html.vim, for
95  
-  " example the names of Vim autoload functions appear as:
  95
+  " example the names of Vim autoload functions can appear as:
96 96
   " 
97 97
   "   foo#bar#<span class=Normal>baz</span>
98 98
   " 
99 99
   let patterns = []
  100
+  let slfunctions = []
100 101
   for name in keys(a:tags_to_publish)
101  
-    let tokens = []
102  
-    for token in split(name, '\W\@=\|\W\@<=')
103  
-      let escaped = xolox#escape#pattern(token)
104  
-      call add(tokens, s:ignore_html(token))
105  
-    endfor
106 102
     let entry = a:tags_to_publish[name]
107  
-    if g:publish_viml_sl_hack && get(entry, 'language') == 'Vim'
108  
-      let subpattern = '\s\(s:\|<[Ss][Ii][Dd]>\)' . xolox#escape#pattern(name) . '\s*('
109  
-      if get(entry, 'cmd') =~ subpattern
110  
-        if !exists('s:viml_sl_prefix')
111  
-          let s:viml_sl_prefix = s:nasty()
112  
-        endif
113  
-        call insert(tokens, s:viml_sl_prefix)
  103
+    if get(entry, 'language') == 'Vim'
  104
+      let is_slfunc = '\s\(s:\|<[Ss][Ii][Dd]>\)' . xolox#escape#pattern(name) . '\s*('
  105
+      if get(entry, 'cmd') =~ is_slfunc
  106
+        call add(slfunctions, xolox#escape#pattern(name))
  107
+        continue
114 108
       endif
115 109
     endif
116  
-    call add(patterns, join(tokens, ''))
  110
+    call add(patterns, xolox#escape#pattern(name))
117 111
   endfor
  112
+  call insert(patterns, '\%(\%(&lt;[Ss][Ii][Dd]&gt;\|s:\)\%(' . join(slfunctions, '\|') . '\)\)')
118 113
   let tag_names_pattern = escape(join(patterns, '\|'), '/')
119 114
   " Gotcha: Use \w\@<! and \w\@! here instead of \< and \> which won't work.
120 115
   return '%s/[A-Za-z0-9_]\@<!\%(' . tag_names_pattern . '\)[A-Za-z0-9_]\@!/\=s:ConvertTagToLink(submatch(0))/eg'
121 116
 endfunction
122 117
 
123  
-function! s:ignore_html(s)
124  
-  return printf('\%%(<[^/][^>]*>%s</[^>]\+>\|%s\)', a:s, a:s)
125  
-endfunction
126  
-
127  
-function! s:nasty()
128  
-  " return '\%(s:\|&lt;[Ss][Ii][Dd]&gt;\)'
129  
-  let short = s:ignore_html('s') . s:ignore_html(':')
130  
-  let long = s:ignore_html('&lt;') . s:ignore_html('[Ss][Ii][Dd]') . s:ignore_html('&gt;')
131  
-  return '\%(' . short . '\|' . long . '\)'
  118
+function! publish#munge_syntax_items() " {{{1
  119
+  " Tag to hyperlink conversion only works when tag names appear literally in
  120
+  " the output of 2html.vim while this isn't always the case in Vim scripts.
  121
+  if &filetype == 'vim'
  122
+    syntax match vimFuncName /\<s:\w\+\>/ containedin=vim.*
  123
+    syntax match vimFuncName /\c<Sid>\w\+\>/ containedin=vim.*
  124
+  endif
132 125
 endfunction
133 126
 
134 127
 function! publish#rsync_check(target) " {{{1
7  publish.vim
... ...
@@ -1,6 +1,6 @@
1 1
 " Vim plug-in
2 2
 " Author: Peter Odding <peter@peterodding.com>
3  
-" Last Change: August 31, 2010
  3
+" Last Change: September 5, 2010
4 4
 " URL: http://peterodding.com/code/vim/publish/
5 5
 " License: MIT
6 6
 " Version: 1.6
@@ -21,10 +21,6 @@ if !exists('g:publish_plaintext')
21 21
   let g:publish_plaintext = 0
22 22
 endif
23 23
 
24  
-if !exists('g:publish_viml_sl_hack')
25  
-  let g:publish_viml_sl_hack = 1
26  
-endif
27  
-
28 24
 function! Publish(source, target, files) abort
29 25
   let start = xolox#timer#start()
30 26
   call xolox#message("Preparing to publish file%s ..", len(a:files) == 1 ? '' : 's')
@@ -58,6 +54,7 @@ function! Publish(source, target, files) abort
58 54
     endif
59 55
     silent execute 'doautocmd User PublishPre'
60 56
     let highlight_start = xolox#timer#start()
  57
+    call publish#munge_syntax_items()
61 58
     runtime syntax/2html.vim
62 59
     let msg = "publish.vim: The 2html.vim script took %s to highlight %s."
63 60
     call xolox#timer#stop(msg, highlight_start, pathname)

0 notes on commit 459b829

Please sign in to comment.
Something went wrong with that request. Please try again.