├── doc ├── tags └── weakpoint.txt ├── plugin └── weakpoint.vim ├── README.md └── WeekPointSplitter.lua /doc/tags: -------------------------------------------------------------------------------- 1 | :WeakPoint weakpoint.txt /*:WeakPoint* 2 | WeakPoint weakpoint.txt /*WeakPoint* 3 | weakpoint weakpoint.txt /*weakpoint* 4 | weakpoint-installation weakpoint.txt /*weakpoint-installation* 5 | weakpoint-license weakpoint.txt /*weakpoint-license* 6 | weakpoint-requirements weakpoint.txt /*weakpoint-requirements* 7 | weakpoint-usage weakpoint.txt /*weakpoint-usage* 8 | weakpoint.txt weakpoint.txt /*weakpoint.txt* 9 | -------------------------------------------------------------------------------- /doc/weakpoint.txt: -------------------------------------------------------------------------------- 1 | *weakpoint.txt* Simple slideshow tool 2 | 3 | Author: Pavel Tisnovsky 4 | License: BSD-like (see |weakpoint-license|) 5 | 6 | INTRODUCTION *weakpoint* *WeakPoint* 7 | 8 | Simple slideshow tool 9 | 10 | REQUIREMENTS *weakpoint-requirements* 11 | 12 | - On Unix, you need to have "cp" and "sort" in your path. 13 | 14 | INSTALLATION *weakpoint-installation* 15 | 16 | cd ~/.vim/bundle 17 | git clone git://github.com/tisnik/vim-weakpoint 18 | 19 | USAGE *weakpoint-usage* *:WeakPoint* 20 | > 21 | :WeakPoint 22 | < 23 | LICENSE *weakpoint-license* 24 | 25 | Copyright (c) 2012-2015 Pavel Tisnovsky 26 | 27 | Redistribution and use in source and binary forms, with or without 28 | modification, are permitted provided that the following conditions are 29 | met: 30 | 31 | * Redistributions of source code must retain the above copyright 32 | notice, this list of conditions and the following disclaimer. 33 | * Redistributions in binary form must reproduce the above copyright 34 | notice, this list of conditions and the following disclaimer in the 35 | documentation and/or other materials provided with the distribution. 36 | * Neither the name William Lee nor the names of its contributors may be 37 | used to endorse or promote products derived from this software without 38 | specific prior written permission. 39 | 40 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 41 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 42 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 43 | WILLIAM LEE AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 44 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 46 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 47 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 48 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 49 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | 51 | vim:tw=78:et:ft=help:norl: 52 | -------------------------------------------------------------------------------- /plugin/weakpoint.vim: -------------------------------------------------------------------------------- 1 | " Slideshow tool v1.2 2 | " Pavel Tisnovsky 2012, 2013, 2014, 2015 3 | 4 | " Ziskani seznamu vsech souboru v aktualnim adresari 5 | function! s:GetFileList() 6 | return split(system("ls -1 | sort")) 7 | endfunction 8 | 9 | " Prechod na prvni slajd 10 | function! s:GotoFirstSlide() 11 | let s:index = 0 12 | endfunction 13 | 14 | " Prechod na posledni slajd 15 | function! s:GotoLastSlide() 16 | let s:index = len(s:slides) - 1 17 | endfunction 18 | 19 | " Zjisteni, zda uzivatel nepresel pred prvni slajd 20 | function! s:BeforeFirstSlide() 21 | return s:index < 0 22 | endfunction 23 | 24 | " Zjisteni, zda uzivatel nepresel za posledni slajd 25 | function! s:AfterLastSlide() 26 | return s:index >= len(s:slides) 27 | endfunction 28 | 29 | " Zobrazeni nasledujiciho slajdu 30 | function! s:ShowNextSlide() 31 | let s:index += 1 32 | if s:AfterLastSlide() 33 | call s:GotoFirstSlide() 34 | endif 35 | call s:ShowActualSlide() 36 | endfunction 37 | 38 | " Zobrazeni predchoziho slajdu 39 | function! s:ShowPrevSlide() 40 | let s:index -= 1 41 | if s:BeforeFirstSlide() 42 | call s:GotoLastSlide() 43 | endif 44 | call s:ShowActualSlide() 45 | endfunction 46 | 47 | " Zobrazeni prvniho slajdu 48 | function! s:ShowFirstSlide() 49 | call s:GotoFirstSlide() 50 | call s:ShowActualSlide() 51 | endfunction 52 | 53 | " Zobrazeni posledniho slajdu 54 | function! s:ShowLastSlide() 55 | call s:GotoLastSlide() 56 | call s:ShowActualSlide() 57 | endfunction 58 | 59 | " Funkce zajistujici nacteni slajdu 60 | function! s:ShowActualSlide() 61 | execute "edit" s:slides[s:index] 62 | endfunction 63 | 64 | " Uprava stavove radky - bude se zobrazovat cislo 65 | " slajdu, pocet slajdu a jmeno souboru obsahujiciho slajd 66 | function! StatusLine() 67 | return "Slide " . (1+s:index) . "/" . len(s:slides) . " : " . s:slides[s:index] 68 | endfunction 69 | 70 | " Nastaveni zpusobu ovladani prohlizecky 71 | function! s:SetupKeys() 72 | noremap :call ShowPrevSlide() 73 | noremap :call ShowNextSlide() 74 | noremap :call ShowFirstSlide() 75 | noremap :call ShowLastSlide() 76 | endfunction 77 | 78 | function! s:WeakPoint() 79 | " Promenna obsahujici seznam slajdu 80 | let s:slides = s:GetFileList() 81 | 82 | " Index aktualniho slajdu 83 | let s:index = 0 84 | 85 | " Kontrola 86 | if s:slides == [] 87 | echo "Zadne soubory v pracovnim adresari" 88 | else 89 | " Registrace funkce pouzite pro zjisteni obsahu stavove radky 90 | set statusline=%!StatusLine() 91 | 92 | " Nastaveni zobrazeni stavove radky i v pripade, ze je pouzito 93 | " jen jedno okno 94 | set laststatus=2 95 | 96 | call s:ShowFirstSlide() 97 | call s:SetupKeys() 98 | endif 99 | endfunction 100 | 101 | command WeakPoint :call s:WeakPoint() 102 | 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-weakpoint 2 | 3 | Simple markdown-able plaintext slideshow tool for vim 4 | 5 | ### Table of Contents 6 | * [Installation](#installation) 7 | * [Usage](#usage) 8 | * [Markdown support](#markdown-support) 9 | * [Enabling markdown](#enabling-markdown) 10 | * [Folding](#folding) 11 | * [Single file presentation](#single-file-presentation) 12 | * [Example file](#example-file) 13 | * [Magic command](#magic-command) 14 | * [Options](#options) 15 | * [Example result animation](#example-result-animation) 16 | * [License](#license) 17 | 18 | # vim-weakpoint 19 | 20 | Simple markdown-able plaintext slideshow tool for vim 21 | 22 | ## Installation 23 | 24 | With [pathogen.vim](https://github.com/tpope/vim-pathogen): 25 | 26 | cd ~/.vim/bundle 27 | git clone git://github.com/tisnik/vim-weakpoint 28 | 29 | ## Usage 30 | 31 | :cd directory_with_slides 32 | :WeakPoint 33 | 34 | or directly: 35 | 36 | cd directory_with_slides && vim -c ":WeakPoint" 37 | 38 | * If you use pathogen, you can use :Helptags to regenerate documentation. 39 | * You then can see ":h weakpoint" for more information. 40 | * Don't forget that your slides must be **sortable** to have an order in slideshow 41 | 42 | ## Markdown support 43 | Markdown, which is nice both as plain text and as interpreted file, will change vim-plain-text-presentation to really fully featured one. 44 | ### Enabling markdown 45 | * Install, again via pathogen, [vim-markdown](https://github.com/plasticboy/vim-markdown): 46 | * suffix your slides with .markdown as `xyz.markdown` 47 | * out of the box you will get 48 | * bullets 49 | * bold and italic 50 | * urls 51 | * headlines 52 | * code highlight 53 | * and much more... to create awesome plaintext presentation 54 | 55 | **tip**: configure font of your terminal emulator to adapt to the screen/projector ... blindness of audience 56 | 57 | ### Folding 58 | For successful presentation, except usual pathogen settings of 59 | 60 | execute pathogen#infect() 61 | syntax on 62 | filetype plugin indent on 63 | 64 | it is **strongly recomended** to have also 65 | 66 | let g:vim_markdown_folding_disabled = 1 67 | :set tabstop=4 68 | :set shiftwidth=4 69 | 70 | in `/.vimrc `; to avoid unexpected behavior of markdown during presentations (like auto folding or corrupted tables) 71 | 72 | ## Single file presentation 73 | The plaintext presentations (especially markdowned) may be awesome for some cases, however *creating* them with slide per file can be extremely uncomfortable. To help with this issue `~/.vim/bundle/vim-weakpoint/WeekPointSplitter.lua` was added. This lua (which you already have) script requires lua-posix (which you likely have too). 74 | 75 | ### Example file 76 | This allows you to write single file presentation, eg: 77 |
 78 | # WeakPoint markdown presentation
 79 | 	* vim-weakpoint + vim-markdown are **awesome**
 80 | 		* allows code `like this`
 81 | 		* allows bullets
 82 | 		* allows *italic*
 83 | 		=> creates non disturbing presentation with all comfort
 84 |    * Above you can see that also errors in parsing can be useful
 85 |    * it also allows http://some.url/highlighted/clickable ,  cool!
 86 | 
 87 | ## Folding
 88 | Unluckily folding must be disabled, and various levels of headlines are not distinguished
 89 | --PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE--
 90 | # Tables
 91 |  			cool	diff-able	images
 92 | WeakPoint	x		x			only via url
 93 | PowerPoint	no		no			depends on your opinion on cliparts
 94 | 
 95 | So they works to...
 96 | --PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE----PAGE---
 97 | # Code
 98 | single `code` is working. How does multi-line?
 99 | ```
100 | it can
101 | rocks too!
102 | ```
103 | the one with empty lines:
104 | 
105 | 	code
106 | 	is it
107 | 	right
108 | 
109 | This is no more code
110 | 	HTH
111 | 
112 | 113 | ### Magic command 114 | 115 | This file can then can be processed like eg: 116 | `lua ~/.vim/bundle/vim-weakpoint/WeekPointSplitter.lua ~/Desktop/examplePresentation.markdown -deduct -height 30 -vim` 117 | This created: 118 | ``` 119 | tree ~/Desktop/examplePresentation-WeakPoint/ 120 | ~/Desktop/examplePresentation-WeakPoint/ 121 | ├── 1.markdown 122 | ├── 2.markdown 123 | └── 3.markdown 124 | 125 | 0 directories, 3 files 126 | ``` 127 | And lunched your plaintext presentation in the ~/Desktop/examplePresentation-WeakPoint/. You do not need to worry about sorting, as output of WeekPointSplitter.lua is always sortable, no metter of count of slides. 128 | 129 | ### Options 130 | 131 | Except simple splitting of given file in current working directory, WeekPointSplitter allowes you a bit more: 132 | * enforce output dir via `-output` 133 | * if necessary, to remove content of this directory via `-clean` 134 | * **deduct** via `-deduct` switch the output directory location and name from input file 135 | * to get rid of vim's `~` non existing line marker via `-height number` which adds *number* of empty spaces 136 | * to overwrite default `--PAGE--` marker via `-break new_value` 137 | * the page is split, everytime line *starts with* this pattern 138 | * to generate slides, or directly start WeakPoint via `-vim` 139 | 140 | if you wish to chain the tool, it uses stderr, except final output of output directory to stdout. 141 | 142 | ## Example result animation 143 | 144 | You can see individual images at: https://github.com/tisnik/vim-weakpoint/issues/1 145 | 146 | ![animation](https://user-images.githubusercontent.com/2904395/43991898-30990754-9d76-11e8-9060-867bb0136c06.gif) 147 | 148 | ## License 149 | 150 | Copyright (c) 2012-2015 Pavel Tisnovsky (BSD-Like) 151 | 152 | -------------------------------------------------------------------------------- /WeekPointSplitter.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/lua 2 | 3 | local OUTPUT_SWITCH = "-output" 4 | local CLEAN_SWITCH = "-clean" 5 | local DEDUCT_SWITCH = "-deduct" 6 | local HEIGHT_SWITCH = "-height" 7 | local BREAK_SWITCH = "-break" 8 | local VIM = "-vim" 9 | 10 | local OUT_DIR_DEFAULT="." 11 | local inFile = nil 12 | local outDir = OUT_DIR_DEFAULT 13 | local clean = false 14 | local deduct = false 15 | local height = 0 16 | local page = "--PAGE--" 17 | local vim = false 18 | 19 | local function boolToString(b) 20 | if (b) then 21 | return "true" 22 | else 23 | return "false" 24 | end 25 | end 26 | local function help(exit) 27 | print("Spliting uttility for github.com/tisnik/vim-weakpoint (ideally with github.com/plasticboy/vim-markdown [which neds .markdown suffix])") 28 | print("Will split your file to several slides, so you can run them as comfortbale console presentation") 29 | print("Single input parameter of inut file is necessary eg PtisnovsWeakPointSpliter my/file.markdown") 30 | print("Optional swithces") 31 | print(OUTPUT_SWITCH.." dir_to_save_slides_to set the output directory. Default is `"..outDir.. "`") 32 | print(CLEAN_SWITCH.." default "..", will empty the output directory") 33 | print(DEDUCT_SWITCH.." default "..boolToString(deduct)..", will create directory input'sDir/file-WeakPoint (wihtut suffix), and treat it as -output. Or in input'sDir/file-WeakPoint if output is specified. If you need cwd, do not use -deduct ") 34 | print(HEIGHT_SWITCH.." number defualt "..height..",will fill the slides with empty lines untill a number (so vim do not show the ~)") 35 | print(BREAK_SWITCH.." string if line is starting by this string, the line is removed, and next slide started default is "..page) 36 | print("Warning, some characters, like . have to be escaped by %. (eg %.). This is caused by my stupidity in startsWith implementation by pseudo regex") 37 | print(VIM.." default "..boolToString(vim)..", after presentation is lunched, vim is executed in target dirctory, so you can ctrl+c:WeakPoint and check the slides") 38 | os.exit(exit) 39 | end 40 | 41 | function startsWith(str,start) 42 | return string.sub(str, 1, string.len(start))==start 43 | end 44 | 45 | function fileExists(name) 46 | local f=io.open(name,"r") 47 | if f~=nil then 48 | io.close(f) 49 | return true 50 | else 51 | return false 52 | end 53 | end 54 | 55 | function lastIndexOf(haystack, needle) 56 | local i=string.match(haystack, ".*"..needle.."()") 57 | if i==nil then 58 | return nil 59 | else 60 | return i-1 61 | end 62 | end 63 | 64 | function deductFileName(name) 65 | if (string.match(name, "%.")) then 66 | name = string.sub(name, 0, lastIndexOf(name, "%.")-1) 67 | end 68 | return name.."-WeakPoint" 69 | end 70 | 71 | function fileGetName(path) 72 | if (string.match(path, "/")) then 73 | name = string.sub(path, lastIndexOf(path, "/")+1) 74 | else 75 | name=name 76 | end 77 | return name 78 | end 79 | 80 | function getParentFile(path) 81 | if (string.match(path, "/")) then 82 | parent = string.sub(path, 0, lastIndexOf(path, "/")) 83 | else 84 | parent="." 85 | end 86 | return parent 87 | end 88 | 89 | function createWriter(currentPage, outDir, width, name) 90 | local f = outDir.."/"..createName(currentPage, width, name) 91 | fho,err = io.open(f,"w") 92 | return fho 93 | end 94 | 95 | function createName(currentPage, width, name) 96 | local suffix = "" 97 | if (string.match(name, "%.")) then 98 | suffix = string.sub(name, lastIndexOf(name,"%.")) 99 | end 100 | local r = currentPage.."" 101 | while (#r < width) do 102 | r="0"..r; 103 | end 104 | r=r..suffix; 105 | io.stderr:write(r.."\n"); 106 | return r; 107 | end 108 | 109 | if (#arg == 0) then 110 | help(1) 111 | end 112 | 113 | local shift=0; 114 | for x=1,#arg,1 do 115 | i=x+shift 116 | if (i > #arg) then 117 | break 118 | end 119 | if (arg[i] == "-h" or arg[i] == "--help" or arg[i] == "-help") then 120 | if (#arg == 1) then 121 | help(0) 122 | else 123 | help(10) 124 | end 125 | end 126 | if (startsWith(arg[i], "-")) then 127 | if (arg[i] == OUTPUT_SWITCH) then 128 | shift=shift+1 129 | outDir = arg[i+1] 130 | elseif (arg[i] == CLEAN_SWITCH) then 131 | clean = true 132 | elseif (arg[i] == DEDUCT_SWITCH) then 133 | deduct = true 134 | elseif (arg[i] == HEIGHT_SWITCH) then 135 | shift=shift+1 136 | height = tonumber(arg[i+1]) 137 | elseif (arg[i] == BREAK_SWITCH) then 138 | shift=shift+1 139 | page = arg[i+1] 140 | elseif(arg[i] == VIM) then 141 | vim = true 142 | else 143 | io.stderr:write("unknown switch "..arg[i].."\n") 144 | os.exit(3) 145 | end 146 | else 147 | inFile = arg[i] 148 | end 149 | end 150 | 151 | if (fileExists(inFile)) then 152 | io.stderr:write(inFile.." exists and is file\n") 153 | else 154 | io.stderr:write(inFile.." do not exists and is not file\n") 155 | os.exit(2) 156 | end 157 | 158 | io.stderr:write(CLEAN_SWITCH..": "..boolToString(clean).."\n") 159 | io.stderr:write(DEDUCT_SWITCH..": "..boolToString(deduct).."\n") 160 | io.stderr:write(HEIGHT_SWITCH..": "..height.."\n") 161 | io.stderr:write(BREAK_SWITCH..": "..page.."\n") 162 | io.stderr:write(VIM..": "..boolToString(vim).."\n") 163 | local posix = require "posix" 164 | if (deduct) then 165 | local name = deductFileName(fileGetName(inFile)) 166 | if (outDir == OUT_DIR_DEFAULT) then 167 | -- not set: cwd or via in? 168 | -- in cwd is used differently usually 169 | outDir = getParentFile(inFile)..name 170 | else 171 | outDir = outDir.."/"..name 172 | end 173 | posix.mkdir(outDir) 174 | end 175 | io.stderr:write(OUTPUT_SWITCH..": "..outDir.."\n") 176 | 177 | if (clean) then 178 | posix.spawn({"rm", "-rfv", outDir..""}) 179 | posix.mkdir(outDir) 180 | end 181 | 182 | local totalPages = 1; 183 | fh,err = io.open(inFile) 184 | while true do 185 | s = fh:read() 186 | if s == nil then break end 187 | if startsWith(s,page) then 188 | totalPages=totalPages+1 189 | end 190 | end 191 | fh:close() 192 | io.stderr:write("Pages: "..totalPages.."\n"); 193 | local width = #(totalPages..""); 194 | local currentPage = 1; 195 | local lines = 0; 196 | fh,err = io.open(inFile) 197 | local bw = createWriter(currentPage, outDir, width, fileGetName(inFile)); 198 | while true do 199 | s = fh:read() 200 | if s == nil then break end 201 | lines=lines+1 202 | if startsWith(s,page) then 203 | for x=lines,height,1 do 204 | bw:write("\n") 205 | end 206 | bw:flush() 207 | bw:close() 208 | currentPage=currentPage+1; 209 | lines = 0; 210 | bw = createWriter(currentPage, outDir, width, fileGetName(inFile)); 211 | else 212 | bw:write(s) 213 | bw:write("\n") 214 | end 215 | end 216 | fh:close() 217 | for x=lines,height-1,1 do 218 | bw:write("\n") 219 | end 220 | bw:flush() 221 | bw:close() 222 | io.stderr:flush(); 223 | print(outDir); 224 | if (vim) then 225 | cwd=posix.getcwd() 226 | posix.chdir(outDir) 227 | posix.execp("vim", {".", "-c", ":WeakPoint"}) 228 | posix.chdir(cwd) --should be not necessary 229 | end 230 | --------------------------------------------------------------------------------