soywiki 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +50 -46
  2. data/lib/soywiki.rb +2 -2
  3. data/lib/soywiki.vim +44 -40
  4. metadata +2 -2
data/README.markdown CHANGED
@@ -116,6 +116,39 @@ content.
116
116
 
117
117
  That's all you need to know to get started.
118
118
 
119
+ ## Namespaced WikiWords
120
+
121
+ You can get very far with SoyWiki using normal CamelCase WikiWords.
122
+
123
+ NormalWikiWord
124
+
125
+ But if you want, you can also namespace your WikiWords, like so:
126
+
127
+ namespaced.WikiWord
128
+
129
+ A namespaced WikiWord is a WikiWord prefixed by a namespace and a
130
+ period. The namespace word must start with a lower-case letter and
131
+ consist only of letters, numbers, and underscore characters. You can't
132
+ chain namespace words together: the maximum nesting level is 1.
133
+
134
+ Namespaced WikiWords help organize your wiki space conceptually. They also
135
+ have two other benefits:
136
+
137
+ First, wiki pages that represent a namespaced WikiWord are stored under a
138
+ subdirectory named after the namespace. This can help reduce clutter in
139
+ your wiki directory.
140
+
141
+ Every WikiWord namespace lets you use abbreviated links within that
142
+ namespace. For example, if you are editing a page called
143
+ `recipes.SoyMacaroni` and you want to link to another page in the same
144
+ namespace called `recipes.SoyRaspberrySmoothie` you can type the link as
145
+ just `SoyRaspberrySmoothie`. SoyWiki will know that this is a link to
146
+ another page in the same namespace.
147
+
148
+ When you first start SoyWiki, the active namespace the is the default
149
+ namespace `main`.
150
+
151
+
119
152
  ## Wiki navigation
120
153
 
121
154
  You can navigate a SoyWiki wiki very quickly with the following
@@ -225,21 +258,28 @@ same wiki page.
225
258
 
226
259
  ## Search
227
260
 
228
- To search your SoyWiki wiki, type `:SWSearch [search term]`. Vim will
229
- load any matches in the quickfix list window. If there are matches, you
230
- can use `:cn` and `:cp` to go from match to match, `:cl` to list the
231
- matches, and `:cc [item number]` to see a particular match ln the list. See
232
- `:help quickfix` to see the list of matches. for more QuickFix commands.
261
+ * `:SWSearch` [term]
262
+ * `:SWNamespacedSearch` [term]
263
+
264
+ These commands search your SoyWiki wiki. Vim will load any matches in
265
+ the quickfix list window. If there are matches, you can use `:cn` and
266
+ `:cp` to go from match to match, `:cl` to list the matches, and `:cc
267
+ [item number]` to see a particular match ln the list. See `:help
268
+ quickfix` to see the list of matches. for more QuickFix commands.
269
+
270
+ Examples:
233
271
 
234
- Searches are case-sensitve by default. To do a case-insensitive search,
235
- add a `\c` to your search string, e.g.:
272
+ :SWSearch Gnu
273
+ :SWNamespacedSearch Gnu
236
274
 
237
- :SWSearch Gnu\c
275
+ You can use `:SWS` as a shortcut for `:SWSearch`. You can also
276
+ tab-complete `:SWNS` to `:SWSNamespacedSearch`.
238
277
 
239
- Again, you can use `:SWS` as a shortcut.
278
+ Searches are case-insensitve.
240
279
 
241
280
  Under the hood, `:SWSearch` is just a thin wrapper around the `:vimgrep`
242
- command.
281
+ command. Use `:vimgrep` directly if you want to do anything more
282
+ specific.
243
283
 
244
284
  Tip: You can flag important notes in your wiki content by typing flags
245
285
  like TODO or IMPORTANT on the same line, and then use `:SWSearch` and
@@ -279,42 +319,6 @@ non-programmers, so a future version of SoyWiki may provide a more
279
319
  user-friendly interface for distributed collaboration workflows.
280
320
 
281
321
 
282
- ## Namespaced WikiWords
283
-
284
- You can get very far with SoyWiki using normal CamelCase WikiWords.
285
-
286
- NormalWikiWord
287
-
288
- But if you want, you can also namespace your WikiWords, like so:
289
-
290
- namespaced.WikiWord
291
-
292
- A namespaced WikiWord is a WikiWord prefixed by a namespace and a
293
- period. The namespace word must start with a lower-case letter and
294
- consist only of letters, numbers, and underscore characters. You can't
295
- chain namespace words together: the maximum nesting level is 1.
296
-
297
- Namespaced WikiWords help organize your wiki space conceptually. They also
298
- have two other benefits:
299
-
300
- First, wiki pages that represent a namespaced WikiWord are stored under a
301
- subdirectory named after the namespace. This can help reduce clutter in
302
- your wiki directory.
303
-
304
- Second, a WikiWord namespace lets you use abbreviated links within that
305
- namespace. For example, if you are editing a page called
306
- `recipes.SoyMacaroni` and you want to link to another page in the same
307
- namespace called `recipes.SoyRaspberrySmoothie` you can type the link in
308
- this special abbreviated form:
309
-
310
- .SoyRaspberrySmoothie
311
-
312
- SoyWiki will know from the leading period that this is a link to another
313
- page in the same namespace.
314
-
315
- WikiLink autocompletion also works with abbreviated namespaced links. Just type a
316
- period, and invoke autocompletion with `CTRL-x CTRL-u`.
317
-
318
322
 
319
323
  ## Expanding a wiki page
320
324
 
data/lib/soywiki.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  class String
3
- # TODO change this to a Windows compatible approach
3
+ # not Windows compatible
4
4
  def to_file_path
5
5
  self.gsub(".", "/")
6
6
  end
@@ -20,7 +20,7 @@ end
20
20
 
21
21
 
22
22
  module Soywiki
23
- VERSION = '0.1.3'
23
+ VERSION = '0.1.4'
24
24
  WIKI_WORD = /\b([a-z][\w_]+\.)?[A-Z][a-z]+[A-Z]\w*\b/
25
25
 
26
26
  def self.run
data/lib/soywiki.vim CHANGED
@@ -3,7 +3,8 @@
3
3
  " License: MIT License (c) 2011 Daniel Choi
4
4
 
5
5
  " This regex matches namedspaced WikiWords and unqualified WikiWords
6
- let s:wiki_link_pattern = '\C\<\([a-z][[:alnum:]_]\+\.\)\?[A-Z][a-z]\+[A-Z]\w*\>'
6
+ let s:wiki_link_pattern = '\C\m\<\([a-z][[:alnum:]_]\+\.\)\?[A-Z][a-z]\+[A-Z]\w*\>'
7
+
7
8
 
8
9
  let s:http_link_pattern = 'https\?:[^ >)\]]\+'
9
10
  let s:rename_links_command = 'soywiki-rename '
@@ -40,6 +41,7 @@ func! s:namespace_of_title(page_title)
40
41
  return get(segments, 0)
41
42
  else
42
43
  call s:display_missing_namespace_error(len(segments))
44
+ return ""
43
45
  endif
44
46
  endfunc
45
47
 
@@ -92,11 +94,15 @@ func! s:list_pages()
92
94
  call s:page_list_window(s:get_page_list(), "Select page: ")
93
95
  endfunc
94
96
 
97
+ func! s:trim_link(link)
98
+ let link = matchstr(a:link, s:wiki_link_pattern)
99
+ return link
100
+ endfunc
101
+
95
102
  " returns a fully namespaced link
96
103
  func! s:link_under_cursor()
97
- let link = expand("<cWORD>")
98
- " strip off non-letters at the end (e.g., a comma)
99
- let link = substitute(link, '[^[:alnum:]]*$', '', '')
104
+ let link = s:trim_link(expand("<cWORD>"))
105
+ " strip off non-letters at the end and beginning (e.g., a comma)
100
106
  if ! s:has_namespace(link)
101
107
  let link = s:infer_namespace(link)
102
108
  endif
@@ -151,6 +157,9 @@ func! s:load_page(page, split)
151
157
  if (!filereadable(file))
152
158
  " create the file
153
159
  let namespace = s:namespace_of_title(a:page)
160
+ if namespace == ""
161
+ return
162
+ end
154
163
  call system("mkdir -p " . namespace)
155
164
  call writefile([title, '', ''], file)
156
165
  endif
@@ -257,8 +266,7 @@ func! s:pages_in_this_namespace(pages)
257
266
  let namespace = s:page_namespace()
258
267
  let pages = filter( a:pages, 'v:val =~ "^' . namespace . '\."')
259
268
  " strip leading namespace
260
- let pages = map( pages, "substitute(v:val, '^" . namespace . "\.', '', '') " )
261
- return pages
269
+ return map(pages, "substitute(v:val, '^" . namespace . "\.', '', '') ")
262
270
  endfunc
263
271
 
264
272
  " When user press TAB after typing a few characters in the page selection
@@ -304,44 +312,37 @@ function! s:page_list_window(page_match_list, prompt)
304
312
  " call feedkeys("a", 't')
305
313
  endfunction
306
314
 
307
- " This function assumes s:matching_pages has been set by the calling function
308
315
  function! CompletePageTitle(findstart, base)
309
- let fragment = expand("<cWORD>")
310
- if !exists("s:matching_pages")
311
- let s:matching_pages = s:get_page_list()
312
- endif
313
- if match(fragment, '^[A-Z]') == 0
314
- " we have a WikiWord without a namespace; filter down to pages in pages in this
315
- " namespace
316
- let s:matching_pages = s:pages_in_this_namespace(s:matching_pages)
317
- endif
318
316
  if a:findstart
319
317
  " locate the start of the word
320
- " Assume we're in a page select window if there is a ': ' in the line.
321
- " Admittedly, this is not work well in all cases
322
- if bufname('') == 'page-list-buffer'
323
- " by starting after prompt ': '
324
- let start = match(getline('.'), ': ') + 2
325
- else
326
- " locate the start of the word
327
- let line = getline('.')
328
- let start = col('.') - 1
329
- while start > 0 && line[start - 1] =~ '\a'
330
- let start -= 1
331
- endwhile
332
- end
318
+ let line = getline('.')
319
+ let start = col('.') - 1
320
+ while start > 0 && line[start - 1] =~ '\m[[:alnum:]\.]'
321
+ let start -= 1
322
+ endwhile
333
323
  return start
334
324
  else
335
325
  let base = s:trimString(a:base)
336
326
  if (base == '')
337
- return s:matching_pages
327
+ return s:get_page_list()
338
328
  else
339
329
  let res = []
340
- for m in s:matching_pages
341
- if m =~ '\c' . base
342
- call add(res, m)
343
- endif
344
- endfor
330
+ if bufname('') == 'page-list-buffer'
331
+ let pages = s:get_page_list()
332
+ for m in pages
333
+ if m =~ '\c' . base
334
+ call add(res, m)
335
+ endif
336
+ endfor
337
+ else
338
+ " autocomplete inline
339
+ let pages = base =~ '\C^[a-z]' ? s:get_page_list() : s:pages_in_this_namespace(s:get_page_list())
340
+ for m in pages
341
+ if m =~ '^\c' . base
342
+ call add(res, m)
343
+ endif
344
+ endfor
345
+ endif
345
346
  return res
346
347
  endif
347
348
  endif
@@ -450,10 +451,13 @@ func! s:insert_divider()
450
451
  endfunc
451
452
  "------------------------------------------------------------------------
452
453
  " SEARCH
453
- func! s:wiki_search(pattern)
454
-
454
+ func! s:wiki_search(pattern, in_this_namespace)
455
455
  let pattern = (empty(a:pattern) ? @/ : a:pattern)
456
- execute printf('vimgrep/%s/ %s', pattern, "**/*")
456
+ if a:in_this_namespace
457
+ execute printf('vimgrep/\c%s/ %s', pattern, s:page_namespace()."/*")
458
+ else
459
+ execute printf('vimgrep/\c%s/ %s', pattern, "*/*")
460
+ endif
457
461
  endfunc
458
462
 
459
463
  "------------------------------------------------------------------------
@@ -517,8 +521,8 @@ func! s:global_mappings()
517
521
  command! -bar -nargs=1 -range -complete=file SWLinkAppend :<line1>,<line2>call s:extract(<f-args>, 'append', 1)
518
522
  command! -bar -nargs=1 -range -complete=file SWLinkInsert :<line1>,<line2>call s:extract(<f-args>, 'insert', 1)
519
523
 
520
- command! -bar -nargs=1 SWSearch :call s:wiki_search(<f-args>)
521
- " TODO a search confined to current namespace
524
+ command! -bar -nargs=1 SWSearch :call s:wiki_search(<f-args>, 0)
525
+ command! -bar -nargs=1 SWNamespaceSearch :call s:wiki_search(<f-args>, 1)
522
526
 
523
527
  autocmd BufReadPost,BufNewFile,WinEnter,BufEnter,BufNew,BufAdd * call s:highlight_wikiwords()
524
528
  autocmd BufEnter * call s:prep_buffer()
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Choi