soywiki 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -157,9 +157,10 @@ commands:
157
157
  * `CTRL-k` and `CTRL-j` move the cursor directly to the next or previous WikiLink on the page
158
158
  * `ENTER` follows the WikiLink under the cursor
159
159
  * `,f` follows the first WikiLink after the cursor
160
- * `CTRL-l` opens a WikiLink in a vertical split window
161
- * `CTRL-n` does the same, but in a regular split window
162
- * Both `CTRL-h` and `q` close a split window
160
+ * `CTRL-l` opens a WikiLink in a vertical split window; press again
161
+ while the cursor is on the top line to close the new window
162
+ * `CTRL-h` does the same, but in a regular split window
163
+ * `q` closes a split window
163
164
 
164
165
  These key mappings may not be very mnemonic, but they are easy to
165
166
  memorize through muscle memory and were chosen to keep the hands
data/Rakefile CHANGED
@@ -9,6 +9,10 @@ require 'soywiki'
9
9
 
10
10
  Bundler::GemHelper.install_tasks
11
11
 
12
+
13
+ desc "release and build and push new website"
14
+ task :push => [:release, :build_webpage]
15
+
12
16
  desc "build and push website"
13
17
  task :web => :build_webpage do
14
18
  `scp website/soywiki.html zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
data/lib/soywiki.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'string_ext'
2
2
 
3
3
  module Soywiki
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  WIKI_WORD = /\b([a-z][\w_]+\.)?[A-Z][a-z]+[A-Z]\w*\b/
6
6
 
7
7
  def self.run
data/lib/soywiki.vim CHANGED
@@ -91,7 +91,12 @@ endfunc
91
91
 
92
92
  func! s:list_pages()
93
93
  let s:search_for_link = ""
94
- call s:page_list_window(s:get_page_list(), 'select-page', "Select page: ")
94
+ let pages = s:get_page_list()
95
+ if len(pages) == 0
96
+ echom "There are no wiki pages yet but this one."
97
+ else
98
+ call s:page_list_window(pages, 'select-page', "Select page: ")
99
+ end
95
100
  endfunc
96
101
 
97
102
  func! s:trim_link(link)
@@ -133,6 +138,13 @@ func! s:follow_link_under_cursor(split)
133
138
  if link == ""
134
139
  echom link . " is not a wiki link"
135
140
  return ""
141
+ elseif line('.') == 1
142
+ " SPECIAL CASE
143
+ " close window
144
+ if winnr('$') > 1
145
+ close
146
+ endif
147
+ return
136
148
  else
137
149
  call s:load_page(link, a:split)
138
150
  endif
@@ -148,12 +160,19 @@ func! s:find_next_wiki_link(backward)
148
160
  return s:link_under_cursor()
149
161
  endfunc
150
162
 
163
+ " --------------------------------------------------------------------------------
164
+ " LOAD PAGE
165
+
151
166
  func! s:load_page(page, split)
152
167
  if (s:is_wiki_page())
153
168
  write
154
169
  endif
155
170
  let file = s:pagetitle2file(a:page)
156
171
  let title = s:filename2pagetitle(a:page)
172
+ if bufwinnr(file) != -1
173
+ exec bufwinnr(file)."wincmd w"
174
+ return
175
+ endif
157
176
  if (!filereadable(file))
158
177
  " create the file
159
178
  let namespace = s:namespace_of_title(a:page)
@@ -164,17 +183,17 @@ func! s:load_page(page, split)
164
183
  call writefile([title, '', ''], file)
165
184
  endif
166
185
  if (a:split == 2)
167
- exec "botright vsplit ". file
168
- else
169
- exec "botright split ". file
170
- endif
171
- if (a:split == 0)
172
- wincmd p
173
- close
186
+ exec "rightbelow vsplit ". file
187
+ elseif (a:split == 1)
188
+ exec "rightbelow split ". file
189
+ elseif (a:split == 0)
190
+ exec "e ".file
174
191
  endif
175
- if len(s:search_for_link) > 0
192
+ if s:search_for_link != ''
176
193
  let res = search(s:search_for_link, 'cw')
177
194
  let s:search_for_link = ''
195
+ else
196
+ normal gg
178
197
  endif
179
198
  endfunc
180
199
 
@@ -252,19 +271,29 @@ endfunc
252
271
  " -------------------------------------------------------------------------------
253
272
  " select Page
254
273
 
274
+ func! s:omit_this_page(page_list)
275
+ if exists("s:return_to_bufname")
276
+ let page_list = filter( a:page_list, 'v:val != "'.s:return_to_bufname.'"')
277
+ return page_list
278
+ else
279
+ return a:page_list
280
+ endif
281
+ endfunc
282
+
255
283
  " This function both sets a script variable and returns the value.
256
284
  func! s:get_page_list()
257
285
  " no file current in buffer
258
- if len(bufname('%')) == 0
286
+ if len(bufname('')) == 0
259
287
  return split(system(s:ls_command), "\n")
260
288
  elseif bufname('') == 'pages-linking-in'
261
289
  " this needs refactoring to rely less on state
262
290
  return s:pages_linking_in
263
291
  else
264
- return split(system(s:ls_command . " | grep -vF '" . s:page_title() . "'" ), "\n")
292
+ return s:omit_this_page(split(system(s:ls_command), "\n"))
265
293
  endif
266
294
  endfunction
267
295
 
296
+
268
297
  func! s:pages_in_this_namespace(pages)
269
298
  let namespace = s:page_namespace()
270
299
  let pages = filter( a:pages, 'v:val =~ "^' . namespace . '\."')
@@ -297,6 +326,7 @@ endfunc
297
326
  function! s:page_list_window(page_match_list, buffer_name, prompt)
298
327
  " remember the original window
299
328
  let s:return_to_winnr = winnr()
329
+ let s:return_to_bufname = s:filename2pagetitle(bufname(''))
300
330
  let s:matching_pages = a:page_match_list
301
331
  exec "topleft split ".a:buffer_name
302
332
  setlocal completefunc=CompletePageTitle
@@ -426,7 +456,7 @@ func! s:extract(...) range
426
456
  endif
427
457
  call writefile([page_title, '', ''], file)
428
458
  endif
429
- exec "split ".file
459
+ exec "rightbelow vsplit ".file
430
460
  else
431
461
  let targetWindow = bufwinnr(bufnr(file))
432
462
  exe targetWindow."wincmd w"
@@ -478,7 +508,7 @@ func! s:expand(seamless, vertical)
478
508
  let res = system(s:expand_command . " seamful " . bufname('%'))
479
509
  endif
480
510
  if a:vertical
481
- botright vnew
511
+ rightbelow vnew
482
512
  else
483
513
  new
484
514
  endif
@@ -511,7 +541,6 @@ func! s:global_mappings()
511
541
  noremap <leader>M :call <SID>list_pages_linking_in()<CR>
512
542
  noremap <silent> <leader>o :call <SID>open_href()<cr>
513
543
  nnoremap <silent> q :close<cr>
514
- nnoremap <silent> <C-h> :close<cr>
515
544
 
516
545
  " reflow text
517
546
  nnoremap \ gwap
@@ -539,7 +568,7 @@ func! s:prep_buffer()
539
568
  set textwidth=72
540
569
  nnoremap <buffer> <cr> :call <SID>follow_link_under_cursor(0)<cr>
541
570
  nnoremap <buffer> <c-l> :call <SID>follow_link_under_cursor(2)<cr>
542
- nnoremap <buffer> <c-n> :call <SID>follow_link_under_cursor(1)<cr>
571
+ nnoremap <buffer> <c-h> :call <SID>follow_link_under_cursor(1)<cr>
543
572
  noremap <buffer> <leader>f :call <SID>follow_link(0)<CR>
544
573
  noremap <buffer> <c-j> :call <SID>find_next_wiki_link(0)<CR>
545
574
  noremap <buffer> <c-k> :call <SID>find_next_wiki_link(1)<CR>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Choi