1
0
Fork 0
mirror of synced 2024-11-22 08:45:34 -05:00

Updated plugins

This commit is contained in:
Amir 2021-08-04 15:52:11 +02:00
parent ab92a1d4f5
commit b3698e4d38
63 changed files with 5414 additions and 2901 deletions

View file

@ -113,8 +113,8 @@ I recommend reading the docs of these plugins to understand them better. Each pl
## Included color schemes ## Included color schemes
* [dracula](https://github.com/dracula/vim): The default * [peaksea](https://github.com/vim-scripts/peaksea): The default
* [peaksea](https://github.com/vim-scripts/peaksea) * [dracula](https://github.com/dracula/vim)
* [vim-colors-solarized](https://github.com/altercation/vim-colors-solarized) * [vim-colors-solarized](https://github.com/altercation/vim-colors-solarized)
* [vim-irblack](https://github.com/wgibbs/vim-irblack) * [vim-irblack](https://github.com/wgibbs/vim-irblack)
* [mayansmoke](https://github.com/vim-scripts/mayansmoke) * [mayansmoke](https://github.com/vim-scripts/mayansmoke)

View file

@ -73,7 +73,7 @@ endfunction
function! ale_linters#ansible#ansible_lint#GetCommand(buffer, version) abort function! ale_linters#ansible#ansible_lint#GetCommand(buffer, version) abort
let l:commands = { let l:commands = {
\ '>=5.0.0': '%e --nocolor --parseable-severity -x yaml -', \ '>=5.0.0': '%e --nocolor --parseable-severity -x yaml %s',
\ '<5.0.0': '%e --nocolor -p %t' \ '<5.0.0': '%e --nocolor -p %t'
\} \}
let l:command = ale#semver#GTE(a:version, [5, 0]) ? l:commands['>=5.0.0'] : l:commands['<5.0.0'] let l:command = ale#semver#GTE(a:version, [5, 0]) ? l:commands['>=5.0.0'] : l:commands['<5.0.0']
@ -91,6 +91,7 @@ call ale#linter#Define('ansible', {
\ '%e --version', \ '%e --version',
\ function('ale_linters#ansible#ansible_lint#GetCommand'), \ function('ale_linters#ansible#ansible_lint#GetCommand'),
\ )}, \ )},
\ 'lint_file': 1,
\ 'callback': {buffer, lines -> ale#semver#RunWithVersionCheck( \ 'callback': {buffer, lines -> ale#semver#RunWithVersionCheck(
\ buffer, \ buffer,
\ ale_linters#ansible#ansible_lint#GetExecutable(buffer), \ ale_linters#ansible#ansible_lint#GetExecutable(buffer),

View file

@ -0,0 +1,46 @@
" Author: Jon Parise <jon@indelible.org>
call ale#Set('thrift_thriftcheck_executable', 'thriftcheck')
call ale#Set('thrift_thriftcheck_options', '')
function! ale_linters#thrift#thriftcheck#GetCommand(buffer) abort
return '%e'
\ . ale#Pad(ale#Var(a:buffer, 'thrift_thriftcheck_options'))
\ . ' --stdin-filename %s'
\ . ' %t'
endfunction
function! ale_linters#thrift#thriftcheck#Handle(buffer, lines) abort
" Matches lines like the following:
"
" file.thrift:1:1:error: "py" namespace must match "^idl\\." (namespace.pattern)
" file.thrift:3:5:warning: 64-bit integer constant -2147483649 may not work in all languages (int.64bit)
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+):(\l+): (.*) \((.*)\)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
if l:match[3] is# 'warning'
let l:type = 'W'
else
let l:type = 'E'
endif
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'type': l:type,
\ 'text': l:match[4],
\ 'code': l:match[5],
\})
endfor
return l:output
endfunction
call ale#linter#Define('thrift', {
\ 'name': 'thriftcheck',
\ 'executable': {b -> ale#Var(b, 'thrift_thriftcheck_executable')},
\ 'command': function('ale_linters#thrift#thriftcheck#GetCommand'),
\ 'callback': 'ale_linters#thrift#thriftcheck#Handle',
\})

View file

@ -533,6 +533,7 @@ Notes:
* `write-good` * `write-good`
* Thrift * Thrift
* `thrift` * `thrift`
* `thriftcheck`
* TypeScript * TypeScript
* `deno` * `deno`
* `eslint` * `eslint`

View file

@ -42,5 +42,24 @@ g:ale_thrift_thrift_options *g:ale_thrift_thrift_options*
This variable can be changed to customize the additional command-line This variable can be changed to customize the additional command-line
arguments that are passed to the thrift compiler. arguments that are passed to the thrift compiler.
===============================================================================
thriftcheck *ale-thrift-thriftcheck*
g:ale_thrift_thriftcheck_executable *g:ale_thrift_thriftcheck_executable*
*b:ale_thrift_thriftcheck_executable*
Type: |String|
Default: `'thriftcheck'`
See |ale-integrations-local-executables|
g:ale_thrift_thriftcheck_options *g:ale_thrift_thriftcheck_options*
*b:ale_thrift_thriftcheck_options*
Type: |String|
Default: `''`
This variable can be changed to customize the additional command-line
arguments that are passed to thriftcheck.
=============================================================================== ===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -460,7 +460,7 @@ integration should not be combined with ALE's own implementation.
ALE additionally integrates with asyncomplete.vim for offering automatic ALE additionally integrates with asyncomplete.vim for offering automatic
completion data. ALE's asyncomplete source requires registration and should completion data. ALE's asyncomplete source requires registration and should
use the defaults provided by the|asyncomplete#sources#ale#get_source_options| function > use the defaults provided by the |asyncomplete#sources#ale#get_source_options| function >
" Use ALE's function for asyncomplete defaults " Use ALE's function for asyncomplete defaults
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#ale#get_source_options({ au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#ale#get_source_options({
@ -3053,6 +3053,7 @@ documented in additional help files.
write-good............................|ale-text-write-good| write-good............................|ale-text-write-good|
thrift..................................|ale-thrift-options| thrift..................................|ale-thrift-options|
thrift................................|ale-thrift-thrift| thrift................................|ale-thrift-thrift|
thriftcheck...........................|ale-thrift-thriftcheck|
typescript..............................|ale-typescript-options| typescript..............................|ale-typescript-options|
deno..................................|ale-typescript-deno| deno..................................|ale-typescript-deno|
eslint................................|ale-typescript-eslint| eslint................................|ale-typescript-eslint|

View file

@ -270,7 +270,7 @@ formatting.
* JSON * JSON
* [fixjson](https://github.com/rhysd/fixjson) * [fixjson](https://github.com/rhysd/fixjson)
* [jq](https://stedolan.github.io/jq/) * [jq](https://stedolan.github.io/jq/)
* [jsonlint](http://zaa.ch/jsonlint/) * [jsonlint](https://github.com/zaach/jsonlint)
* [prettier](https://github.com/prettier/prettier) * [prettier](https://github.com/prettier/prettier)
* [spectral](https://github.com/stoplightio/spectral) * [spectral](https://github.com/stoplightio/spectral)
* Julia * Julia
@ -542,6 +542,7 @@ formatting.
* [write-good](https://github.com/btford/write-good) :warning: * [write-good](https://github.com/btford/write-good) :warning:
* Thrift * Thrift
* [thrift](http://thrift.apache.org/) * [thrift](http://thrift.apache.org/)
* [thriftcheck](https://github.com/pinterest/thriftcheck)
* TypeScript * TypeScript
* [deno](https://deno.land/) * [deno](https://deno.land/)
* [eslint](http://eslint.org/) * [eslint](http://eslint.org/)

View file

@ -157,7 +157,14 @@ function! s:RunRustfmt(command, tmpname, from_writepre)
endif endif
call s:DeleteLines(len(l:content), line('$')) call s:DeleteLines(len(l:content), line('$'))
call setline(1, l:content) if has('nvim') && exists('*nvim_buf_set_lines')
" setline() gets called for every item on the array,
" this results on the neovim buffer callbacks being called n times,
" using nvim_buf_set_lines() makes the change in one call.
call nvim_buf_set_lines(0, 0, -1, v:true, l:content)
else
call setline(1, l:content)
endif
" only clear location list if it was previously filled to prevent " only clear location list if it was previously filled to prevent
" clobbering other additions " clobbering other additions

13
sources_non_forked/tlib/.gitignore vendored Normal file
View file

@ -0,0 +1,13 @@
tags
!doc/tags
Makefile
TODO.TXT
TODO_archived.viki
*.vba
*.vmb
*.zip
.last_*
test
test_*
tmp
var

View file

@ -0,0 +1,909 @@
0.1
Initial release
0.2
- More list convenience functions
- tlib#EditList()
- tlib#InputList(): properly handle duplicate items; it type contains
'i', the list index + 1 is returned, not the element
0.3
- tlib#InputList(): Show feedback in statusline instead of the echo area
- tlib#GetVar(), tlib#GetValue()
0.4
- tlib#InputList(): Up/Down keys wrap around list
- tlib#InputList(): FIX: Problem when reducing the filter & using AND
- tlib#InputList(): Made <a-numeric> work (can be configured via
- tlib#InputList(): special display_format: "filename"
- tlib#Object: experimental support for some kind of OOP
- tlib#World: Extracted some functions from tlib.vim to tlib/World.vim
- tlib#FileJoin(), tlib#FileSplit(), tlib#RelativeFilename()
- tlib#Let()
- tlib#EnsureDirectoryExists(dir)
- tlib#DirName(dir)
- tlib#DecodeURL(url), tlib#EncodeChar(char), tlib#EncodeURL(url)
- FIX: Problem when using shift-up/down with filtered lists
0.5
- tlib#InputList(): FIX: Selecting items in filtered view
- tlib#InputList(): <c-bs>: Remove last AND pattern from filter
0.6
- tlib#InputList(): Disabled <c-space> map
- tlib#InputList(): try to be smart about user itentions only if a
list's length is < g:tlib_sortprefs_threshold (default: 200)
- tlib#Object: Super() method
- tlib#MyRuntimeDir()
- tlib#GetCacheName(), tlib#CacheSave(), tlib#CacheGet()
- tlib#Args(), tlib#GetArg()
- FIX: tlib#InputList(): Display problem with first item
0.7
- tlib#InputList(): <c-z> ... Suspend/Resume input
- tlib#InputList(): <c-q> ... Input text on the command line (useful on
slow systems when working with very large lists)
- tlib#InputList(): AND-pattern starting with '!' will work as 'exclude
matches'
- tlib#InputList(): FIX <c-bs> pop OR-patterns properly
- tlib#InputList(): display_format == filename: don't add '/' to
directory names (avoid filesystem access)
0.8
- FIX: Return empty cache name for buffers that have no files attached to it
- Some re-arranging
0.9
- Re-arrangements & modularization (this means many function names have
changed, on the other hand only those functions are loaded that are
actually needed)
- tlib#input#List(): Added maps with m-modifiers for <c-q>, <c-z>, <c-a>
- tlib#input#List(): Make sure &fdm is manual
- tlib#input#List(): When exiting the list view, consume the next 5
characters in the queue (if any)
- tlib#input#EditList(): Now has cut, copy, paste functionality.
- Added documentation and examples
0.10
- tlib#input#List(): (v)split type of commands leave the original window
untouched (you may use <c-w> to replace its contents)
- tlib#file#With(): Check whether an existing buffer is loaded.
- Scratch related functions went to tlib/scratch.vim so that they are
accessible from other scripts.
- Configure the list window height via g:tlib_inputlist_pct (1..100%)
0.11
NEW:
- The :TLet command replaces :TLLet (which was removed)
- :TScratch[!] command (with ! don't split but use the whole window)
- tlib#rx#Escape(text, ?magic='m')
- tlib#buffer#GetList(?show_hidden=0)
- tlib#dir#CD(), tlib#dir#Push(), tlib#dir#Pop()
- tlib#input#ListW: A slightly remodeled version of tlib#input#List
that takes a World as second argument.
- Added some documentation doc/tlib.txt (most of it is automatically
compiled from the source files)
CHANGES:
- tlib#input#List(): The default keys for AND, NOT have changed to
be more Google-like (space, minus); the keys can be configured via
global variables.
IMPROVEMENTS:
- In file listings, indicate if a file is loaded, listed, modified
etc.
- tlib#input#List(): Highlight the filter pattern
- tlib#input#List(): <c-up/down> scrolls g:tlib_scroll_lines
(default=10) lines
FIXES:
- tlib#input#List(): Centering line, clear match, clear & restore
the search register
- tlib#input#List(): Ensure the window layout doesn't change (if the
number of windows hasn't changed)
- tlib#arg#Ex(): Don't escape backslashes by default
0.12
NEW:
- tlib/tab.vim
CHANGES:
- Renamed tlib#win#SetWin() to tlib#win#Set()
IMPROVEMENTS:
- tlib#input#List(): <left>, <right> keys work in some lists
- tlib#input#List(): If an index_table is provided this will be used
instead of the item's list index.
FIXES:
- tlib#input#List(): Problem with scrolling, when the list was
shorter than the window (eg when using a vertical window).
- tlib#cache#Filename(): Don't rewrite name as relative filename if
explicitly given as argument. Avoid double (back)slashes.
- TLet: simplified
0.13
CHANGES:
- Scratch: Set &fdc=0.
- The cache directory can be configured via g:tlib_cache
- Renamed tlib#buffer#SetBuffer() to tlib#buffer#Set().
FIXES:
- tlib#input#List(): Select the active item per mouse.
- TLet: simplified
0.14
NEW:
- tlib#buffer#InsertText()
CHANGES:
- tlib#win#[SG]etLayout(): Use a dictionnary, set &cmdheight.
FIXES:
- Wrong order with pre-defined filters.
0.15
NEW:
- tlib#string#TrimLeft(), tlib#string#TrimRight(), tlib#string#Strip()
- Progress bar
0.16
NEW:
- tlib#string#Printf1()
0.17
NEW:
- TBrowseOutput
- Some minor changes
0.18
NEW:
- tlib/time.vim
- g:tlib_inputlist_livesearch_threshold
CHANGES:
- tlib#input#ListD(), World: Don't redisplay the list while typing
new letters; calculate filter regexps only once before filtering the
list.
- World.vim: Minor changes to how filenames are handled.
0.19
NEW:
- tag.vim
FIX:
- dir.vim: Use plain dir name in tlib#dir#Ensure()
- tlib#input#List(): An initial filter argument creates [[filter]]
and not as before [[''], [filter]].
- tlib#input#List(): When type was "si" and the item was picked by
filter, the wrong index was returned.
- tlib#input#List(): Don't check if chars are typed when displaying
the list for the first time.
0.20
- The arguments of tlib#tag#Collect() have changed.
- tlib#input#List(): The view can be "suspended" on initial display.
- tlib#input#List(): Follow/trace cursor functionality
0.21
- tlib#buffer#InsertText(): Respect tabs and (experimental) formatoptions+=or
- tlib/syntax.vim: Syntax-related functions
0.22
- FIX: very magic mode for tlib#rx#Escape() (thanks A Politz)
- FIX: tlib#arg#Ex: escape "!"
0.23
- Respect the setting of g:tlib_inputlist_filename_indicators
- tlib#input#List(): Reset syntax on resume; option to make list window "sticky"
- tlib#agent#ToggleStickyList()
- Simplified tlib#url#Decode()
- tlib#arg#Ex(): use fnameescape() if available
0.24
- s:prototype.SetInitialFilter: accept list as argument
- Maintain buffer MRU if required
0.25
- NEW: tlib#notify#TrimMessage(): trim message to prevent "Press ENTER"
messages (contributed by Erik Falor)
- NEW: tlib#notify#Echo()
- FIX: World.CloseScratch(): Set window
- FIX: tlib#input#ListW(): Set initial_display = 1 on reset
0.26
- NEW: tlib#normal#WithRegister()
- FIX: Try not to change numbered registers
0.27
- FIX: Cosmetic bug, wrong packaging (thanks Nathan Neff)
- Meaning of World#filter_format changed; new World#filter_options
- Filtering didn't work as advertised
- tlib#string#Count()
0.28
- tlib#input#List():
-- Improved handling of sticky lists; <cr> and <Leftmouse> resume a
suspended list and immediately selects the item under the cursor
-- Experimental "seq" matching style: the conjunctions are sequentially
ordered, they are combined with "OR" (disjunctions), the regexp is
'magic', and "." is expanded to '.\{-}'
-- Experimental "cnfd" matching style: Same as cnf but with an "elastic"
dot "." that matches '\.\{-}'
-- Filtering acts as if &ic=1 && $sc=1
-- Weighting is done by the filter
- tlib#agent#Input(): Consume <esc> when aborting input()
- INCOMPATIBLE CHANGE: Changed eligible values of g:tlib_inputlist_match
to "cnf", "cnfd", "seq" and "fuzzy"
- NEW: tlib#buffer#KeepCursorPosition()
- tlib#buffer#InsertText(): Take care of the extra line when appending
text to an empty buffer.
0.29
- tlib#string#Strip(): Strip also control characters (newlines etc.)
- tlib#rx#Suffixes(): 'suffixes' as Regexp
- World#RestoreOrigin(): Don't assume &splitbelow
0.30
- World#RestoreOrigin(): Don't assume &splitright
0.31
- :TRequire command
-tlib#input#List: For i-type list views, make sure agents are called
with the base indices.
0.32
- tlib#agent#Exit: explicitly return empty value (as a consequence,
pressing <esc> when browsing an index-list, returns 0 and not "")
- tlib#signs
- tlib#input#List: set local statusline
0.33
- Don't reset statusline
- Don't use fnamemodify() to split filenames (for performance reasons)
- scratch: Set ft after setting up scratch options
- tlib#map#PumAccept(key)
0.34
- tlib#buffer#HighlightLine(line): call tlib#autocmdgroup#Init()
(reported by Sergey Khorev)
0.35
- tlib#input#EditList(): return the list if the user presses esc
0.36
- Display a message when the filter is for whatever reason invalid
- Removed tlib#paragraph#Delete()
- New: tlib#paragraph#Define(), tlib#textobjects#StandardParagraph()
- Try to speed up list display (a rewrite of World.DisplayList() etc. is
required)
0.37
- g:tlib_inputlist_livesearch_threshold defaults to 1000
- tlib#World: optional scratch_pos field
- tlib#input#List: By default <m-NUMBER> selects by number but NUMBER is
interpreted as string
- tlib#date
- TTimeCommand
0.38
- tlib#World#Resize: set winfix{height|width}
0.39
- g:tlib#cache#dont_purge
- tlib#vim#RestoreWindow()
- tlib#ballon#...()
0.40
- tlib#agent#ViewFile: Use split/sbuffer if nohidden && modified
- tlib#buffer#GetList(): order by "basename"
version: "0.41"
- World.UseScratch(): keepalt
- Really include balloon.vim
MD5 checksum: 3fcbc4f7556f5378d39622e62ab8f379
version: "0.42"
- tlib#input#List: <s-space> inserts a *-like wildcard (represented as "__")
- Check if a cache file cannot be created because a directory of the same name exists (display a message if so)
- tlib#cache#Filename: Removed check if a directory of the same name exists (due to inconsistent use)
- Minor improvements related to buffer handling (scratch_split)
- .gitignore
- docs (thanks to blueyed)
- There is no "edit" answer possibility.
- Fix first purge: do nothing if no timestamp file.
- g:tlib_pick_single_item
- Removed pick_single_item. Changed the default behavour when a list has only 1 item. See doc for g:tlib_pick_last_item.
- Updated help for tlib#input#List(); help_extra attribute
- EXPERIMENTAL: cache_var, restore_from_cache, on_leave properties; #Initialize(), #Leave()
- added tlib#cmd#BrowseOutputWithCallback function and :TBrowseScriptnames command
- tlib#cmd#BrowseOutputWithCallback function and :TBrowseScriptnames command documentation
- s:prototype.Initialize(): unlet self.cache_var after restoring values
- tlib#input#List: filter-specific help
- Removed the seq filter (use cnfd or fuzzy instead)
- tlib#input#List: temp_prompt (for help message)
MD5 checksum: aa8b5a4602235cc1a5bc9ee45d801b81
version: "0.42"
- g:tlib#cache#silent: don't display messages when purging the cache (fixes #9)
- Changed message when deleting directories in the cache.
- g:tlib#input#use_popup: Don't rely on has('menu') but also check for gtk & win gui (fixes #10)
- debug
- tlib#input#ListW(): Didn't return a list when type == "m"
- docs (solves #11)
MD5 checksum: aa8b5a4602235cc1a5bc9ee45d801b81
version: "0.45"
- fuzzy mode: prototype.highlight defaults to g:tlib_inputlist_higroup
- tlib#scratch: Use noautocmd
- tlib#input#ListW(): Use world.RestoreOrigin() instead of tlib#win#SetLayout(world.winview)
- tlib#input#ListW(): Revert to tlib#win#SetLayout(world.winview)
- tlib#cmd#OutputAsList(): Also save output in g:tlib#cmd#last_output
- tlib#agent#Suspend(): Resume on BufEnter
- tlib#input#Resume(): Make sure we are in the right buffer
- tlib#agent#Suspend(): Use only BufEnter event to trigger a Resume
- tlib#input#ListW(): When redisplaying a list, make sure prefix > 0
- tlib#vcs: Access vcs (initially only git is supported)
- tlib#vcs: improved
- tlib#persistent: Persistent data file names
- tlib#file#With(): Trigger BufRead autocommands
- Duplicate help tags (fixes #13)
- Make sure scrolloff is 0 while viewing the list (fixes https://github.com/tomtom/vikitasks_vim/issues/2)
MD5 checksum: 0af19ebc0e424727a598a988fdc90f4e
- Support for tinykeymap (move paragraph)
- Moved para_move to autoload/tinykeymap/map
- tlib#vcs: some "diff" commands were defined as "ls"; updated hg def; %s is optional
MD5 checksum: f2f2fe0893e75bb9423c1ddcd01f38f6
version: "0.46"
- tlib#input#List: optimizations
- Prepare for multi-mode maps
- tlib#input#List: cnfx is new default filter
- Filters: minor changes to how the pattern is displayed
- g:tlib#input#format_filename: alternative method for formatting filenames
- tlib#input#List: allow multiple keymaps / modes
- Handle rezise events
- Don't initialize the same window twice
- Minor optimizations to how help is displayed
- Handle VimResize event per buffer
- Improve display of filenames & highlighting
- Filename highlighter: set Highlight_filename()
- RunStateHandlers(): set world variable
- Optimize help display
MD5 checksum: e3652927722bdc51935eb1a04238546b
version: "1.00"
- Set g:tlib_inputlist_and to ' ' again
- g:tlib#input#filename_max_width: maximum display width of filenames
- tlib#input#List: <s-esc>, <f10>: run command by name
MD5 checksum: a42f90275cdbe9f7d92cac61b884a2d1
version: "1.01"
- #UseInputListScratch(): Make sure the TLib autogroup was created (fixes #14)
MD5 checksum: 5a6da7fc99c7fc7584e8fc2f7bf86fe4
version: "1.02"
- tlib#cache#Value(cfile, generator, ftime, ...): cache value & check timestamp
- Replaced g:tlib#cache#silent with g:tlib#cache#verbosity
- FormatFilenames: improved handling of utf8 characters
- tlib#persistent#Value()
- tlib#input#List: Allow filename indiactors defined by the caller
- Custom filename_indicators are displayed after (and clearly separted from) the standard indicators
- Check the return value of an unknown_key agent
- Format filename = "l": Allow ".." as start of a directory name
- Format filename = "l": If the filename is just a filename's tail, display it on both sides
- Set g:tlib_filename_sep to "\" on Windows (again)
- g:tlib#cache#max_filename: If the cache filename is longer than N characters, use |pathshorten()|.
MD5 checksum: b64ce6764f39f40bfc95f3916bbb0057
version: "1.04"
version: "1.05"
- tlib#hash: Adler32 & CRC32 (using zlib via ruby) algorithms
- tlib#cache#Filename(): If the cache filename is too long, add the Adler32 checksum to the shortened path
- tlib#cache#Filename(): Use tlib#hash#Adler32() only if the or() function exists
- tlib#hash#Adler32(): Raise error, if or() doesn't exist
- tlib#hash#CRC32(): Alternative implementation of crc32 (doesn't work yet, thus currently disabled)
- tlib#bitwise: Bitwise operations for older versions of vim
- tlib#number: Base conversion
- tlib#input#ListW(): Handle mouse clicks more correctly
- tlib#bitwise#Num2Bits(): Supports returning floats
- tlib#hash#CRC32(): Alternative implementation of crc32 (doesn't work yet)
- tlib#hash#CRC32(): Re-enable ruby version
- tlib#hash#CRC32B(): Implementation of CRC32B checksum in vimscript (used only if +ruby isn't available)
- tlib#hash#CRC32B(): vim version: cache the crc table
- tlib#cache#Filename(): Use tlib#hash#CRC32B(file) instead of not Adler32 for filenames too long
- tlib#hash#CRC32B(): ruby version: return upper case hex value
- g:tlib#hash#use_crc32: define which crc32b version should be used
- Moved spec files from vimtlib to tlib_vim
- tlib#bitwise#Add() and tlib#bitwise#Sub()
- tlib#file#Relative(): Wrong results for filenames that don't exist
- Implementation of hash#Adler32 for earlier vim versions; g:tlib#hash#use_adler32
- tlib#cache#Filename(): Use adler32 again
- addon-info
- tlib#file#Absolute(): remove redundant "." parts in full filename
- win32: Fix moving window when using :vertical for tlib#inpu#List()
- tlib#cache#Filename(): Don't create wrong directory if the cache filename is too long
- tlib#file#Join(): if strip_slashes, also strip redundant (back)slashes
- tlib#input#ListW(): Always set post_keys variable
- tlib#file#With(): escape backslashes
- tlib#cmd#OutputAsList(): Support for nesting
- tlib#dir#NativeName(dirname)
MD5 checksum: 493f9beca44374de386f20d1613155e3
- Rename g:tlib_debug to g:tlib#debug
- Renamed g:tlib_sortprefs_threshold to g:tlib#input#sortprefs_threshold
- Renamed g:tlib#input#livesearch_threshold
- Renamed g:tlib_inputlist_match to g:tlib#input#filter_mode
- Renamed g:tlib_inputlist_higroup to g:tlib#input#higroup
- Renamed g:tlib#debug
- Moved g:tlib_pick_last_item
- Renamed g:tlib#input#and, g:tlib#input#or, g:tlib#input#not
- Moved g:tlib_numeric_chars to autoload/tlib/input.vim
- Renamed g:tlib#input#keyagents_InputList_s, g:tlib#input#keyagents_InputList_m, g:tlib#input#handlers_EditList
- Moved g:tlib_inputlist_pct, g:tlib_inputlist_width_filename, g:tlib_inputlist_filename_indicators, g:tlib_inputlist_shortmessage to autoload/tlib/World.vim
- Renamed tlib#input#pick_last_item (2)
- prototype.SelectItemsByNames()
- filtered_items: Restricted view
- prototype.PrintLines()
- Restricted view (2)
- Moved g:tlib_scroll_lines to autoload/tlib/agent.vim
- prototype.PrintLines() (2)
- tlib#input: Improved handling of popup menu (allows submenu)
- tlib#input: Allow mods in keys
- Moved g:tlib_scratch_pos to autoload/tlib/scratch.vim
- Moved g:tlib_tags_extra, g:tlib_tag_substitute to autoload/tlib/tag.vim
- tlib#agent#CompleteAgentNames(): Respect Arglead
- Move g:tlib_viewline_position to autoload/tlib/buffer.vim
- Move g:tlib_cache to autoload/tlib/cache.vim
- Renamed g:tlib_filename_sep to g:tlib#dir#sep
- prototype.UseScratch(): Set b:tlib_world
- tlib#input: f9 toggles resticted view
- tlib#input: next_agent, next_eval
- tlib#input: Revised use of the popup menu
- tlib#input: Disable popup menu for gui_gtk
- tlib#input: Re-enabled the popup menu for gtk gui
- tlib#input: FIX popup menu on Windows
- Renamed g:tlib_numeric_chars to g:tlib#input#numeric_chars (disabled per-buffer values) (fixes #35)
- Improve scratch list
- New: tlib#grep
- Merge branch 'master' of https://github.com/bruno-/tlib_vim into pull16
- g:tlib_scratch_hidden: Configure how to "hide" the scratch buffer
- tlib#grep#Do: don't escape "*" in patterns
- Optimize use of visible scratch buffers
- World.scratch_hidden parameter
- scratch: Always use keepalt & keepjumps
MD5 checksum: 2e40449c47dc606ccef57aa0b1e22e8e
version: "1.06"
version: "1.07"
- Help template
- prototype.Highlight_filename(): Use matchstr() instead of fnamemodify()
- Display buffer-related filename indicators only if g:tlib_inputlist_filename_indicators is true
- tlib#file#Join(): strip_slashes defaults to 1
MD5 checksum: 6c8fa96fd3747be05df848ee93dd789b
version: "1.08"
- list#input: Improved support for file indicators (closes #17)
- tlib#char#Get(): Optionally, also return mod
- tlib#input#ListW: Use #DisplayFormat(world.list)
- Renamed cnfx filter to glob & minor filter-related enhancements
- list#input: Make help available as command; help cannot be called via ?
- list#input: Improved help message
- list#input: Support Home & End keys
- list#input: Added glob filter
- tlib#agent#ShowInfo: Show full filename
- tlib#cmd#BrowseOutputWithCallback: Support calling callback with multiple results
- tlib#cmd#ParseScriptname: Properly parse results from :scriptnames
- tlib#tab#Set()
- Prepare for proper handling of scratch_split == -1
- tlib#vim#CopyFunction()
- tlib#cache#Value(): If generator is empty, use the optional argument as start value
- tlib#persistent#Get() refers to tlib#cache#Get()
MD5 checksum: 459ec620168d1ae9b18c69eb3f991832
- tlib#cache#Filename(): Use sha256() for VIM >= 7.4
- tlib#cache#Value(): Undo previous hack
- tlib#list#Uniq(): option to remove empty values
- tlib#cache#MTime(); tlib#persistent#Save() calls tlib#cache#Save()
- tlib#input#ListW: Temporarily set noshowmode
- tlib#list#Uniq(): Fix handling of empty items
- lis picker: Remove <C-Space> from help
- tlib#list#Uniq(): Implementation based on syntastic#util#unique(list) by scrooloose
MD5 checksum: b5fb4107d63930c2c8b1f0f6b3a7ff07
version: "1.09"
- tlib#cache#Filename(): Use sha256() for VIM >= 7.4
- tlib#cache#Value(): Undo previous hack
- tlib#list#Uniq(): option to remove empty values
- tlib#cache#MTime(); tlib#persistent#Save() calls tlib#cache#Save()
- tlib#input#ListW: Temporarily set noshowmode
- tlib#list#Uniq(): Fix handling of empty items
- lis picker: Remove <C-Space> from help
- tlib#list#Uniq(): Implementation based on syntastic#util#unique(list) by scrooloose
MD5 checksum: b5fb4107d63930c2c8b1f0f6b3a7ff07
version: "1.09"
- tlib#string#Chomp: Optional argument: max number of chars that should be removed
MD5 checksum: 8c1b94e25045580874e2f892d509291b
version: "1.10"
- tlib#vcs#FindVCS(filename): Wrong parameters to fnamemodifiy if filename is a directory
- Some system-related functions (e.g. facilitate use of cygwin tools)
- tlib#arg#StringAsKeyArgsEqual(), tlib#arg#StringAsKeyArgs(): Support "key=val" type argument lists
- tlib#vcs#Executable()
- scripts/create_crc_table.rb
- tlib#var#Get(): For namespaces other than global, replace "#" with "_"
MD5 checksum: 4a33f2f23e1fc6600b32e7f8323e001e
version: "1.11"
- tlib#list#ToDictionary()
- tlib#dir#CanonicName(): Use tlib#file#Canonic()
- tlib#file#Canonic()
MD5 checksum: 7995ab58f31eb6673d20deab8761838e
version: "1.12"
- SetInitialFilter(): Use deepcopy()
- tlib#var#List(): use keys(namespace) for newer versions of vim
- g:tlib#input#user_shortcuts (not functional yet)
- tlib#input#List: state "picked"
- UseInputListScratch(): Allow customization via self.index_next_syntax
- tlib#cmd#Capture()
- Facilitate customization of key agents via g:tlib_extend_keyagents_InputList_s, g:tlib_extend_keyagents_InputList_m
MD5 checksum: 7dd8b17a1a5b555df979381dcbd4c9aa
version: "1.13"
- SetInitialFilter(): Use deepcopy()
- tlib#var#List(): use keys(namespace) for newer versions of vim
- g:tlib#input#user_shortcuts (not functional yet)
- tlib#input#List: state "picked"
- UseInputListScratch(): Allow customization via self.index_next_syntax
- tlib#cmd#Capture()
- Facilitate customization of key agents via g:tlib_extend_keyagents_InputList_s, g:tlib_extend_keyagents_InputList_m
MD5 checksum: 7dd8b17a1a5b555df979381dcbd4c9aa
version: "1.13"
version: "1.14"
- FIX #18: Make sure the scratch isn't readonly
- FIX: display filter (properly handle backslashes)
- Remove loaded_* guard from autoload files
- tlib#notify#Echo(): minor changes
- tlib#file#Edit() (used by tlib#agent#ViewFile)
- tlib#buffer#GetList(): Buffer numbers are converted to numbers
- tlib#sys: Change order of functions (move tlib#sys#IsCygwinBin to the (possibly FIX #19)
- g:tlib#sys#check_cygpath: Call tlib#sys#IsExecutable('cygpath', 1) (possibly FIX #19)
MD5 checksum: 2cf6386218736a2d09db43c8e751e5a4
version: "1.15"
- tlib#file#Join(): New optional argument: maybe_absolute Drop preceding parts if a part looks like an absolute filename
- tlib#sys#Open(), tlib#sys#IsSpecial() (moved from viki)
- tlib#list#Uniq(): Handle hetergenous lists
- FIX #21: duplicate help tag
- NEW tlib#dictionary#Rev()
- tlib#input#List(): Use <Tab> to complete current word
- NEW tlib#arg#GetOpts(); ENH tlib#arg#StringAsKeyArgsEqual()
- cache: Allow for in memory cache
- NEW tlib#eval#Extend()
- Move qfl/loclist browser from trag to tlib
- FIX tlib#eval#Extend()
- Simplify tlib#eval#Extend()
- World.index_next_syntax may be a dict
- tlib#qfl#QflList: Use copy()
- tlib#arg#GetOpts: Handle exit code
MD5 checksum: 13fd8b0e4ba9cd932c57fc40ac3f641f
version: "1.15"
- tlib#file#Join(): New optional argument: maybe_absolute Drop preceding parts if a part looks like an absolute filename
- tlib#sys#Open(), tlib#sys#IsSpecial() (moved from viki)
- tlib#list#Uniq(): Handle hetergenous lists
- FIX #21: duplicate help tag
- NEW tlib#dictionary#Rev()
- tlib#input#List(): Use <Tab> to complete current word
- NEW tlib#arg#GetOpts(); ENH tlib#arg#StringAsKeyArgsEqual()
- cache: Allow for in memory cache
- NEW tlib#eval#Extend()
- Move qfl/loclist browser from trag to tlib
- FIX tlib#eval#Extend()
- Simplify tlib#eval#Extend()
- World.index_next_syntax may be a dict
- tlib#qfl#QflList: Use copy()
- tlib#arg#GetOpts: Handle exit code
MD5 checksum: 13fd8b0e4ba9cd932c57fc40ac3f641f
- tlib#arg#GetOpts: Handle short options
- tlib#arg: support short flags & facilitate completion
- NEW :TLibTrace
- tlib#sys#system_browser: FIX XDG string
- NEW tlib#sys#SystemInDir() (used by tlib#vcs#Ls)
- tlib#agent#Complete: improve fltrx
- Remove tlib#arg#Key(), :TKeyArg
- Move :TRequire, :TTimeCommand to macros/tlib.vim
- NEW tlib#cmd#TBrowseScriptnames()
- TScratch: use empty('<bang>')
- NEW :TLibTrace
- tlib#qfl: FIX TTagedFilesFilename regexp
- Remove tlib#arg#Key()
- tlib#buffer#InsertText(): Don't use TKeyArg
- tlib#eval#Extend: don't assign value
- NEW :TLibTrace, tlib#trace (was tlib#debug)
- NEW tlib#string#SplitCommaList()
- NEW tlib#time#FormatNow()
- tlib#arg#GetOpts: selectively disable "long", "short" flags
- tlib#arg#CComplete(): Support values completion (complete_customlist field)
- NEW tlib#date#Shift()
- tlib#qfl#Balloon(): Handle items with no bufnr
- NEW tlib#file#Glob, tlib#file#Globpath
- tlib#progressbar#Display(): optional "always" argument
- tlib#vcs#GitLsPostprocess(): Try to handle encoded filenames from git ls-files
- tlib#vcs#GitLsPostprocess: Eval only \ddd substrings
- FIX #22: duplicate tag
- tlib#buffer: Use 2match instead of 3match (incompatibility with matchparen)
- FIX #23: duplicate help tag
- tlib#string#SplitCommaList: optional "sep" argument
- Rename TLibTrace -> Tlibtrace; NEW Tlibtraceset command
- Rename s:SetSyntax -> tlib#qfl#SetSyntax
- mv tlib#rx#Convert to incubator
MD5 checksum: f3656fb35b7b3033084d6c5e504aca61
version: "1.16"
- tlib#input#List: #ReduceFilter: make sure the regexp is valid
- TTimeCommand -> Ttimecommand
- tlib#eval#Extend: mode argument for expand() compatibility
- tlib#input#List: Key handlers can have additional arguments
- tlib#qfl#AgentWithSelected: Set world
- prototype.UseInputListScratch: Run tlib_UseInputListScratch hook earlier
- tlib#qfl#AgentWithSelected: typo
- tlib#arg#GetOpts: type conversion (comma-separated lists etc.)
- tlib#arg: validators
- NEW tlib#date#IsDate()
- tlib#balloon#Remove: Unset &ballooneval, &balloonexpr
- NEW tlib#balloon#Expand()
- NEW tlib#date#Format()
- FIX tlib#date#Shift(..., "+Xm") for months
- NEW tlib#trace#Backtrace()
- NEW tlib#type#Is(), tlib#type#Are(), tlib#type#Has(), tlib#type#Have()
- NEW :Tlibassert
MD5 checksum: 3c4125a28ff1860accd254846651c251
version: "1.17"
- tlib#input#List: #ReduceFilter: make sure the regexp is valid
- TTimeCommand -> Ttimecommand
- tlib#eval#Extend: mode argument for expand() compatibility
- tlib#input#List: Key handlers can have additional arguments
- tlib#qfl#AgentWithSelected: Set world
- prototype.UseInputListScratch: Run tlib_UseInputListScratch hook earlier
- tlib#qfl#AgentWithSelected: typo
- tlib#arg#GetOpts: type conversion (comma-separated lists etc.)
- tlib#arg: validators
- NEW tlib#date#IsDate()
- tlib#balloon#Remove: Unset &ballooneval, &balloonexpr
- NEW tlib#balloon#Expand()
- NEW tlib#date#Format()
- FIX tlib#date#Shift(..., "+Xm") for months
- NEW tlib#trace#Backtrace()
- NEW tlib#type#Is(), tlib#type#Are(), tlib#type#Has(), tlib#type#Have()
- NEW :Tlibassert
MD5 checksum: 3c4125a28ff1860accd254846651c251
version: "1.17"
- tlib#input#List: #ReduceFilter: make sure the regexp is valid
- TTimeCommand -> Ttimecommand
- tlib#eval#Extend: mode argument for expand() compatibility
- tlib#input#List: Key handlers can have additional arguments
- tlib#qfl#AgentWithSelected: Set world
- prototype.UseInputListScratch: Run tlib_UseInputListScratch hook earlier
- tlib#qfl#AgentWithSelected: typo
- tlib#arg#GetOpts: type conversion (comma-separated lists etc.)
- tlib#arg: validators
- NEW tlib#date#IsDate()
- tlib#balloon#Remove: Unset &ballooneval, &balloonexpr
- NEW tlib#balloon#Expand()
- NEW tlib#date#Format()
- FIX tlib#date#Shift(..., "+Xm") for months
- NEW tlib#trace#Backtrace()
- NEW tlib#type#Is(), tlib#type#Are(), tlib#type#Has(), tlib#type#Have()
- NEW :Tlibassert
MD5 checksum: 3c4125a28ff1860accd254846651c251
version: "1.17"
- tlib#input#List: #ReduceFilter: make sure the regexp is valid
- TTimeCommand -> Ttimecommand
- tlib#eval#Extend: mode argument for expand() compatibility
- tlib#input#List: Key handlers can have additional arguments
- tlib#qfl#AgentWithSelected: Set world
- prototype.UseInputListScratch: Run tlib_UseInputListScratch hook earlier
- tlib#qfl#AgentWithSelected: typo
- tlib#arg#GetOpts: type conversion (comma-separated lists etc.)
- tlib#arg: validators
- NEW tlib#date#IsDate()
- tlib#balloon#Remove: Unset &ballooneval, &balloonexpr
- NEW tlib#balloon#Expand()
- NEW tlib#date#Format()
- FIX tlib#date#Shift(..., "+Xm") for months
- NEW tlib#trace#Backtrace()
- NEW tlib#type#Is(), tlib#type#Are(), tlib#type#Has(), tlib#type#Have()
- NEW :Tlibassert
MD5 checksum: 3c4125a28ff1860accd254846651c251
version: "1.17"
- tlib#arg: Completion for comma-separated lists
- Use "silent cd"
- NEW tlib#type#DefSchema(); FIX tlib#type#Has()
- tlib#cache#Value(): minor change
- tlib#date#IsDate() also checks whether the date is valid
- ! tlib#sys#Open(): escape special chars only once
- tlib#trace#Print: Allow for strings
- :Tlibtrace, :Tlibtraceset, :Tlibassert remove `-bar`
- NEW :Tlibtype (type/schema assertions); tlib#type#Is() also accepts schemas as "types"
- tlib#dir#CD(): Use haslocaldir()
- tlib#qfl#AgentGotoQFE: Don't use wincmd w
- NEW tlib#string#Input()
- FIX g:tlib#sys#system_rx; add OpenOffice exensions to g:tlib#sys#special_suffixes
- NEW tlib#selection#GetSelection()
- tlib#date#Shift(): Fix "Xm", ++specs
- tlib#trace#Set: FIX Properly handly "-label"
MD5 checksum: c3a1fe7d3cd86becbd3f7b0ba7ae9cd8
version: "1.19"
version: "1.20"
- tlib#arg: Completion for comma-separated lists
- Use "silent cd"
- NEW tlib#type#DefSchema(); FIX tlib#type#Has()
- tlib#cache#Value(): minor change
- tlib#date#IsDate() also checks whether the date is valid
- ! tlib#sys#Open(): escape special chars only once
- tlib#trace#Print: Allow for strings
- :Tlibtrace, :Tlibtraceset, :Tlibassert remove `-bar`
- NEW :Tlibtype (type/schema assertions); tlib#type#Is() also accepts schemas as "types"
- tlib#dir#CD(): Use haslocaldir()
- tlib#qfl#AgentGotoQFE: Don't use wincmd w
- NEW tlib#string#Input()
- FIX g:tlib#sys#system_rx; add OpenOffice exensions to g:tlib#sys#special_suffixes
- NEW tlib#selection#GetSelection()
- tlib#date#Shift(): Fix "Xm", ++specs
- tlib#trace#Set: FIX Properly handly "-label"
MD5 checksum: c919e0782931a8c628c6996903f989d3
- tlib#date#Shift(): Support for business days 'Nb'
- tlib#list#Uniq: Properly handle empty strings
- tlib#trace: Use g:tlib#trace#printer and tlib#trace#Printer_{printer}
- tlib#dictionary#Rev: Optional argument `opts = {}`; properly handle empty values etc.
- NEW g:tlib#trace#hl
- NEW spec/dictionary.vim
- tlib#agent#CompleteAgentNames: case insensitive
- tlib#arg#CComplete: --[no-]debug option
- tlib#date#Format: use localtime() if no arg is provided
- NEW tlib#file#IsAbsolute
- NEW tlib#notify#PrintError()
- tlib#trace#Print: FIX s/exec/call/
- tlib#type#Is() match full type name
- NEW tlib#string#MatchAll()
- Tlibtraceset, tlib#trace#Set(): If no `+` or `-` is prepended, assume `+`.
- tlib#list#Input: fix highlighting for filenames
- tlib#input#ListW: use world.CloseScratch(1)
- tlib#agent#ViewFile: Ignore errors in :exec back
- NEW tlib#agent#EditFileInWindow()
- :Tlibtraceset uses tlib#arg#GetOpts(), i.e. you can set the log file more easily
MD5 checksum: 20a48e225f32b9f58808096a5377af04
version: "1.22"
- tlib#date#Shift(): Support for business days 'Nb'
- tlib#list#Uniq: Properly handle empty strings
- tlib#trace: Use g:tlib#trace#printer and tlib#trace#Printer_{printer}
- tlib#dictionary#Rev: Optional argument `opts = {}`; properly handle empty values etc.
- NEW g:tlib#trace#hl
- NEW spec/dictionary.vim
- tlib#agent#CompleteAgentNames: case insensitive
- tlib#arg#CComplete: --[no-]debug option
- tlib#date#Format: use localtime() if no arg is provided
- NEW tlib#file#IsAbsolute
- NEW tlib#notify#PrintError()
- tlib#trace#Print: FIX s/exec/call/
- tlib#type#Is() match full type name
- NEW tlib#string#MatchAll()
- Tlibtraceset, tlib#trace#Set(): If no `+` or `-` is prepended, assume `+`.
- tlib#list#Input: fix highlighting for filenames
- tlib#input#ListW: use world.CloseScratch(1)
- tlib#agent#ViewFile: Ignore errors in :exec back
- NEW tlib#agent#EditFileInWindow()
- :Tlibtraceset uses tlib#arg#GetOpts(), i.e. you can set the log file more easily
MD5 checksum: 20a48e225f32b9f58808096a5377af04
version: "1.22"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"
- bump version 1.23 + misc changes
- FIX #24: avoid vim8 features
- tlib#win#GetID(): Alternative implementation sets a window variable to identify the window
- tlib#arg#GetOpts(): If args is a dict, return it
- tlib#file#FilterFiles(): FIX typo
- tlib#trace#Set: Experimental support for log levels
- tlib#input#ListW: make sure to close scratch when <= 1 items are in the list
- FIX #25: set win_nr again; fix some lint warnings
- tlib#progressbar#Init(): returns a statusline definition that can be used for restor
MD5 checksum: c4d6e018cbbd3b286a9b1648b748c1f3
version: "1.23"

View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View file

@ -0,0 +1,9 @@
{
"name" : "tlib",
"version" : "dev",
"author" : "Tom Link <micathom at gmail com>",
"maintainer" : "Tom Link <micathom at gmail com>",
"repository" : {"type": "git", "url": "git://github.com/tomtom/tlib_vim.git"},
"dependencies" : {},
"description" : "tlib -- A library of vim functions"
}

View file

@ -0,0 +1,12 @@
" para_move.vim
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2012-08-28.
" @Last Change: 2012-08-29.
" @Revision: 3
" Move paragraphs
call tinykeymap#EnterMap("para_move", "gp", {'name': 'move paragraph'})
call tinykeymap#Map("para_move", "j", "silent call tlib#paragraph#Move('Down', '<count>')")
call tinykeymap#Map("para_move", "k", "silent call tlib#paragraph#Move('Up', '<count>')")

View file

@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2008-11-25. " @Created: 2008-11-25.
" @Last Change: 2014-11-18. " @Last Change: 2017-09-28.
" @Revision: 0.0.114 " @Revision: 11.0.114
let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2 let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2
let s:prototype.highlight = g:tlib#input#higroup let s:prototype.highlight = g:tlib#input#higroup
@ -47,7 +47,8 @@ function! s:prototype.AssessName(world, name) dict "{{{3
" if flt =~# '\u' && a:name =~# flt " if flt =~# '\u' && a:name =~# flt
" let xa += 5 " let xa += 5
" endif " endif
let rel = 1.0 + 5.0 * len(flt) / len(a:name)
let xa += float2nr(rel)
if a:name =~ '\^'. flt if a:name =~ '\^'. flt
let xa += 4 let xa += 4
elseif a:name =~ '\<'. flt elseif a:name =~ '\<'. flt
@ -131,7 +132,7 @@ function! s:prototype.ReduceFrontFilter(world) dict "{{{3
if empty(str) if empty(str)
let filter = filter[0 : -2] let filter = filter[0 : -2]
else else
let filter = strpart(filter, 0, len(filter) - len(str)) let filter = tlib#string#Strcharpart(filter, 0, len(filter) - len(str))
endif endif
" TLogVAR str, filter " TLogVAR str, filter
let a:world.filter[0][0] = filter let a:world.filter[0][0] = filter

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,7 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 328 " @Revision: 362
" :filedoc: " :filedoc:
" Various agents for use as key handlers in tlib#input#List() " Various agents for use as key handlers in tlib#input#List()
@ -14,7 +13,8 @@ TLet g:tlib_scroll_lines = 10
" General {{{1 " General {{{1
function! tlib#agent#Exit(world, selected) "{{{3 function! tlib#agent#Exit(world, selected) "{{{3
if a:world.key_mode == 'default' Tlibtrace 'tlib', a:selected
if a:world.key_mode ==# 'default'
call a:world.CloseScratch() call a:world.CloseScratch()
let a:world.state = 'exit empty escape' let a:world.state = 'exit empty escape'
let a:world.list = [] let a:world.list = []
@ -29,6 +29,7 @@ endf
function! tlib#agent#CopyItems(world, selected) "{{{3 function! tlib#agent#CopyItems(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let @* = join(a:selected, "\n") let @* = join(a:selected, "\n")
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
return a:world return a:world
@ -39,6 +40,7 @@ endf
" InputList related {{{1 " InputList related {{{1
function! tlib#agent#PageUp(world, selected) "{{{3 function! tlib#agent#PageUp(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.offset -= (winheight(0) / 2) let a:world.offset -= (winheight(0) / 2)
let a:world.state = 'scroll' let a:world.state = 'scroll'
return a:world return a:world
@ -46,6 +48,7 @@ endf
function! tlib#agent#PageDown(world, selected) "{{{3 function! tlib#agent#PageDown(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.offset += (winheight(0) / 2) let a:world.offset += (winheight(0) / 2)
let a:world.state = 'scroll' let a:world.state = 'scroll'
return a:world return a:world
@ -53,6 +56,7 @@ endf
function! tlib#agent#Home(world, selected) "{{{3 function! tlib#agent#Home(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.prefidx = 1 let a:world.prefidx = 1
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
return a:world return a:world
@ -60,6 +64,7 @@ endf
function! tlib#agent#End(world, selected) "{{{3 function! tlib#agent#End(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.prefidx = len(a:world.list) let a:world.prefidx = len(a:world.list)
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
return a:world return a:world
@ -68,6 +73,7 @@ endf
function! tlib#agent#Up(world, selected, ...) "{{{3 function! tlib#agent#Up(world, selected, ...) "{{{3
TVarArg ['lines', 1] TVarArg ['lines', 1]
Tlibtrace 'tlib', a:selected, lines
let a:world.idx = '' let a:world.idx = ''
if a:world.prefidx > lines if a:world.prefidx > lines
let a:world.prefidx -= lines let a:world.prefidx -= lines
@ -81,6 +87,7 @@ endf
function! tlib#agent#Down(world, selected, ...) "{{{3 function! tlib#agent#Down(world, selected, ...) "{{{3
TVarArg ['lines', 1] TVarArg ['lines', 1]
Tlibtrace 'tlib', a:selected, lines
let a:world.idx = '' let a:world.idx = ''
if a:world.prefidx <= (len(a:world.list) - lines) if a:world.prefidx <= (len(a:world.list) - lines)
let a:world.prefidx += lines let a:world.prefidx += lines
@ -93,16 +100,19 @@ endf
function! tlib#agent#UpN(world, selected) "{{{3 function! tlib#agent#UpN(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
return tlib#agent#Up(a:world, a:selected, g:tlib_scroll_lines) return tlib#agent#Up(a:world, a:selected, g:tlib_scroll_lines)
endf endf
function! tlib#agent#DownN(world, selected) "{{{3 function! tlib#agent#DownN(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
return tlib#agent#Down(a:world, a:selected, g:tlib_scroll_lines) return tlib#agent#Down(a:world, a:selected, g:tlib_scroll_lines)
endf endf
function! tlib#agent#ShiftLeft(world, selected) "{{{3 function! tlib#agent#ShiftLeft(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.offset_horizontal -= (winwidth(0) / 2) let a:world.offset_horizontal -= (winwidth(0) / 2)
if a:world.offset_horizontal < 0 if a:world.offset_horizontal < 0
let a:world.offset_horizontal = 0 let a:world.offset_horizontal = 0
@ -113,6 +123,7 @@ endf
function! tlib#agent#ShiftRight(world, selected) "{{{3 function! tlib#agent#ShiftRight(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.offset_horizontal += (winwidth(0) / 2) let a:world.offset_horizontal += (winwidth(0) / 2)
let a:world.state = 'display shift' let a:world.state = 'display shift'
return a:world return a:world
@ -120,12 +131,14 @@ endf
function! tlib#agent#Reset(world, selected) "{{{3 function! tlib#agent#Reset(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.state = 'reset' let a:world.state = 'reset'
return a:world return a:world
endf endf
function! tlib#agent#ToggleRestrictView(world, selected) "{{{3 function! tlib#agent#ToggleRestrictView(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if empty(a:world.filtered_items) if empty(a:world.filtered_items)
return tlib#agent#RestrictView(a:world, a:selected) return tlib#agent#RestrictView(a:world, a:selected)
else else
@ -135,11 +148,11 @@ endf
function! tlib#agent#RestrictView(world, selected) "{{{3 function! tlib#agent#RestrictView(world, selected) "{{{3
" TLogVAR a:selected Tlibtrace 'tlib', a:selected
let filtered_items = map(copy(a:selected), 'index(a:world.base, v:val) + 1') let filtered_items = map(copy(a:selected), 'index(a:world.base, v:val) + 1')
" TLogVAR 1, filtered_items Tlibtrace 'tlib', 1, filtered_items
let filtered_items = filter(filtered_items, 'v:val > 0') let filtered_items = filter(filtered_items, 'v:val > 0')
" TLogVAR 2, filtered_items Tlibtrace 'tlib', 2, filtered_items
if !empty(filtered_items) if !empty(filtered_items)
let a:world.filtered_items = filtered_items let a:world.filtered_items = filtered_items
endif endif
@ -149,6 +162,7 @@ endf
function! tlib#agent#UnrestrictView(world, selected) "{{{3 function! tlib#agent#UnrestrictView(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.filtered_items = [] let a:world.filtered_items = []
let a:world.state = 'display' let a:world.state = 'display'
return a:world return a:world
@ -156,6 +170,7 @@ endf
function! tlib#agent#Input(world, selected) "{{{3 function! tlib#agent#Input(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let flt0 = a:world.CleanFilter(a:world.filter[0][0]) let flt0 = a:world.CleanFilter(a:world.filter[0][0])
let flt1 = input('Filter: ', flt0) let flt1 = input('Filter: ', flt0)
echo echo
@ -174,15 +189,16 @@ endf
" Suspend (see |tlib#agent#Suspend|) the input loop and jump back to the " Suspend (see |tlib#agent#Suspend|) the input loop and jump back to the
" original position in the parent window. " original position in the parent window.
function! tlib#agent#SuspendToParentWindow(world, selected) "{{{3 function! tlib#agent#SuspendToParentWindow(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let world = a:world let world = a:world
let winnr = world.win_wnr let wid = world.win_id
" TLogVAR winnr Tlibtrace 'tlib', wid
if winnr != -1 if wid != -1
let world = tlib#agent#Suspend(world, a:selected) let world = tlib#agent#Suspend(world, a:selected)
if world.state =~ '\<suspend\>' if world.state =~# '\<suspend\>'
call world.SwitchWindow('win') call world.SwitchWindow('win')
" let pos = world.cursor " let pos = world.cursor
" " TLogVAR pos " Tlibtrace 'tlib', pos
" if !empty(pos) " if !empty(pos)
" call setpos('.', pos) " call setpos('.', pos)
" endif " endif
@ -200,17 +216,18 @@ endf
" <cr> and <LeftMouse> will immediatly select the item under the cursor. " <cr> and <LeftMouse> will immediatly select the item under the cursor.
" < will select the item but the window will remain opened. " < will select the item but the window will remain opened.
function! tlib#agent#Suspend(world, selected) "{{{3 function! tlib#agent#Suspend(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if a:world.allow_suspend if a:world.allow_suspend
" TAssert IsNotEmpty(a:world.scratch) " TAssert IsNotEmpty(a:world.scratch)
" TLogDBG bufnr('%') " TLogDBG bufnr('%')
let br = tlib#buffer#Set(a:world.scratch) let br = tlib#buffer#Set(a:world.scratch)
" TLogVAR br, a:world.bufnr, a:world.scratch Tlibtrace 'tlib', br, a:world.bufnr, a:world.scratch
if bufnr('%') != a:world.scratch if bufnr('%') != a:world.scratch
echohl WarningMsg echohl WarningMsg
echom "tlib#agent#Suspend: Internal error: Not a scratch buffer:" bufname('%') echom "tlib#agent#Suspend: Internal error: Not a scratch buffer:" bufname('%')
echohl NONE echohl NONE
endif endif
" TLogVAR bufnr('%'), bufname('%'), a:world.scratch Tlibtrace 'tlib', bufnr('%'), bufname('%'), a:world.scratch
call tlib#autocmdgroup#Init() call tlib#autocmdgroup#Init()
exec 'autocmd TLib BufEnter <buffer='. a:world.scratch .'> call tlib#input#Resume("world", 0, '. a:world.scratch .')' exec 'autocmd TLib BufEnter <buffer='. a:world.scratch .'> call tlib#input#Resume("world", 0, '. a:world.scratch .')'
let b:tlib_world = a:world let b:tlib_world = a:world
@ -225,12 +242,14 @@ endf
function! tlib#agent#Help(world, selected) "{{{3 function! tlib#agent#Help(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.state = 'help' let a:world.state = 'help'
return a:world return a:world
endf endf
function! tlib#agent#OR(world, selected) "{{{3 function! tlib#agent#OR(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if !empty(a:world.filter[0]) if !empty(a:world.filter[0])
call insert(a:world.filter[0], '') call insert(a:world.filter[0], '')
endif endif
@ -240,6 +259,7 @@ endf
function! tlib#agent#AND(world, selected) "{{{3 function! tlib#agent#AND(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if !empty(a:world.filter[0]) if !empty(a:world.filter[0])
call insert(a:world.filter, ['']) call insert(a:world.filter, [''])
endif endif
@ -249,6 +269,7 @@ endf
function! tlib#agent#ReduceFilter(world, selected) "{{{3 function! tlib#agent#ReduceFilter(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.ReduceFilter() call a:world.ReduceFilter()
let a:world.offset = 1 let a:world.offset = 1
let a:world.state = 'display' let a:world.state = 'display'
@ -257,6 +278,7 @@ endf
function! tlib#agent#PopFilter(world, selected) "{{{3 function! tlib#agent#PopFilter(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.PopFilter() call a:world.PopFilter()
let a:world.offset = 1 let a:world.offset = 1
let a:world.state = 'display' let a:world.state = 'display'
@ -265,6 +287,7 @@ endf
function! tlib#agent#Debug(world, selected) "{{{3 function! tlib#agent#Debug(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
" echo string(world.state) " echo string(world.state)
echo string(a:world.filter) echo string(a:world.filter)
echo string(a:world.idx) echo string(a:world.idx)
@ -277,6 +300,7 @@ endf
function! tlib#agent#Select(world, selected) "{{{3 function! tlib#agent#Select(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.SelectItem('toggle', a:world.prefidx) call a:world.SelectItem('toggle', a:world.prefidx)
" let a:world.state = 'display keepcursor' " let a:world.state = 'display keepcursor'
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
@ -285,6 +309,7 @@ endf
function! tlib#agent#SelectUp(world, selected) "{{{3 function! tlib#agent#SelectUp(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.SelectItem('toggle', a:world.prefidx) call a:world.SelectItem('toggle', a:world.prefidx)
if a:world.prefidx > 1 if a:world.prefidx > 1
let a:world.prefidx -= 1 let a:world.prefidx -= 1
@ -295,6 +320,7 @@ endf
function! tlib#agent#SelectDown(world, selected) "{{{3 function! tlib#agent#SelectDown(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.SelectItem('toggle', a:world.prefidx) call a:world.SelectItem('toggle', a:world.prefidx)
if a:world.prefidx < len(a:world.list) if a:world.prefidx < len(a:world.list)
let a:world.prefidx += 1 let a:world.prefidx += 1
@ -305,6 +331,7 @@ endf
function! tlib#agent#SelectAll(world, selected) "{{{3 function! tlib#agent#SelectAll(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let listrange = range(1, len(a:world.list)) let listrange = range(1, len(a:world.list))
let mode = empty(filter(copy(listrange), 'index(a:world.sel_idx, a:world.GetBaseIdx(v:val)) == -1')) let mode = empty(filter(copy(listrange), 'index(a:world.sel_idx, a:world.GetBaseIdx(v:val)) == -1'))
\ ? 'toggle' : 'set' \ ? 'toggle' : 'set'
@ -317,6 +344,7 @@ endf
function! tlib#agent#ToggleStickyList(world, selected) "{{{3 function! tlib#agent#ToggleStickyList(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.sticky = !a:world.sticky let a:world.sticky = !a:world.sticky
let a:world.state = 'display keepcursor' let a:world.state = 'display keepcursor'
return a:world return a:world
@ -327,11 +355,11 @@ endf
" EditList related {{{1 " EditList related {{{1
function! tlib#agent#EditItem(world, selected) "{{{3 function! tlib#agent#EditItem(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let lidx = a:world.prefidx let lidx = a:world.prefidx
" TLogVAR lidx Tlibtrace 'tlib', lidx
" TLogVAR a:world.table
let bidx = a:world.GetBaseIdx(lidx) let bidx = a:world.GetBaseIdx(lidx)
" TLogVAR bidx Tlibtrace 'tlib', bidx
let item = a:world.GetBaseItem(bidx) let item = a:world.GetBaseItem(bidx)
let item = input(lidx .'@'. bidx .': ', item) let item = input(lidx .'@'. bidx .': ', item)
if item != '' if item != ''
@ -344,6 +372,7 @@ endf
" Insert a new item below the current one. " Insert a new item below the current one.
function! tlib#agent#NewItem(world, selected) "{{{3 function! tlib#agent#NewItem(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let basepi = a:world.GetBaseIdx(a:world.prefidx) let basepi = a:world.GetBaseIdx(a:world.prefidx)
let item = input('New item: ') let item = input('New item: ')
call insert(a:world.base, item, basepi) call insert(a:world.base, item, basepi)
@ -353,6 +382,7 @@ endf
function! tlib#agent#DeleteItems(world, selected) "{{{3 function! tlib#agent#DeleteItems(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let remove = copy(a:world.sel_idx) let remove = copy(a:world.sel_idx)
let basepi = a:world.GetBaseIdx(a:world.prefidx) let basepi = a:world.GetBaseIdx(a:world.prefidx)
if index(remove, basepi) == -1 if index(remove, basepi) == -1
@ -370,12 +400,14 @@ endf
function! tlib#agent#Cut(world, selected) "{{{3 function! tlib#agent#Cut(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let world = tlib#agent#Copy(a:world, a:selected) let world = tlib#agent#Copy(a:world, a:selected)
return tlib#agent#DeleteItems(world, a:selected) return tlib#agent#DeleteItems(world, a:selected)
endf endf
function! tlib#agent#Copy(world, selected) "{{{3 function! tlib#agent#Copy(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.clipboard = [] let a:world.clipboard = []
let bidxs = copy(a:world.sel_idx) let bidxs = copy(a:world.sel_idx)
call add(bidxs, a:world.GetBaseIdx(a:world.prefidx)) call add(bidxs, a:world.GetBaseIdx(a:world.prefidx))
@ -388,6 +420,7 @@ endf
function! tlib#agent#Paste(world, selected) "{{{3 function! tlib#agent#Paste(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if has_key(a:world, 'clipboard') if has_key(a:world, 'clipboard')
for e in reverse(copy(a:world.clipboard)) for e in reverse(copy(a:world.clipboard))
call insert(a:world.base, e, a:world.prefidx) call insert(a:world.base, e, a:world.prefidx)
@ -400,6 +433,7 @@ endf
function! tlib#agent#EditReturnValue(world, rv) "{{{3 function! tlib#agent#EditReturnValue(world, rv) "{{{3
Tlibtrace 'tlib', a:rv
return [a:world.state !~ '\<exit\>', a:world.base] return [a:world.state !~ '\<exit\>', a:world.base]
endf endf
@ -408,22 +442,15 @@ endf
" Files related {{{1 " Files related {{{1
function! tlib#agent#ViewFile(world, selected) "{{{3 function! tlib#agent#ViewFile(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if !empty(a:selected) if !empty(a:selected)
let back = a:world.SwitchWindow('win') let back = a:world.SwitchWindow('win')
" TLogVAR back Tlibtrace 'tlib', back
for filename in a:selected for filename in a:selected
call tlib#file#Edit(filename) call tlib#file#Edit(filename)
endfor endfor
" if !&hidden && &l:modified call a:world.SetOrigin(1)
" let cmd0 = 'split' silent! exec back
" let cmd1 = 'sbuffer'
" else
" let cmd0 = 'edit'
" let cmd1 = 'buffer'
" endif
" call tlib#file#With(cmd0, cmd1, a:selected, a:world)
" TLogVAR &filetype
exec back
let a:world.state = 'display' let a:world.state = 'display'
endif endif
return a:world return a:world
@ -431,41 +458,53 @@ endf
function! tlib#agent#EditFile(world, selected) "{{{3 function! tlib#agent#EditFile(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
return tlib#agent#Exit(tlib#agent#ViewFile(a:world, a:selected), a:selected) return tlib#agent#Exit(tlib#agent#ViewFile(a:world, a:selected), a:selected)
endf endf
function! tlib#agent#EditFileInSplit(world, selected) "{{{3 function! tlib#agent#EditFileInSplit(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.CloseScratch() call a:world.CloseScratch()
" call tlib#file#With('edit', 'buffer', a:selected[0:0], a:world) call tlib#file#With('split', 'sbuffer', a:selected, a:world, 1)
" call tlib#file#With('split', 'sbuffer', a:selected[1:-1], a:world) call a:world.SetOrigin(1)
call tlib#file#With('split', 'sbuffer', a:selected, a:world)
return tlib#agent#Exit(a:world, a:selected) return tlib#agent#Exit(a:world, a:selected)
endf endf
function! tlib#agent#EditFileInVSplit(world, selected) "{{{3 function! tlib#agent#EditFileInVSplit(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.CloseScratch() call a:world.CloseScratch()
" call tlib#file#With('edit', 'buffer', a:selected[0:0], a:world)
" call tlib#file#With('vertical split', 'vertical sbuffer', a:selected[1:-1], a:world)
let winpos = tlib#fixes#Winpos() let winpos = tlib#fixes#Winpos()
call tlib#file#With('vertical split', 'vertical sbuffer', a:selected, a:world) call tlib#file#With('vertical split', 'vertical sbuffer', a:selected, a:world, 1)
if !empty(winpos) if !empty(winpos)
exec winpos exec winpos
endif endif
call a:world.SetOrigin(1)
return tlib#agent#Exit(a:world, a:selected) return tlib#agent#Exit(a:world, a:selected)
endf endf
function! tlib#agent#EditFileInTab(world, selected) "{{{3 function! tlib#agent#EditFileInTab(world, selected) "{{{3
" TLogVAR a:selected Tlibtrace 'tlib', a:selected
call a:world.CloseScratch() call a:world.CloseScratch()
call tlib#file#With('tabedit', 'tab sbuffer', a:selected, a:world) call tlib#file#With('tabedit', 'tab sbuffer', a:selected, a:world, 1)
call a:world.SetOrigin(1)
return tlib#agent#Exit(a:world, a:selected)
endf
function! tlib#agent#EditFileInWindow(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
call a:world.CloseScratch()
call tlib#file#With('hide edit', 'hide buffer', a:selected, a:world, 1)
call a:world.SetOrigin(1)
return tlib#agent#Exit(a:world, a:selected) return tlib#agent#Exit(a:world, a:selected)
endf endf
function! tlib#agent#ToggleScrollbind(world, selected) "{{{3 function! tlib#agent#ToggleScrollbind(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.scrollbind = get(a:world, 'scrollbind') ? 0 : 1 let a:world.scrollbind = get(a:world, 'scrollbind') ? 0 : 1
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
return a:world return a:world
@ -473,6 +512,7 @@ endf
function! tlib#agent#ShowInfo(world, selected) function! tlib#agent#ShowInfo(world, selected)
Tlibtrace 'tlib', a:selected
let lines = [] let lines = []
for f in a:selected for f in a:selected
if filereadable(f) if filereadable(f)
@ -490,12 +530,30 @@ endf
" Buffer related {{{1 " Buffer related {{{1
function! tlib#agent#ViewBufferInWindow(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if !empty(a:selected)
let back = a:world.SwitchWindow('win')
Tlibtrace 'tlib', back
for bufname in a:selected
let cmd = &modified && !&hidden ? 'sbuffer' : 'buffer'
exec cmd fnameescape(bufname)
endfor
" exec back
endif
return tlib#agent#Exit(a:world, a:selected)
endf
function! tlib#agent#PreviewLine(world, selected) "{{{3 function! tlib#agent#PreviewLine(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let l = a:selected[0] let l = a:selected[0]
let ww = winnr() " let ww = winnr()
exec a:world.win_wnr .'wincmd w' let wid = tlib#win#GetID()
call tlib#agent#SuspendToParentWindow(a:world, a:selected)
call tlib#buffer#ViewLine(l, 1) call tlib#buffer#ViewLine(l, 1)
exec ww .'wincmd w' call tlib#win#GotoID(wid)
" exec ww .'wincmd w'
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
return a:world return a:world
endf endf
@ -504,24 +562,12 @@ endf
" If not called from the scratch, we assume/guess that we don't have to " If not called from the scratch, we assume/guess that we don't have to
" suspend the input-evaluation loop. " suspend the input-evaluation loop.
function! tlib#agent#GotoLine(world, selected) "{{{3 function! tlib#agent#GotoLine(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if !empty(a:selected) if !empty(a:selected)
" let l = a:selected[0]
" " TLogVAR l
" let back = a:world.SwitchWindow('win')
" " TLogVAR back
" " if a:world.win_wnr != winnr()
" " let world = tlib#agent#Suspend(a:world, a:selected)
" " exec a:world.win_wnr .'wincmd w'
" " endif
" call tlib#buffer#ViewLine(l)
" exec back
" let a:world.state = 'display'
let l = a:selected[0] let l = a:selected[0]
if a:world.win_wnr != winnr() if a:world.win_id != tlib#win#GetID()
let world = tlib#agent#Suspend(a:world, a:selected) let world = tlib#agent#Suspend(a:world, a:selected)
exec a:world.win_wnr .'wincmd w' call tlib#win#GotoID(a:world.win_id)
endif endif
call tlib#buffer#ViewLine(l, 1) call tlib#buffer#ViewLine(l, 1)
@ -531,6 +577,7 @@ endf
function! tlib#agent#DoAtLine(world, selected) "{{{3 function! tlib#agent#DoAtLine(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if !empty(a:selected) if !empty(a:selected)
let cmd = input('Command: ', '', 'command') let cmd = input('Command: ', '', 'command')
if !empty(cmd) if !empty(cmd)
@ -552,6 +599,7 @@ endf
function! tlib#agent#Wildcard(world, selected) "{{{3 function! tlib#agent#Wildcard(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
if !empty(a:world.filter[0]) if !empty(a:world.filter[0])
let rx_type = a:world.matcher.FilterRxPrefix() let rx_type = a:world.matcher.FilterRxPrefix()
let flt0 = a:world.CleanFilter(a:world.filter[0][0]) let flt0 = a:world.CleanFilter(a:world.filter[0][0])
@ -568,12 +616,14 @@ endf
function! tlib#agent#Null(world, selected) "{{{3 function! tlib#agent#Null(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
return a:world return a:world
endf endf
function! tlib#agent#ExecAgentByName(world, selected) "{{{3 function! tlib#agent#ExecAgentByName(world, selected) "{{{3
Tlibtrace 'tlib', a:selected
let s:agent_names_world = a:world let s:agent_names_world = a:world
let agent_names = {'Help': 'tlib#agent#Help'} let agent_names = {'Help': 'tlib#agent#Help'}
for def in values(a:world.key_map[a:world.key_mode]) for def in values(a:world.key_map[a:world.key_mode])
@ -583,11 +633,11 @@ function! tlib#agent#ExecAgentByName(world, selected) "{{{3
endfor endfor
let s:agent_names = sort(keys(agent_names)) let s:agent_names = sort(keys(agent_names))
let command = input('Command: ', '', 'customlist,tlib#agent#CompleteAgentNames') let command = input('Command: ', '', 'customlist,tlib#agent#CompleteAgentNames')
" TLogVAR command Tlibtrace 'tlib', command
if !has_key(agent_names, command) if !has_key(agent_names, command)
" TLogVAR command Tlibtrace 'tlib', command
silent! let matches = filter(keys(agent_names), 'v:val =~ command') silent! let matches = filter(keys(agent_names), 'v:val =~ command')
" TLogVAR matches Tlibtrace 'tlib', matches
if len(matches) == 1 if len(matches) == 1
let command = matches[0] let command = matches[0]
endif endif
@ -609,43 +659,45 @@ endf
function! tlib#agent#CompleteAgentNames(ArgLead, CmdLine, CursorPos) function! tlib#agent#CompleteAgentNames(ArgLead, CmdLine, CursorPos)
return filter(copy(s:agent_names), 'stridx(v:val, a:ArgLead) != -1') let arglead = tolower(a:Arglead)
return filter(copy(s:agent_names), 'stridx(tolower(v:val), arglead) != -1')
endf endf
function! tlib#agent#Complete(world, selected) abort "{{{3 function! tlib#agent#Complete(world, selected) abort "{{{3
Tlibtrace 'tlib', a:selected
let rxprefix = a:world.matcher.FilterRxPrefix() let rxprefix = a:world.matcher.FilterRxPrefix()
let flt = a:world.filter[0][0] let flt = a:world.filter[0][0]
" TLogVAR flt Tlibtrace 'tlib', flt
let fltrx = rxprefix . flt . '\m[^[:space:][:cntrl:][:punct:]<>*+?&~{}()\[\]\\/]\+' let fltrx = rxprefix . flt . '\m[^[:space:][:cntrl:][:punct:]<>*+?&~{}()\[\]\\/]\+'
let fltrx0 = '\m^' . fltrx let fltrx0 = '\m^' . fltrx
" TLogVAR fltrx, fltrx0 Tlibtrace 'tlib', fltrx, fltrx0
let words = {} let words = {}
for item in a:world.list for item in a:world.list
let parts = split(item, '\ze'. fltrx) let parts = split(item, '\ze'. fltrx)
" TLogVAR item, parts Tlibtrace 'tlib', item, parts
for part in parts for part in parts
let word = matchstr(part, fltrx0) let word = matchstr(part, fltrx0)
" TLogVAR part, word Tlibtrace 'tlib', part, word
if !empty(word) if !empty(word)
let words[word] = 1 let words[word] = 1
endif endif
endfor endfor
endfor endfor
" TLogVAR keys(words) Tlibtrace 'tlib', keys(words)
let completions = keys(words) let completions = keys(words)
" let completions = filter(keys(words), 'matchstr(v:val, fltrx0)') " let completions = filter(keys(words), 'matchstr(v:val, fltrx0)')
let completions = sort(completions, 's:SortCompletions') let completions = sort(completions, 's:SortCompletions')
let completions = tlib#list#Uniq(completions) let completions = tlib#list#Uniq(completions)
" TLogVAR 0, completions Tlibtrace 'tlib', 0, completions
while len(completions) > 1 while len(completions) > 1
let nchar = strwidth(completions[0]) - 1 let nchar = strwidth(completions[0]) - 1
let completions = map(completions, 'strpart(v:val, 0, nchar)') let completions = map(completions, 'tlib#string#Strcharpart(v:val, 0, nchar)')
" TLogVAR 'reduce', completions Tlibtrace 'tlib', 'reduce', completions
let completions = tlib#list#Uniq(completions) let completions = tlib#list#Uniq(completions)
" TLogVAR 'unique', len(completions), completions Tlibtrace 'tlib', 'unique', len(completions), completions
endwh endwh
" TLogVAR 9, completions Tlibtrace 'tlib', 9, completions
if empty(completions) if empty(completions)
let a:world.state = 'redisplay update' let a:world.state = 'redisplay update'
else else

View file

@ -1,8 +1,8 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2015-11-19. " @Last Change: 2017-09-28.
" @Revision: 251 " @Revision: 273
" :def: function! tlib#arg#Get(n, var, ?default="", ?test='') " :def: function! tlib#arg#Get(n, var, ?default="", ?test='')
@ -92,30 +92,34 @@ endf
" ['-ab', '--', '--foo', '--bar=BAR'] " ['-ab', '--', '--foo', '--bar=BAR']
" => {'a': 1, 'b': 1, '__rest__': ['--foo', '--bar=BAR']} " => {'a': 1, 'b': 1, '__rest__': ['--foo', '--bar=BAR']}
function! tlib#arg#GetOpts(args, ...) abort "{{{3 function! tlib#arg#GetOpts(args, ...) abort "{{{3
let throw = a:0 == 0 if type(a:args) == 4
TVarArg ['def', {}] reutrn a:args
" TLogVAR def else
let opts = {'__exit__': 0} let throw = a:0 == 0
for [key, vdef] in items(get(def, 'values', {})) TVarArg ['def', {}]
if has_key(vdef, 'default') " TLogVAR def
let opts[key] = vdef.default let opts = {'__exit__': 0}
endif for [key, vdef] in items(get(def, 'values', {}))
endfor if has_key(vdef, 'default')
let idx = 0 let opts[key] = vdef.default
for o in a:args
let [break, idx] = s:SetOpt(def, opts, idx, o)
if break == 1
break
elseif break == 2
if throw
throw 'tlib#arg#GetOpts: Show help'
else
let opts.__exit__ = 5
endif endif
endif endfor
endfor let idx = 0
let opts.__rest__ = a:args[idx : -1] for o in a:args
return opts let [break, idx] = s:SetOpt(def, opts, idx, o)
if break == 1
break
elseif break == 2
if throw
throw 'tlib#arg#GetOpts: Show help'
else
let opts.__exit__ = 5
endif
endif
endfor
let opts.__rest__ = a:args[idx : -1]
return opts
endif
endf endf
@ -147,7 +151,7 @@ function! s:SetOpt(def, opts, idx, opt) abort "{{{3
let default = get(vdef, 'default', '') let default = get(vdef, 'default', '')
let type = s:GetValueType(vdef) let type = s:GetValueType(vdef)
if default =~ '^-\?\d\+\%(\.\d\+\)$' if default =~ '^-\?\d\+\%(\.\d\+\)$'
if type == -1 if type == -1 || type == 6
let opt .= ' (flag)' let opt .= ' (flag)'
elseif type == 1 elseif type == 1
let opt .= '=INT' let opt .= '=INT'
@ -171,6 +175,11 @@ function! s:SetOpt(def, opts, idx, opt) abort "{{{3
endif endif
endif endif
let break = 2 let break = 2
elseif long && a:opt =~# '^--\%(no-\)\?debug$'
if has_key(a:def, 'trace')
let mod = a:opt =~# '--no-' ? '-' : '+'
exec 'Tlibtraceset' mod . a:def.trace
endif
elseif long && a:opt =~# '^--no-.\+' elseif long && a:opt =~# '^--no-.\+'
let key = matchstr(a:opt, '^--no-\zs.\+$') let key = matchstr(a:opt, '^--no-\zs.\+$')
let a:opts[key] = s:Validate(a:def, key, 0) let a:opts[key] = s:Validate(a:def, key, 0)
@ -267,12 +276,14 @@ function! tlib#arg#CComplete(def, ArgLead) abort "{{{3
" endif " endif
endif endif
if !empty(words) if !empty(words)
let lead = substitute(a:ArgLead, '^--\w\+=', '', '') let prefix = matchstr(a:ArgLead, '^--\w\+=\%([^,]\+,\s*\)*')
let lead = substitute(a:ArgLead, '^--\w\+=\%([^,]\+,\s*\)*', '', '')
" TLogVAR a:ArgLead, lead
if !empty(lead) if !empty(lead)
let nchar = len(lead) let nchar = len(lead)
call filter(words, 'strpart(v:val, 0, nchar) ==# lead') call filter(words, 'tlib#string#Strcharpart(v:val, 0, nchar) ==# lead')
endif endif
let words = map(words, '"--". opt ."=". v:val') let words = map(words, 'prefix . v:val')
return sort(words) return sort(words)
endif endif
endif endif
@ -294,9 +305,12 @@ function! tlib#arg#CComplete(def, ArgLead) abort "{{{3
endif endif
let cs['-'. name] = 1 let cs['-'. name] = 1
endfor endfor
if has_key(a:def, 'trace')
let cs['--debug'] = 1
endif
let nchar = len(a:ArgLead) let nchar = len(a:ArgLead)
if nchar > 0 if nchar > 0
call filter(cs, 'strpart(v:key, 0, nchar) ==# a:ArgLead') call filter(cs, 'tlib#string#Strcharpart(v:key, 0, nchar) ==# a:ArgLead')
endif endif
return sort(keys(cs)) return sort(keys(cs))
endf endf

View file

@ -1,21 +1,21 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: https://github.com/tomtom " @Website: https://github.com/tomtom
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2015-11-23 " @Last Change: 2017-02-22
" @Revision: 38 " @Revision: 42
" Enable tracing via |:Tlibassert|. " Enable tracing via |:Tlibassert|.
function! tlib#assert#Enable() abort "{{{3 function! tlib#assert#Enable() abort "{{{3
" :nodoc: " :nodoc:
command! -nargs=+ -bar Tlibassert call tlib#assert#Assert(expand('<sfile>'), <q-args>, [<args>]) command! -nargs=+ -bang Tlibassert call tlib#assert#Assert(expand('<sfile>'), <q-args>, [<args>])
endf endf
" Disable tracing via |:Tlibassert|. " Disable tracing via |:Tlibassert|.
function! tlib#assert#Disable() abort "{{{3 function! tlib#assert#Disable() abort "{{{3
" :nodoc: " :nodoc:
command! -nargs=+ -bang -bar Tlibassert : command! -nargs=+ -bang Tlibassert :
endf endf

View file

@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30. " @Created: 2007-06-30.
" @Last Change: 2015-11-06. " @Last Change: 2017-09-28.
" @Revision: 7.1.352 " @Revision: 12.1.352
" Where to display the line when using |tlib#buffer#ViewLine|. " Where to display the line when using |tlib#buffer#ViewLine|.
@ -15,19 +15,19 @@ TLet g:tlib_viewline_position = 'zz'
let s:bmru = [] let s:bmru = []
function! tlib#buffer#EnableMRU() "{{{3 function! tlib#buffer#EnableMRU() abort "{{{3
call tlib#autocmdgroup#Init() call tlib#autocmdgroup#Init()
autocmd TLib BufEnter * call s:BMRU_Push(bufnr('%')) autocmd TLib BufEnter * call s:BMRU_Push(bufnr('%'))
endf endf
function! tlib#buffer#DisableMRU() "{{{3 function! tlib#buffer#DisableMRU() abort "{{{3
call tlib#autocmdgroup#Init() call tlib#autocmdgroup#Init()
autocmd! TLib BufEnter autocmd! TLib BufEnter
endf endf
function! s:BMRU_Push(bnr) "{{{3 function! s:BMRU_Push(bnr) abort "{{{3
let i = index(s:bmru, a:bnr) let i = index(s:bmru, a:bnr)
if i >= 0 if i >= 0
call remove(s:bmru, i) call remove(s:bmru, i)
@ -36,7 +36,7 @@ function! s:BMRU_Push(bnr) "{{{3
endf endf
function! s:CompareBuffernameByBasename(a, b) "{{{3 function! s:CompareBuffernameByBasename(a, b) abort "{{{3
let rx = '"\zs.\{-}\ze" \+\S\+ \+\d\+$' let rx = '"\zs.\{-}\ze" \+\S\+ \+\d\+$'
let an = matchstr(a:a, rx) let an = matchstr(a:a, rx)
let an = fnamemodify(an, ':t') let an = fnamemodify(an, ':t')
@ -47,7 +47,7 @@ function! s:CompareBuffernameByBasename(a, b) "{{{3
endf endf
function! s:CompareBufferNrByMRU(a, b) "{{{3 function! s:CompareBufferNrByMRU(a, b) abort "{{{3
let an = matchstr(a:a, '\s*\zs\d\+\ze') let an = matchstr(a:a, '\s*\zs\d\+\ze')
let bn = matchstr(a:b, '\s*\zs\d\+\ze') let bn = matchstr(a:b, '\s*\zs\d\+\ze')
let ai = index(s:bmru, 0 + an) let ai = index(s:bmru, 0 + an)
@ -66,7 +66,7 @@ endf
" Set the buffer to buffer and return a command as string that can be " Set the buffer to buffer and return a command as string that can be
" evaluated by |:execute| in order to restore the original view. " evaluated by |:execute| in order to restore the original view.
function! tlib#buffer#Set(buffer) "{{{3 function! tlib#buffer#Set(buffer) abort "{{{3
let lazyredraw = &lazyredraw let lazyredraw = &lazyredraw
set lazyredraw set lazyredraw
try try
@ -91,12 +91,12 @@ function! tlib#buffer#Set(buffer) "{{{3
endf endf
" :def: function! tlib#buffer#Eval(buffer, code) " :def: function! tlib#buffer#Eval(buffer, code) abort
" Evaluate CODE in BUFFER. " Evaluate CODE in BUFFER.
" "
" EXAMPLES: > " EXAMPLES: >
" call tlib#buffer#Eval('foo.txt', 'echo b:bar') " call tlib#buffer#Eval('foo.txt', 'echo b:bar')
function! tlib#buffer#Eval(buffer, code) "{{{3 function! tlib#buffer#Eval(buffer, code) abort "{{{3
" let cb = bufnr('%') " let cb = bufnr('%')
" let wb = bufwinnr('%') " let wb = bufwinnr('%')
" " TLogVAR cb " " TLogVAR cb
@ -134,7 +134,7 @@ function! tlib#buffer#Eval(buffer, code) "{{{3
endf endf
" :def: function! tlib#buffer#GetList(?show_hidden=0, ?show_number=0, " ?order='bufnr') " :def: function! tlib#buffer#GetList(?show_hidden=0, ?show_number=0, " ?order='bufnr') abort
" Possible values for the "order" argument: " Possible values for the "order" argument:
" bufnr :: Default behaviour " bufnr :: Default behaviour
" mru :: Sort buffers according to most recent use " mru :: Sort buffers according to most recent use
@ -142,7 +142,7 @@ endf
" "
" NOTE: MRU order works on second invocation only. If you want to always " NOTE: MRU order works on second invocation only. If you want to always
" use MRU order, call tlib#buffer#EnableMRU() in your ~/.vimrc file. " use MRU order, call tlib#buffer#EnableMRU() in your ~/.vimrc file.
function! tlib#buffer#GetList(...) function! tlib#buffer#GetList(...) abort
TVarArg ['show_hidden', 0], ['show_number', 0], ['order', ''] TVarArg ['show_hidden', 0], ['show_number', 0], ['order', '']
" TLogVAR show_hidden, show_number, order " TLogVAR show_hidden, show_number, order
let ls_bang = show_hidden ? '!' : '' let ls_bang = show_hidden ? '!' : ''
@ -150,14 +150,14 @@ function! tlib#buffer#GetList(...)
exec 'silent ls'. ls_bang exec 'silent ls'. ls_bang
redir END redir END
let buffer_list = split(bfs, '\n') let buffer_list = split(bfs, '\n')
if order == 'mru' if order ==# 'mru'
if empty(s:bmru) if empty(s:bmru)
call tlib#buffer#EnableMRU() call tlib#buffer#EnableMRU()
echom 'tlib: Installed Buffer MRU logger; disable with: call tlib#buffer#DisableMRU()' echom 'tlib: Installed Buffer MRU logger; disable with: call tlib#buffer#DisableMRU()'
else else
call sort(buffer_list, function('s:CompareBufferNrByMRU')) call sort(buffer_list, function('s:CompareBufferNrByMRU'))
endif endif
elseif order == 'basename' elseif order ==# 'basename'
call sort(buffer_list, function('s:CompareBuffernameByBasename')) call sort(buffer_list, function('s:CompareBuffernameByBasename'))
endif endif
let buffer_nr = map(copy(buffer_list), 'str2nr(matchstr(v:val, ''\s*\zs\d\+\ze''))') let buffer_nr = map(copy(buffer_list), 'str2nr(matchstr(v:val, ''\s*\zs\d\+\ze''))')
@ -176,11 +176,11 @@ function! tlib#buffer#GetList(...)
endf endf
" :def: function! tlib#buffer#ViewLine(line, ?position='z') " :def: function! tlib#buffer#ViewLine(line, ?position='z') abort
" line is either a number or a string that begins with a number. " line is either a number or a string that begins with a number.
" For possible values for position see |scroll-cursor|. " For possible values for position see |scroll-cursor|.
" See also |g:tlib_viewline_position|. " See also |g:tlib_viewline_position|.
function! tlib#buffer#ViewLine(line, ...) "{{{3 function! tlib#buffer#ViewLine(line, ...) abort "{{{3
if a:line if a:line
TVarArg 'pos' TVarArg 'pos'
let ln = matchstr(a:line, '^\d\+') let ln = matchstr(a:line, '^\d\+')
@ -200,7 +200,7 @@ function! tlib#buffer#ViewLine(line, ...) "{{{3
endf endf
function! s:UndoHighlightLine() "{{{3 function! s:UndoHighlightLine() abort "{{{3
2match none 2match none
autocmd! TLib CursorMoved,CursorMovedI <buffer> autocmd! TLib CursorMoved,CursorMovedI <buffer>
autocmd! TLib CursorHold,CursorHoldI <buffer> autocmd! TLib CursorHold,CursorHoldI <buffer>
@ -209,7 +209,7 @@ function! s:UndoHighlightLine() "{{{3
endf endf
function! tlib#buffer#HighlightLine(...) "{{{3 function! tlib#buffer#HighlightLine(...) abort "{{{3
TVarArg ['line', line('.')] TVarArg ['line', line('.')]
" exec '2match MatchParen /^\%'. a:line .'l.*/' " exec '2match MatchParen /^\%'. a:line .'l.*/'
exec '2match Search /^\%'. line .'l.*/' exec '2match Search /^\%'. line .'l.*/'
@ -222,7 +222,7 @@ endf
" Delete the lines in the current buffer. Wrapper for |:delete|. " Delete the lines in the current buffer. Wrapper for |:delete|.
function! tlib#buffer#DeleteRange(line1, line2) "{{{3 function! tlib#buffer#DeleteRange(line1, line2) abort "{{{3
let r = @t let r = @t
try try
exec a:line1.','.a:line2.'delete t' exec a:line1.','.a:line2.'delete t'
@ -233,14 +233,14 @@ endf
" Replace a range of lines. " Replace a range of lines.
function! tlib#buffer#ReplaceRange(line1, line2, lines) function! tlib#buffer#ReplaceRange(line1, line2, lines) abort
call tlib#buffer#DeleteRange(a:line1, a:line2) call tlib#buffer#DeleteRange(a:line1, a:line2)
call append(a:line1 - 1, a:lines) call append(a:line1 - 1, a:lines)
endf endf
" Initialize some scratch area at the bottom of the current buffer. " Initialize some scratch area at the bottom of the current buffer.
function! tlib#buffer#ScratchStart() "{{{3 function! tlib#buffer#ScratchStart() abort "{{{3
norm! Go norm! Go
let b:tlib_inbuffer_scratch = line('$') let b:tlib_inbuffer_scratch = line('$')
return b:tlib_inbuffer_scratch return b:tlib_inbuffer_scratch
@ -248,7 +248,7 @@ endf
" Remove the in-buffer scratch area. " Remove the in-buffer scratch area.
function! tlib#buffer#ScratchEnd() "{{{3 function! tlib#buffer#ScratchEnd() abort "{{{3
if !exists('b:tlib_inbuffer_scratch') if !exists('b:tlib_inbuffer_scratch')
echoerr 'tlib: In-buffer scratch not initalized' echoerr 'tlib: In-buffer scratch not initalized'
endif endif
@ -258,14 +258,14 @@ endf
" Run exec on all buffers via bufdo and return to the original buffer. " Run exec on all buffers via bufdo and return to the original buffer.
function! tlib#buffer#BufDo(exec) "{{{3 function! tlib#buffer#BufDo(exec) abort "{{{3
let bn = bufnr('%') let bn = bufnr('%')
exec 'bufdo '. a:exec exec 'bufdo '. a:exec
exec 'buffer! '. bn exec 'buffer! '. bn
endf endf
" :def: function! tlib#buffer#InsertText(text, keyargs) " :def: function! tlib#buffer#InsertText(text, keyargs) abort
" Keyargs: " Keyargs:
" 'shift': 0|N " 'shift': 0|N
" 'col': col('.')|N " 'col': col('.')|N
@ -273,7 +273,7 @@ endf
" 'indent': 0|1 " 'indent': 0|1
" 'pos': 'e'|'s' ... Where to locate the cursor (somewhat like s and e in {offset}) " 'pos': 'e'|'s' ... Where to locate the cursor (somewhat like s and e in {offset})
" Insert text (a string) in the buffer. " Insert text (a string) in the buffer.
function! tlib#buffer#InsertText(text, ...) "{{{3 function! tlib#buffer#InsertText(text, ...) abort "{{{3
TVarArg ['keyargs', {}] TVarArg ['keyargs', {}]
" TLogVAR a:text, keyargs " TLogVAR a:text, keyargs
let keyargs = extend({ let keyargs = extend({
@ -298,7 +298,7 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
" exec 'norm! '. keyargs.lineno .'G' " exec 'norm! '. keyargs.lineno .'G'
call cursor(keyargs.lineno, keyargs.col) call cursor(keyargs.lineno, keyargs.col)
if keyargs.indent && keyargs.col > 1 if keyargs.indent && keyargs.col > 1
if &fo =~# '[or]' if &formatoptions =~# '[or]'
" FIXME: Is the simple version sufficient? " FIXME: Is the simple version sufficient?
" VERSION 1 " VERSION 1
" " This doesn't work because it's not guaranteed that the " " This doesn't work because it's not guaranteed that the
@ -307,7 +307,7 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
" norm! a " norm! a
" "norm! o " "norm! o
" " TAssertExec redraw | sleep 3 " " TAssertExec redraw | sleep 3
" let idt = strpart(getline('.'), 0, keyargs.col('.') + keyargs.shift) " let idt = tlib#string#Strcharpart(getline('.'), 0, keyargs.col('.') + keyargs.shift)
" " TLogVAR idt " " TLogVAR idt
" let idtl = len(idt) " let idtl = len(idt)
" -1,.delete " -1,.delete
@ -346,10 +346,10 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
let tlen = len(text) let tlen = len(text)
let posshift = matchstr(keyargs.pos, '\d\+') let posshift = matchstr(keyargs.pos, '\d\+')
" TLogVAR keyargs.pos " TLogVAR keyargs.pos
if keyargs.pos =~ '^e' if keyargs.pos =~# '^e'
exec keyargs.lineno + tlen - 1 exec keyargs.lineno + tlen - 1
exec 'norm! 0'. (len(text[-1]) - len(post) + posshift - 1) .'l' exec 'norm! 0'. (len(text[-1]) - len(post) + posshift - 1) .'l'
elseif keyargs.pos =~ '^s' elseif keyargs.pos =~# '^s'
" TLogVAR keyargs.lineno, pre, posshift " TLogVAR keyargs.lineno, pre, posshift
exec keyargs.lineno exec keyargs.lineno
exec 'norm! '. len(pre) .'|' exec 'norm! '. len(pre) .'|'
@ -363,7 +363,7 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
endf endf
function! tlib#buffer#InsertText0(text, ...) "{{{3 function! tlib#buffer#InsertText0(text, ...) abort "{{{3
TVarArg ['keyargs', {}] TVarArg ['keyargs', {}]
let mode = get(keyargs, 'mode', 'i') let mode = get(keyargs, 'mode', 'i')
" TLogVAR mode " TLogVAR mode
@ -382,13 +382,13 @@ function! tlib#buffer#InsertText0(text, ...) "{{{3
endf endf
function! tlib#buffer#CurrentByte() "{{{3 function! tlib#buffer#CurrentByte() abort "{{{3
return line2byte(line('.')) + col('.') return line2byte(line('.')) + col('.')
endf endf
" Evaluate cmd while maintaining the cursor position and jump registers. " Evaluate cmd while maintaining the cursor position and jump registers.
function! tlib#buffer#KeepCursorPosition(cmd) "{{{3 function! tlib#buffer#KeepCursorPosition(cmd) abort "{{{3
" let pos = getpos('.') " let pos = getpos('.')
let view = winsaveview() let view = winsaveview()
try try

View file

@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30. " @Created: 2007-06-30.
" @Last Change: 2015-10-24. " @Last Change: 2019-01-02.
" @Revision: 31.1.243 " @Revision: 125.1.243
" The cache directory. If empty, use |tlib#dir#MyRuntime|.'/cache'. " The cache directory. If empty, use |tlib#dir#MyRuntime|.'/cache'.
@ -45,21 +45,37 @@ TLet g:tlib#cache#dont_purge = ['[\/]\.last_purge$']
" |pathshorten()|. " |pathshorten()|.
TLet g:tlib#cache#max_filename = 200 TLet g:tlib#cache#max_filename = 200
TLet g:tlib#cache#use_json = 0
TLet g:tlib#cache#use_encoding = ''
let s:cache = {} let s:cache = {}
" :display: tlib#cache#Dir(?mode = 'bg') " :display: tlib#cache#Dir(?mode = 'bg', ?ensure_dir = true)
" The default cache directory. " The default cache directory.
function! tlib#cache#Dir(...) "{{{3 function! tlib#cache#Dir(...) "{{{3
TVarArg ['mode', 'bg'] TVarArg ['mode', 'bg'], ['ensure_dir', 1]
let dir = tlib#var#Get('tlib_cache', mode) let dir = tlib#var#Get('tlib_cache', mode)
if empty(dir) if empty(dir)
let dir = tlib#file#Join([tlib#dir#MyRuntime(), 'cache']) let dir = tlib#file#Join([tlib#dir#MyRuntime(), 'cache'])
endif endif
if ensure_dir
call tlib#dir#Ensure(dir)
endif
return dir return dir
endf endf
" :display: tlib#cache#EncodedFilename(type, file, ?mkdir=0, ?dir='')
" Encode `file` and call |tlib#cache#Filename()|.
function! tlib#cache#EncodedFilename(type, file, ...) "{{{3
let file = tlib#url#Encode(a:file)
return call(function('tlib#cache#Filename'), [a:type, file] + a:000)
endf
" :def: function! tlib#cache#Filename(type, ?file=%, ?mkdir=0, ?dir='') " :def: function! tlib#cache#Filename(type, ?file=%, ?mkdir=0, ?dir='')
function! tlib#cache#Filename(type, ...) "{{{3 function! tlib#cache#Filename(type, ...) "{{{3
" TLogDBG 'bufname='. bufname('.') " TLogDBG 'bufname='. bufname('.')
@ -90,12 +106,15 @@ function! tlib#cache#Filename(type, ...) "{{{3
" TLogVAR file, dir, mkdir " TLogVAR file, dir, mkdir
let cache_file = tlib#file#Join([dir, file]) let cache_file = tlib#file#Join([dir, file])
if len(cache_file) > g:tlib#cache#max_filename if len(cache_file) > g:tlib#cache#max_filename
" echom "DBG long filename" cache_file
" echom "DBG long filename" dir
if v:version >= 704 if v:version >= 704
let shortfilename = pathshorten(file) .'_'. sha256(file) let shortfilename = sha256(file)
else else
let shortfilename = pathshorten(file) .'_'. tlib#hash#Adler32(file) let shortfilename = tlib#hash#Adler32(file)
endif endif
let cache_file = tlib#cache#Filename(a:type, shortfilename, mkdir, dir0) " let cache_file = tlib#cache#Filename(a:type, shortfilename, mkdir, dir0)
let cache_file = tlib#file#Join([dir, shortfilename])
else else
if mkdir && !isdirectory(dir) if mkdir && !isdirectory(dir)
try try
@ -126,15 +145,45 @@ function! s:SetTimestamp(cfile, type) "{{{3
endf endf
function! tlib#cache#Save(cfile, dictionary, ...) "{{{3 function! s:PutValue(cfile, value) abort "{{{3
let s:cache[a:cfile] = {'mtime': localtime(), 'data': a:value}
endf
function! s:GetValue(cfile, default) abort "{{{3
return get(get(s:cache, a:cfile, {}), 'data', a:default)
endf
function! s:GetCacheTime(cfile) abort "{{{3
let not_found = !has_key(s:cache, a:cfile)
let cftime = not_found ? -1 : s:cache[a:cfile].mtime
return cftime
endf
function! tlib#cache#Save(cfile, value, ...) "{{{3
TVarArg ['options', {}] TVarArg ['options', {}]
let in_memory = get(options, 'in_memory', 0) let in_memory = get(options, 'in_memory', 0)
if in_memory if in_memory
" TLogVAR in_memory, a:cfile, localtime() " TLogVAR in_memory, a:cfile, localtime()
let s:cache[a:cfile] = {'mtime': localtime(), 'data': a:dictionary} call s:PutValue(a:cfile, a:value)
elseif !empty(a:cfile) elseif !empty(a:cfile)
" TLogVAR a:dictionary " TLogVAR a:value
call writefile([string(a:dictionary)], a:cfile, 'b') let cfile = a:cfile
if g:tlib#cache#use_json && exists('*json_encode')
try
let value = json_encode(a:value)
let cfile .= '.json'
catch
echoerr v:exception
let value = string(a:value)
endtry
else
let value = string(a:value)
endif
Tlibtrace 'tlib', cfile, value
call writefile([value], cfile, 'b')
call s:SetTimestamp(a:cfile, 'write') call s:SetTimestamp(a:cfile, 'write')
endif endif
endf endf
@ -152,16 +201,57 @@ function! tlib#cache#Get(cfile, ...) "{{{3
let in_memory = get(options, 'in_memory', 0) let in_memory = get(options, 'in_memory', 0)
if in_memory if in_memory
" TLogVAR in_memory, a:cfile " TLogVAR in_memory, a:cfile
return get(get(s:cache, a:cfile, {}), 'data', default) return s:GetValue(a:cfile, default)
else else
call tlib#cache#MaybePurge() call tlib#cache#MaybePurge()
if !empty(a:cfile) && filereadable(a:cfile) if !empty(a:cfile)
let val = readfile(a:cfile, 'b') let jsonfile = a:cfile .'.json'
call s:SetTimestamp(a:cfile, 'read') let use_json = g:tlib#cache#use_json && exists('*json_decode') && exists('v:none') && filereadable(jsonfile)
return eval(join(val, "\n")) if use_json
else let use_json = 1
return default let cfile = jsonfile
else
let cfile = a:cfile
endif
let mt = s:GetCacheTime(cfile)
let ft = getftime(cfile)
if mt != -1 && mt >= ft
return s:GetValue(cfile, default)
elseif ft != -1
call s:SetTimestamp(cfile, 'read')
let val = join(readfile(cfile, 'b'), '\n')
try
if use_json
" NOTE: Copy result of json_decode() in order to
" avoid "E741: value is locked" error in vim8.
let value = json_decode(val)
if value is v:none
let value = default
else
let value = copy(value)
endif
else
let value = eval(val)
endif
call s:PutValue(cfile, value)
return value
catch
echohl ErrorMsg
echom v:exception
echom 'tlib#cache#Get: Invalid value in:' cfile
echom 'Value:' string(val)
echom 'Please review the file and delete it if necessary'
echom 'Will use default value:' string(default)
echohl NONE
if g:tlib#debug
let @* = string(val)
endif
" call s:PutValue(cfile, default)
return default
endtry
endif
endif endif
return default
endif endif
endf endf
@ -172,10 +262,14 @@ endf
function! tlib#cache#Value(cfile, generator, ftime, ...) "{{{3 function! tlib#cache#Value(cfile, generator, ftime, ...) "{{{3
TVarArg ['args', []], ['options', {}] TVarArg ['args', []], ['options', {}]
let in_memory = get(options, 'in_memory', 0) let in_memory = get(options, 'in_memory', 0)
let not_found = in_memory ? !has_key(s:cache, a:cfile) : !filereadable(a:cfile) if in_memory
" TLogVAR in_memory, not_found let cftime = s:GetCacheTime(a:cfile)
let cftime = in_memory ? (not_found ? 0 : s:cache[a:cfile].mtime) : getftime(a:cfile) else
if not_found || (a:ftime != 0 && cftime < a:ftime) let cftime = getftime(a:cfile)
endif
let ftime = a:ftime
" TLogVAR in_memory, cftime
if cftime == -1 || ftime == -1 || (ftime != 0 && cftime < ftime)
" TLogVAR a:generator, args " TLogVAR a:generator, args
let val = call(a:generator, args) let val = call(a:generator, args)
" TLogVAR val " TLogVAR val
@ -194,6 +288,12 @@ function! tlib#cache#Value(cfile, generator, ftime, ...) "{{{3
endf endf
function! tlib#cache#ValueFromName(type, name, ...) abort "{{{3
let cfile = tlib#cache#Filename(a:type, tlib#url#Encode(a:name), 1)
return call(function('tlib#cache#Value'), [cfile] + a:000)
endf
" Call |tlib#cache#Purge()| if the last purge was done before " Call |tlib#cache#Purge()| if the last purge was done before
" |g:tlib#cache#purge_every_days|. " |g:tlib#cache#purge_every_days|.
function! tlib#cache#MaybePurge() "{{{3 function! tlib#cache#MaybePurge() "{{{3
@ -251,16 +351,12 @@ function! tlib#cache#Purge() "{{{3
try try
for file in files for file in files
if isdirectory(file) if isdirectory(file)
if empty(filter(copy(newer), 'strpart(v:val, 0, len(file)) ==# file')) if empty(filter(copy(newer), 'tlib#string#Strcharpart(v:val, 0, len(file)) ==# file'))
call add(deldir, file) call add(deldir, file)
endif endif
else else
if getftime(file) < threshold if getftime(file) < threshold
if delete(file) call s:Delete(msg, file, '')
call add(msg, "TLib: Could not delete cache file: ". file)
elseif g:tlib#cache#verbosity >= 2
call add(msg, "TLib: Delete cache file: ". file)
endif
else else
call add(newer, file) call add(newer, file)
endif endif
@ -273,56 +369,68 @@ function! tlib#cache#Purge() "{{{3
echo join(msg, "\n") echo join(msg, "\n")
endif endif
if !empty(deldir) if !empty(deldir)
if &shell =~ 'sh\(\.exe\)\?$' let deldir = filter(reverse(sort(deldir)), 's:Delete(msg, v:val, "d")')
let scriptfile = 'deldir.sh' if !empty(deldir)
let rmdir = 'rm -rf %s' if &shell =~ 'sh\(\.exe\)\?$'
else let scriptfile = 'deldir.sh'
let scriptfile = 'deldir.bat' let rmdir = 'rm -rf %s'
let rmdir = 'rmdir /S /Q %s' else
endif let scriptfile = 'deldir.bat'
let enc = g:tlib#cache#script_encoding let rmdir = 'rmdir /S /Q %s'
if has('multi_byte') && enc != &enc
call map(deldir, 'iconv(v:val, &enc, enc)')
endif
let scriptfile = tlib#file#Join([dir, scriptfile])
if filereadable(scriptfile)
let script = readfile(scriptfile)
else
let script = []
endif
let script += map(copy(deldir), 'printf(rmdir, shellescape(v:val, 1))')
let script = tlib#list#Uniq(script)
call writefile(script, scriptfile)
call inputsave()
if g:tlib#cache#run_script == 0
if g:tlib#cache#verbosity >= 1
echohl WarningMsg
if g:tlib#cache#verbosity >= 2
echom "TLib: Purged cache. Need to run script to delete directories"
endif
echom "TLib: Please review and execute: ". scriptfile
echohl NONE
endif endif
else let enc = g:tlib#cache#script_encoding
try if has('multi_byte') && enc != &enc
let yn = g:tlib#cache#run_script == 2 ? 'y' : tlib#input#Dialog("TLib: About to delete directories by means of a shell script.\nDirectory removal script: ". scriptfile ."\nRun script to delete directories now?", ['yes', 'no', 'edit'], 'no') call map(deldir, 'iconv(v:val, &enc, enc)')
if yn =~ '^y\%[es]$' endif
exec 'cd '. fnameescape(dir) let scriptfile = tlib#file#Join([dir, scriptfile])
exec '! ' &shell shellescape(scriptfile, 1) if filereadable(scriptfile)
exec 'cd -' let script = readfile(scriptfile)
call delete(scriptfile) else
elseif yn =~ '^e\%[dit]$' let script = []
exec 'edit '. fnameescape(scriptfile) endif
let script += map(copy(deldir), 'printf(rmdir, shellescape(v:val, 1))')
let script = tlib#list#Uniq(script)
call writefile(script, scriptfile)
call inputsave()
if g:tlib#cache#run_script == 0
if g:tlib#cache#verbosity >= 1
echohl WarningMsg
if g:tlib#cache#verbosity >= 2
echom "TLib: Purged cache. Need to run script to delete directories"
endif
echom "TLib: Please review and execute: ". scriptfile
echohl NONE
endif endif
finally else
call inputrestore() try
endtry let yn = g:tlib#cache#run_script == 2 ? 'y' : tlib#input#Dialog("TLib: About to delete directories by means of a shell script.\nDirectory removal script: ". scriptfile ."\nRun script to delete directories now?", ['yes', 'no', 'edit'], 'no')
if yn =~ '^y\%[es]$'
exec 'silent cd '. fnameescape(dir)
exec '! ' &shell shellescape(scriptfile, 1)
exec 'silent cd -'
call delete(scriptfile)
elseif yn =~ '^e\%[dit]$'
exec 'edit '. fnameescape(scriptfile)
endif
finally
call inputrestore()
endtry
endif
endif endif
endif endif
call s:PurgeTimestamp(dir) call s:PurgeTimestamp(dir)
endf endf
function! s:Delete(msg, file, flags) abort "{{{3
let rv = delete(a:file, a:flags)
if !rv && g:tlib#cache#verbosity >= 2
call add(a:msg, "TLib#cache: Delete ". file)
endif
return rv
endf
function! s:PurgeTimestamp(dir) "{{{3 function! s:PurgeTimestamp(dir) "{{{3
let last_purge = tlib#file#Join([a:dir, '.last_purge']) let last_purge = tlib#file#Join([a:dir, '.last_purge'])
" TLogVAR last_purge " TLogVAR last_purge
@ -338,7 +446,7 @@ function! tlib#cache#ListFilesInCache(...) "{{{3
endif endif
let files = reverse(split(filess, '\n')) let files = reverse(split(filess, '\n'))
let pos0 = len(tlib#dir#CanonicName(dir)) let pos0 = len(tlib#dir#CanonicName(dir))
call filter(files, 's:ShouldPurge(strpart(v:val, pos0))') call filter(files, 's:ShouldPurge(tlib#string#Strcharpart(v:val, pos0))')
return files return files
endf endf

View file

@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-03-25. " @Created: 2010-03-25.
" @Last Change: 2015-11-23. " @Last Change: 2017-09-06.
" @Revision: 21.0.34 " @Revision: 44.0.34
if !exists('g:tlib#date#ShortDatePrefix') | let g:tlib#date#ShortDatePrefix = '20' | endif "{{{2 if !exists('g:tlib#date#ShortDatePrefix') | let g:tlib#date#ShortDatePrefix = '20' | endif "{{{2
@ -17,12 +17,14 @@ let g:tlib#date#date_format = '%Y-%m-%d'
function! tlib#date#IsDate(text) abort "{{{3 function! tlib#date#IsDate(text) abort "{{{3
return a:text =~# '^'. g:tlib#date#date_rx .'$' return a:text =~# '^'. g:tlib#date#date_rx .'$' &&
\ !empty(tlib#date#Parse(a:text, 0, 1))
endf endf
function! tlib#date#Format(secs1970) abort "{{{3 function! tlib#date#Format(...) abort "{{{3
return strftime(g:tlib#date#date_format, a:secs1970) let secs1970 = a:0 >= 1 ? a:1 : localtime()
return strftime(g:tlib#date#date_format, secs1970)
endf endf
@ -37,11 +39,16 @@ function! tlib#date#DiffInDays(date, ...)
endf endf
" :display: tlib#date#Parse(date, ?allow_zero=0) "{{{3 " :display: tlib#date#Parse(date, ?allow_zero=0, ?silent=0) "{{{3
function! tlib#date#Parse(date, ...) "{{{3 function! tlib#date#Parse(date, ...) "{{{3
let min = a:0 >= 1 && a:1 ? 0 : 1 let min = a:0 >= 1 && a:1 ? 0 : 1
" TLogVAR a:date, min let silent = a:0 >= 2 ? a:2 : 0
Tlibtype 'tlib', a:date, min, silent
let m = matchlist(a:date, '^\(\d\{2}\|\d\{4}\)-\(\d\{1,2}\)-\(\d\{1,2}\)$') let m = matchlist(a:date, '^\(\d\{2}\|\d\{4}\)-\(\d\{1,2}\)-\(\d\{1,2}\)$')
Tlibtype 'tlib', m
let year = ''
let month = ''
let days = ''
if !empty(m) if !empty(m)
let year = m[1] let year = m[1]
let month = m[2] let month = m[2]
@ -61,13 +68,17 @@ function! tlib#date#Parse(date, ...) "{{{3
endif endif
endif endif
endif endif
Tlibtype 'tlib', year, month, days
if empty(m) || year == '' || month == '' || days == '' || if empty(m) || year == '' || month == '' || days == '' ||
\ month < min || month > 12 || days < min || days > 31 \ month < min || month > 12 || days < min || days > 31
echoerr 'TLib: Invalid date: '. a:date if !silent
echoerr 'TLib: Invalid date: '. a:date
endif
return [] return []
endif endif
if strlen(year) == 2 if strlen(year) == 2
let year = g:tlib#date#ShortDatePrefix . year let year = g:tlib#date#ShortDatePrefix . year
Tlibtype 'tlib', year
endif endif
return [0 + year, 0 + month, 0 + days] return [0 + year, 0 + month, 0 + days]
endf endf
@ -137,22 +148,35 @@ function! tlib#date#Shift(date, shift) abort "{{{3
let ml = matchlist(a:date, g:tlib#date#date_rx) let ml = matchlist(a:date, g:tlib#date#date_rx)
" TLogVAR a:date, a:shift, n, ml " TLogVAR a:date, a:shift, n, ml
if a:shift =~ 'd$' if a:shift =~ 'd$'
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * n let date = tlib#date#AddDays(a:date, n)
" TLogVAR secs elseif a:shift =~ 'b$'
let n1 = n
let secs = tlib#date#SecondsSince1970(a:date)
while n1 > 0
let n1 -= 1
let secs += g:tlib#date#dayshift
let uday = strftime('%u', secs)
if uday == 6
let secs += g:tlib#date#dayshift * 2
elseif uday == 7
let secs += g:tlib#date#dayshift
endif
endwh
let date = tlib#date#Format(secs) let date = tlib#date#Format(secs)
elseif a:shift =~ 'w$' elseif a:shift =~ 'w$'
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * n * 7 let date = tlib#date#AddDays(a:date, n * 7)
let date = tlib#date#Format(secs)
elseif a:shift =~ 'm$' elseif a:shift =~ 'm$'
let d = str2nr(ml[3]) let d = str2nr(ml[3])
let ms = str2nr(ml[2]) + n let ms = str2nr(ml[2]) + n
let m = (ms - 1) % 12 + 1 let m = (ms - 1) % 12 + 1
let yr = str2nr(ml[1]) + ms / 12 let yr = str2nr(ml[1]) + (ms - 1) / 12
let date = printf('%04d-%02d-%02d', yr, m, d) let date = printf('%04d-%02d-%02d', yr, m, d)
" TLogVAR d, ms, m, yr, date " TLogVAR d, ms, m, yr, date
elseif a:shift =~ 'y$' elseif a:shift =~ 'y$'
let yr = str2nr(ml[1]) + n let yr = str2nr(ml[1]) + n
let date = substitute(a:date, '^\d\{4}', yr, '') let date = substitute(a:date, '^\d\{4}', yr, '')
else
throw 'tlib#date#Shift: Unsupported arguments: '. string(a:shift)
endif endif
" if !empty(ml[4]) && date !~ '\s'. ml[4] .'$' " if !empty(ml[4]) && date !~ '\s'. ml[4] .'$'
" let date .= ' '. ml[4] " let date .= ' '. ml[4]
@ -161,3 +185,11 @@ function! tlib#date#Shift(date, shift) abort "{{{3
return date return date
endf endf
function! tlib#date#AddDays(date, n) abort "{{{3
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * a:n
" TLogVAR secs
let date = tlib#date#Format(secs)
return date
endf

View file

@ -1,14 +1,44 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: https://github.com/tomtom " @Website: https://github.com/tomtom
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2015-10-14 " @Last Change: 2016-04-06
" @Revision: 2 " @Revision: 22
function! tlib#dictionary#Rev(dict) abort "{{{3 " :display: tlib#dictionary#Rev(dict, ?opts = {}) abort "{{{3
function! tlib#dictionary#Rev(dict, ...) abort "{{{3
let opts = a:0 >= 1 ? a:1 : {}
Tlibtype a:dict, 'dict', opts, 'dict'
let rev = {} let rev = {}
let use_string = get(opts, 'use_string', 0)
let use_eval = get(opts, 'use_eval', 0)
let values_as_list = get(opts, 'values_as_list', 0)
for [m, f] in items(a:dict) for [m, f] in items(a:dict)
let rev[f] = m if use_string
let k = string(f)
else
let k = type(f) == 1 ? f : string(f)
if k ==# ''
let k = get(opts, 'empty', '')
if empty(k)
continue
endif
endif
endif
if use_eval
let v = eval(m)
else
let v = m
endif
if values_as_list
if has_key(rev, k)
call add(rev[k], v)
else
let rev[k] = [v]
endif
else
let rev[k] = v
endif
endfor endfor
return rev return rev
endf endf

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 40 " @Revision: 43
" TLet g:tlib#dir#sep = '/' " TLet g:tlib#dir#sep = '/'
TLet g:tlib#dir#sep = exists('+shellslash') && !&shellslash ? '\' : '/' TLet g:tlib#dir#sep = exists('+shellslash') && !&shellslash ? '\' : '/'
@ -65,12 +65,12 @@ endf
" :def: function! tlib#dir#CD(dir, ?locally=0) => CWD " :def: function! tlib#dir#CD(dir, ?locally=0) => CWD
function! tlib#dir#CD(dir, ...) "{{{3 function! tlib#dir#CD(dir, ...) "{{{3
TVarArg ['locally', 0] TVarArg ['locally', haslocaldir()]
let cmd = locally ? 'lcd! ' : 'cd! ' let cmd = locally ? 'lcd! ' : 'cd! '
" let cwd = getcwd() " let cwd = getcwd()
let cmd .= tlib#arg#Ex(a:dir) let cmd .= tlib#arg#Ex(a:dir)
" TLogVAR a:dir, locally, cmd " TLogVAR a:dir, locally, cmd
exec cmd exec 'silent' cmd
" return cwd " return cwd
return getcwd() return getcwd()
endf endf
@ -78,7 +78,7 @@ endf
" :def: function! tlib#dir#Push(dir, ?locally=0) => CWD " :def: function! tlib#dir#Push(dir, ?locally=0) => CWD
function! tlib#dir#Push(dir, ...) "{{{3 function! tlib#dir#Push(dir, ...) "{{{3
TVarArg ['locally', 0] TVarArg ['locally', haslocaldir()]
call add(s:dir_stack, [getcwd(), locally]) call add(s:dir_stack, [getcwd(), locally])
return tlib#dir#CD(a:dir, locally) return tlib#dir#CD(a:dir, locally)
endf endf

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 168 " @Revision: 225
if !exists('g:tlib#file#drop') if !exists('g:tlib#file#drop')
@ -24,6 +24,12 @@ if !exists('g:tlib#file#absolute_filename_rx')
let g:tlib#file#absolute_filename_rx = '^\~\?[\/]' "{{{2 let g:tlib#file#absolute_filename_rx = '^\~\?[\/]' "{{{2
endif endif
if !exists('g:tlib#file#reject_rx')
let g:tlib#file#reject_rx = '\%(^\|[\/]\)\%(tags\|Thumbs\.db\)$' "{{{2
endif
""" File related {{{1 """ File related {{{1
" For the following functions please see ../../test/tlib.vim for examples. " For the following functions please see ../../test/tlib.vim for examples.
@ -31,9 +37,9 @@ endif
" EXAMPLES: > " EXAMPLES: >
" tlib#file#Split('foo/bar/filename.txt') " tlib#file#Split('foo/bar/filename.txt')
" => ['foo', 'bar', 'filename.txt'] " => ['foo', 'bar', 'filename.txt']
function! tlib#file#Split(filename) "{{{3 function! tlib#file#Split(filename) abort "{{{3
let prefix = matchstr(a:filename, '^\(\w\+:\)\?/\+') let prefix = matchstr(a:filename, '^\(\w\+:\)\?/\+')
" TLogVAR prefix Tlibtrace 'tlib', prefix
if !empty(prefix) if !empty(prefix)
let filename = a:filename[len(prefix) : -1] let filename = a:filename[len(prefix) : -1]
else else
@ -52,9 +58,9 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#file#Join(['foo', 'bar', 'filename.txt']) " tlib#file#Join(['foo', 'bar', 'filename.txt'])
" => 'foo/bar/filename.txt' " => 'foo/bar/filename.txt'
function! tlib#file#Join(filename_parts, ...) "{{{3 function! tlib#file#Join(filename_parts, ...) abort "{{{3
TVarArg ['strip_slashes', 1], 'maybe_absolute' TVarArg ['strip_slashes', 1], 'maybe_absolute'
" TLogVAR a:filename_parts, strip_slashes Tlibtrace 'tlib', a:filename_parts, strip_slashes
if maybe_absolute if maybe_absolute
let filename_parts = [] let filename_parts = []
for part in a:filename_parts for part in a:filename_parts
@ -70,7 +76,7 @@ function! tlib#file#Join(filename_parts, ...) "{{{3
" let rx = tlib#rx#Escape(g:tlib#dir#sep) .'$' " let rx = tlib#rx#Escape(g:tlib#dir#sep) .'$'
let rx = '[/\\]\+$' let rx = '[/\\]\+$'
let parts = map(copy(filename_parts), 'substitute(v:val, rx, "", "")') let parts = map(copy(filename_parts), 'substitute(v:val, rx, "", "")')
" TLogVAR parts Tlibtrace 'tlib', parts
return join(parts, g:tlib#dir#sep) return join(parts, g:tlib#dir#sep)
else else
return join(filename_parts, g:tlib#dir#sep) return join(filename_parts, g:tlib#dir#sep)
@ -81,18 +87,18 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#file#Relative('foo/bar/filename.txt', 'foo') " tlib#file#Relative('foo/bar/filename.txt', 'foo')
" => 'bar/filename.txt' " => 'bar/filename.txt'
function! tlib#file#Relative(filename, basedir) "{{{3 function! tlib#file#Relative(filename, basedir) abort "{{{3
" TLogVAR a:filename, a:basedir Tlibtrace 'tlib', a:filename, a:basedir
" TLogDBG getcwd() " TLogDBG getcwd()
" TLogDBG expand('%:p') " TLogDBG expand('%:p')
let b0 = tlib#file#Absolute(a:basedir) let b0 = tlib#file#Absolute(a:basedir)
let b = tlib#file#Split(b0) let b = tlib#file#Split(b0)
" TLogVAR b Tlibtrace 'tlib', b
let f0 = tlib#file#Absolute(a:filename) let f0 = tlib#file#Absolute(a:filename)
let fn = fnamemodify(f0, ':t') let fn = fnamemodify(f0, ':t')
let fd = fnamemodify(f0, ':h') let fd = fnamemodify(f0, ':h')
let f = tlib#file#Split(fd) let f = tlib#file#Split(fd)
" TLogVAR f0, fn, fd, f Tlibtrace 'tlib', f0, fn, fd, f
if f[0] != b[0] if f[0] != b[0]
let rv = f0 let rv = f0
else else
@ -103,18 +109,23 @@ function! tlib#file#Relative(filename, basedir) "{{{3
call remove(f, 0) call remove(f, 0)
call remove(b, 0) call remove(b, 0)
endwh endwh
" TLogVAR f, b Tlibtrace 'tlib', f, b
let rv = tlib#file#Join(repeat(['..'], len(b)) + f + [fn]) let rv = tlib#file#Join(repeat(['..'], len(b)) + f + [fn])
endif endif
" TLogVAR rv Tlibtrace 'tlib', rv
return rv return rv
endf endf
function! tlib#file#Absolute(filename, ...) "{{{3 function! tlib#file#IsAbsolute(filename) abort "{{{3
return a:filename =~? '^\%(/\|\w\+:/\)'
endf
function! tlib#file#Absolute(filename, ...) abort "{{{3
if filereadable(a:filename) if filereadable(a:filename)
let filename = fnamemodify(a:filename, ':p') let filename = fnamemodify(a:filename, ':p')
elseif a:filename =~ '^\(/\|[^\/]\+:\)' elseif a:filename =~# '^\(/\|[^\/]\+:\)'
let filename = a:filename let filename = a:filename
else else
let cwd = a:0 >= 1 ? a:1 : getcwd() let cwd = a:0 >= 1 ? a:1 : getcwd()
@ -126,17 +137,19 @@ function! tlib#file#Absolute(filename, ...) "{{{3
endf endf
function! tlib#file#Canonic(filename, ...) "{{{3 function! tlib#file#Canonic(filename, ...) abort "{{{3
TVarArg ['mode', ''] TVarArg ['mode', '']
if a:filename =~ '^\\\\' if empty(mode)
let mode = 'windows' if a:filename =~# '^\\\\'
elseif a:filename =~ '^\(file\|ftp\|http\)s\?:' let mode = 'windows'
let mode = 'url' elseif a:filename =~# '^\(file\|ftp\|http\)s\?:'
elseif (empty(mode) && g:tlib#sys#windows) let mode = 'url'
let mode = 'windows' elseif (empty(mode) && g:tlib#sys#windows)
let mode = 'windows'
endif
endif endif
let filename = a:filename let filename = a:filename
if mode == 'windows' if mode ==# 'windows'
let filename = substitute(filename, '/', '\\', 'g') let filename = substitute(filename, '/', '\\', 'g')
else else
let filename = substitute(filename, '\\', '/', 'g') let filename = substitute(filename, '\\', '/', 'g')
@ -145,7 +158,7 @@ function! tlib#file#Canonic(filename, ...) "{{{3
endf endf
function! s:SetScrollBind(world) "{{{3 function! s:SetScrollBind(world) abort "{{{3
let sb = get(a:world, 'scrollbind', &scrollbind) let sb = get(a:world, 'scrollbind', &scrollbind)
if sb != &scrollbind if sb != &scrollbind
let &scrollbind = sb let &scrollbind = sb
@ -153,60 +166,81 @@ function! s:SetScrollBind(world) "{{{3
endf endf
" :def: function! tlib#file#With(fcmd, bcmd, files, ?world={}) " :def: function! tlib#file#With(fcmd, bcmd, files, ?world={}) abort
function! tlib#file#With(fcmd, bcmd, files, ...) "{{{3 function! tlib#file#With(fcmd, bcmd, files, ...) abort "{{{3
" TLogVAR a:fcmd, a:bcmd, a:files Tlibtrace 'tlib', a:fcmd, a:bcmd, a:files
let world = a:0 >= 1 ? a:1 : {}
let unset_switchbuf = a:0 >= 2 ? a:2 : 0
exec tlib#arg#Let([['world', {}]]) exec tlib#arg#Let([['world', {}]])
call tlib#autocmdgroup#Init() call tlib#autocmdgroup#Init()
augroup TLibFileRead augroup TLibFileRead
autocmd! autocmd!
augroup END augroup END
for f in a:files if unset_switchbuf
let bn = bufnr('^'.f.'$') let switchbuf = &switchbuf
" TLogVAR f, bn set switchbuf&
let bufloaded = bufloaded(bn) endif
let ok = 0 try
let s:bufread = "" for f in a:files
if bn != -1 && buflisted(bn) try
if !empty(a:bcmd) let bn = bufnr('^'.f.'$')
" TLogDBG a:bcmd .' '. bn Tlibtrace 'tlib', f, bn
exec a:bcmd .' '. bn let bufloaded = bufloaded(bn)
let ok = 1 let ok = 0
call s:SetScrollBind(world) let s:bufread = ""
endif if bn != -1 && buflisted(bn)
else if !empty(a:bcmd)
if filereadable(f) let bcmd = a:bcmd .' '. bn
if !empty(a:fcmd) Tlibtrace 'tlib', bcmd
" TLogDBG a:fcmd .' '. tlib#arg#Ex(f) exec bcmd
exec 'autocmd TLibFileRead BufRead' escape(f, '\ ') 'let s:bufread=expand("<afile>:p")' let ok = 1
try call s:SetScrollBind(world)
exec a:fcmd .' '. tlib#arg#Ex(f) endif
finally else
exec 'autocmd! TLibFileRead BufRead' if filereadable(f)
endtry if !empty(a:fcmd)
let ok = 1 " TLogDBG a:fcmd .' '. tlib#arg#Ex(f)
call s:SetScrollBind(world) exec 'autocmd TLibFileRead BufRead' escape(f, '\ ') 'let s:bufread=expand("<afile>:p")'
try
let fcmd = a:fcmd .' '. tlib#arg#Ex(f)
Tlibtrace 'tlib', fcmd
exec fcmd
finally
exec 'autocmd! TLibFileRead BufRead'
endtry
let ok = 1
call s:SetScrollBind(world)
endif
else
echohl error
echom 'File not readable: '. f
echohl NONE
endif
endif endif
else Tlibtrace 'tlib', ok, bufloaded, &filetype
echohl error if empty(s:bufread) && ok && !bufloaded && empty(&filetype)
echom 'File not readable: '. f doautocmd BufRead
endif
catch /^Vim\%((\a\+)\)\=:E325/
echohl ErrorMsg
echom v:exception
echohl NONE echohl NONE
endif endtry
endfor
finally
augroup! TLibFileRead
if unset_switchbuf
let &switchbuf = switchbuf
endif endif
" TLogVAR ok, bufloaded, &filetype unlet! s:bufread
if empty(s:bufread) && ok && !bufloaded && empty(&filetype) endtry
doautocmd BufRead
endif
endfor
augroup! TLibFileRead
unlet! s:bufread
" TLogDBG "done" " TLogDBG "done"
endf endf
" Return 0 if the file isn't readable/doesn't exist. " Return 0 if the file isn't readable/doesn't exist.
" Otherwise return 1. " Otherwise return 1.
function! tlib#file#Edit(fileid) "{{{3 function! tlib#file#Edit(fileid) abort "{{{3
if type(a:fileid) == 0 if type(a:fileid) == 0
let bn = a:fileid let bn = a:fileid
let filename = fnamemodify(bufname(bn), ':p') let filename = fnamemodify(bufname(bn), ':p')
@ -217,20 +251,26 @@ function! tlib#file#Edit(fileid) "{{{3
if filename == expand('%:p') if filename == expand('%:p')
return 1 return 1
else else
" TLogVAR a:fileid, bn, filename, g:tlib#file#drop, filereadable(filename) Tlibtrace 'tlib', a:fileid, bn, filename, g:tlib#file#drop, filereadable(filename), bufnr('%')
if bn != -1 && buflisted(bn) if bn != -1 && buflisted(bn)
if g:tlib#file#drop if g:tlib#file#drop
" echom "DBG" get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename) " echom "DBG" get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename)
exec get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename) exec get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename)
" echom "DBG" bufnr('%')
else else
" echom "DBG" get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn " echom "DBG" get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
exec get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn exec get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
" echom "DBG" bufnr('%')
endif endif
return 1 return 1
elseif filereadable(filename) endif
if !filereadable(filename) && exists('#TLibPrepareFile#User')
exec 'doautocmd TLibPrepareFile User' filename
endif
if filereadable(filename)
try try
" let file = tlib#arg#Ex(filename) " let file = tlib#arg#Ex(filename)
" " TLogVAR file " Tlibtrace 'tlib', file
" echom "DBG" get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename) " echom "DBG" get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename)
exec get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename) exec get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename)
catch /E325/ catch /E325/
@ -252,27 +292,65 @@ function! tlib#file#Edit(fileid) "{{{3
endf endf
function! tlib#file#FilterFiles(files, options) abort "{{{3
Tlibtrace 'tlib', a:files, a:options, g:tlib#file#reject_rx
if !get(a:options, 'all', 0)
call filter(a:files, 'v:val !~# g:tlib#file#reject_rx')
endif
Tlibtrace 'tlib', a:files
let type = get(a:options, 'type', 'fd')
Tlibtrace 'tlib', type
if type !~# 'd' || type !~# 'f'
call filter(a:files, 'isdirectory(v:val) ? type =~# "d" : type =~# "f"')
endif
Tlibtrace 'tlib', a:files
return a:files
endf
if v:version > 704 || (v:version == 704 && has('patch279')) if v:version > 704 || (v:version == 704 && has('patch279'))
function! tlib#file#Glob(pattern) abort "{{{3 function! tlib#file#Glob(pattern, ...) abort "{{{3
return glob(a:pattern, 0, 1) let all = a:0 >= 1 ? a:1 : 0
let nosuf = a:0 >= 2 ? a:2 : 0
return tlib#file#FilterFiles(glob(a:pattern, nosuf, 1), {'all': all})
endf endf
function! tlib#file#Globpath(path, pattern) abort "{{{3 function! tlib#file#Globpath(path, pattern, ...) abort "{{{3
return globpath(a:path, a:pattern, 0, 1) let all = a:0 >= 1 ? a:1 : 0
let nosuf = a:0 >= 2 ? a:2 : 0
return tlib#file#FilterFiles(globpath(a:path, a:pattern, nosuf, 1), {'all': all})
endf endf
else else
" :nodoc: " :nodoc:
function! tlib#file#Glob(pattern) abort "{{{3 function! tlib#file#Glob(pattern, ...) abort "{{{3
return split(glob(a:pattern), '\n') let all = a:0 >= 1 ? a:1 : 0
let nosuf = a:0 >= 2 ? a:2 : 0
return tlib#file#FilterFiles(split(glob(a:pattern, nosuf), '\n'), {'all': all})
endf endf
" :nodoc: " :nodoc:
function! tlib#file#Globpath(path, pattern) abort "{{{3 function! tlib#file#Globpath(path, pattern, ...) abort "{{{3
return split(globpath(a:path, a:pattern), '\n') let all = a:0 >= 1 ? a:1 : 0
let nosuf = a:0 >= 2 ? a:2 : 0
return tlib#file#FilterFiles(split(globpath(a:path, a:pattern), '\n'), {'all': all})
endf endf
endif endif
let s:filereadable = {}
augroup TLib
autocmd BufWritePost,FileWritePost,FocusLost * let s:filereadable = {}
augroup end
function! tlib#file#Filereadable(filename) abort "{{{3
if !has_key(s:filereadable, a:filename)
let s:filereadable[a:filename] = filereadable(a:filename)
endif
return s:filereadable[a:filename]
endf

View file

@ -1,8 +1,7 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 1366 " @Revision: 1430
" :filedoc: " :filedoc:
" Input-related, select from a list etc. " Input-related, select from a list etc.
@ -312,7 +311,7 @@ function! tlib#input#List(type, ...) "{{{3
if !empty(filter) if !empty(filter)
" let world.initial_filter = [[''], [filter]] " let world.initial_filter = [[''], [filter]]
" let world.initial_filter = [[filter]] " let world.initial_filter = [[filter]]
" TLogVAR world.initial_filter Tlibtrace 'tlib', world.initial_filter, filter
call world.SetInitialFilter(filter) call world.SetInitialFilter(filter)
endif endif
endif endif
@ -333,10 +332,11 @@ endf
" (an instance of tlib#World as returned by |tlib#World#New|). " (an instance of tlib#World as returned by |tlib#World#New|).
function! tlib#input#ListW(world, ...) "{{{3 function! tlib#input#ListW(world, ...) "{{{3
TVarArg 'cmd' TVarArg 'cmd'
" let time0 = str2float(reltimestr(reltime())) " DBG let time0 = str2float(reltimestr(reltime()))
" TLogVAR time0 Tlibtrace 'tlib', time0
let world = a:world let world = a:world
if world.pick_last_item >= 1 && stridx(world.type, 'e') == -1 && len(world.base) <= 1 if world.pick_last_item >= 1 && stridx(world.type, 'e') == -1 && len(world.base) <= 1
call world.CloseScratch(1)
let rv = get(world.base, 0, world.rv) let rv = get(world.base, 0, world.rv)
if stridx(world.type, 'm') != -1 if stridx(world.type, 'm') != -1
return [rv] return [rv]
@ -345,7 +345,7 @@ function! tlib#input#ListW(world, ...) "{{{3
endif endif
endif endif
call s:Init(world, cmd) call s:Init(world, cmd)
" TLogVAR world.state, world.sticky, world.initial_index Tlibtrace 'tlib', world.state, world.sticky, world.initial_index
" let statusline = &l:statusline " let statusline = &l:statusline
" let laststatus = &laststatus " let laststatus = &laststatus
let showmode = &showmode let showmode = &showmode
@ -361,38 +361,24 @@ function! tlib#input#ListW(world, ...) "{{{3
try try
while !empty(world.state) && world.state !~ '^exit' && (world.show_empty || !empty(world.base)) while !empty(world.state) && world.state !~ '^exit' && (world.show_empty || !empty(world.base))
let post_keys = '' let post_keys = ''
" TLogDBG 'while' Tlibtrace 'tlib', 'while', world.state
" TLogVAR world.state let time01 = str2float(reltimestr(reltime()))
" let time01 = str2float(reltimestr(reltime())) " DBG Tlibtrace 'tlib', time01, time01 - time0
" TLogVAR time01, time01 - time0
try try
let world = s:RunStateHandlers(world) let world = s:RunStateHandlers(world)
" if exists('b:tlib_world_event') let time02 = str2float(reltimestr(reltime()))
" let event = b:tlib_world_event Tlibtrace 'tlib', time02, time02 - time0
" unlet! b:tlib_world_event
" if event == 'WinLeave'
" " let world.resume_state = world.state
" let world = tlib#agent#Suspend(world, world.rv)
" break
" endif
" endif
" let time02 = str2float(reltimestr(reltime())) " DBG
" TLogVAR time02, time02 - time0
if world.state =~ '\<reset\>' if world.state =~ '\<reset\>'
" TLogDBG 'reset'
" call world.Reset(world.state =~ '\<initial\>')
call world.Reset() call world.Reset()
continue continue
endif endif
call s:SetOffset(world) call s:SetOffset(world)
" let time02 = str2float(reltimestr(reltime())) " DBG let time02 = str2float(reltimestr(reltime()))
" TLogVAR time02, time02 - time0 Tlibtrace 'tlib', time02, time02 - time0
" TLogDBG 1 Tlibtrace 'tlib', world.state
" TLogVAR world.state
if world.state == 'scroll' if world.state == 'scroll'
let world.prefidx = world.offset let world.prefidx = world.offset
let world.state = 'redisplay' let world.state = 'redisplay'
@ -402,33 +388,26 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.sticky = 1 let world.sticky = 1
endif endif
" TLogVAR world.filter Tlibtrace 'tlib', world.filter
" TLogVAR world.sticky Tlibtrace 'tlib', world.sticky
if world.state =~ '\<picked\>' if world.state =~ '\<picked\>'
" TLogVAR world.rv Tlibtrace 'tlib', world.rv
throw 'picked' throw 'picked'
elseif world.state =~ '\<pick\>' elseif world.state =~ '\<pick\>'
let world.rv = world.CurrentItem() let world.rv = world.CurrentItem()
" TLogVAR world.rv Tlibtrace 'tlib', world.rv
throw 'picked' throw 'picked'
elseif world.state =~ 'display' elseif world.state =~ 'display'
if world.state =~ '^display' if world.state =~ '^display'
" let time03 = str2float(reltimestr(reltime())) " DBG let time03 = str2float(reltimestr(reltime()))
" TLogVAR time03, time03 - time0 Tlibtrace 'tlib', time03, time03 - time0
if world.IsValidFilter() if world.IsValidFilter()
let time1 = str2float(reltimestr(reltime()))
" let time1 = str2float(reltimestr(reltime())) " DBG Tlibtrace 'tlib', time1, time1 - time0
" TLogVAR time1, time1 - time0
call world.BuildTableList() call world.BuildTableList()
" let time2 = str2float(reltimestr(reltime())) " DBG let time2 = str2float(reltimestr(reltime()))
" TLogVAR time2, time2 - time0 Tlibtrace 'tlib', time2, time2 - time0
" TLogDBG 2
" TLogDBG len(world.table)
" TLogVAR world.table
" let world.list = map(copy(world.table), 'world.GetBaseItem(v:val)')
" TLogDBG 3
let world.llen = len(world.list) let world.llen = len(world.list)
" TLogVAR world.index_table
if empty(world.index_table) if empty(world.index_table)
let dindex = range(1, world.llen) let dindex = range(1, world.llen)
let world.index_width = len(world.llen) let world.index_width = len(world.llen)
@ -436,12 +415,11 @@ function! tlib#input#ListW(world, ...) "{{{3
let dindex = world.index_table let dindex = world.index_table
let world.index_width = len(max(dindex)) let world.index_width = len(max(dindex))
endif endif
" let time3 = str2float(reltimestr(reltime())) " DBG let time3 = str2float(reltimestr(reltime()))
" TLogVAR time3, time3 - time0 Tlibtrace 'tlib', time3, time3 - time0
if world.llen == 0 && !world.show_empty if world.llen == 0 && !world.show_empty
call world.ReduceFilter() call world.ReduceFilter()
let world.offset = 1 let world.offset = 1
" TLogDBG 'ReduceFilter'
continue continue
else else
if world.llen == 1 if world.llen == 1
@ -449,18 +427,15 @@ function! tlib#input#ListW(world, ...) "{{{3
if world.pick_last_item >= 2 if world.pick_last_item >= 2
" echom 'Pick last item: '. world.list[0] " echom 'Pick last item: '. world.list[0]
let world.prefidx = '1' let world.prefidx = '1'
" TLogDBG 'pick last item'
throw 'pick' throw 'pick'
endif endif
else else
let world.last_item = '' let world.last_item = ''
endif endif
endif endif
" let time4 = str2float(reltimestr(reltime())) " DBG let time4 = str2float(reltimestr(reltime()))
" TLogVAR time4, time4 - time0 Tlibtrace 'tlib', time4, time4 - time0
" TLogDBG 4 Tlibtrace 'tlib', world.idx, world.llen, world.state
" TLogVAR world.idx, world.llen, world.state
" TLogDBG world.FilterIsEmpty()
if world.state == 'display' if world.state == 'display'
if world.idx == '' && world.llen < g:tlib#input#sortprefs_threshold && !world.FilterIsEmpty() if world.idx == '' && world.llen < g:tlib#input#sortprefs_threshold && !world.FilterIsEmpty()
call world.SetPrefIdx() call world.SetPrefIdx()
@ -473,27 +448,22 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.prefidx = 1 let world.prefidx = 1
endif endif
endif endif
" let time5 = str2float(reltimestr(reltime())) " DBG let time5 = str2float(reltimestr(reltime()))
" TLogVAR time5, time5 - time0 Tlibtrace 'tlib', time5, time5 - time0
" TLogVAR world.initial_index, world.prefidx Tlibtrace 'tlib', world.initial_index, world.prefidx
" TLogDBG 5 Tlibtrace 'tlib', len(world.list)
" TLogDBG len(world.list)
" TLogVAR world.list
let dlist = world.DisplayFormat(world.list) let dlist = world.DisplayFormat(world.list)
" TLogVAR world.prefidx Tlibtrace 'tlib', world.prefidx
" TLogDBG 6 let time6 = str2float(reltimestr(reltime()))
" let time6 = str2float(reltimestr(reltime())) " DBG Tlibtrace 'tlib', time6, time6 - time0
" TLogVAR time6, time6 - time0
if world.offset_horizontal > 0 if world.offset_horizontal > 0
call map(dlist, 'v:val[world.offset_horizontal:-1]') call map(dlist, 'tlib#string#Strcharpart(v:val, world.offset_horizontal)')
endif endif
" let time7 = str2float(reltimestr(reltime())) " DBG let time7 = str2float(reltimestr(reltime()))
" TLogVAR time7, time7 - time0 Tlibtrace 'tlib', time7, time7 - time0
" TLogVAR dindex
let dlist = map(range(0, world.llen - 1), 'printf("%0'. world.index_width .'d", dindex[v:val]) .": ". dlist[v:val]') let dlist = map(range(0, world.llen - 1), 'printf("%0'. world.index_width .'d", dindex[v:val]) .": ". dlist[v:val]')
" TLogVAR dlist let time8 = str2float(reltimestr(reltime()))
" let time8 = str2float(reltimestr(reltime())) " DBG Tlibtrace 'tlib', time8, time8 - time0
" TLogVAR time8, time8 - time0
else else
@ -505,30 +475,14 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.prefidx = 1 let world.prefidx = 1
endif endif
endif endif
" TLogVAR world.idx, world.prefidx Tlibtrace 'tlib', world.idx, world.prefidx
" TLogDBG 7 Tlibtrace 'tlib', world.prefidx, world.offset
" TLogVAR world.prefidx, world.offset Tlibtrace 'tlib', world.initial_display, !tlib#char#IsAvailable()
" TLogDBG (world.prefidx > world.offset + winheight(0) - 1)
" if world.prefidx > world.offset + winheight(0) - 1
" let listtop = world.llen - winheight(0) + 1
" let listoff = world.prefidx - winheight(0) + 1
" let world.offset = min([listtop, listoff])
" TLogVAR world.prefidx
" TLogDBG len(list)
" TLogDBG winheight(0)
" TLogVAR listtop, listoff, world.offset
" elseif world.prefidx < world.offset
" let world.offset = world.prefidx
" endif
" TLogDBG 8
" TLogVAR world.initial_display, !tlib#char#IsAvailable()
if world.state =~ '\<update\>' || world.initial_display || !tlib#char#IsAvailable() if world.state =~ '\<update\>' || world.initial_display || !tlib#char#IsAvailable()
" TLogDBG len(dlist)
call world.DisplayList(world.Query(), dlist) call world.DisplayList(world.Query(), dlist)
call world.FollowCursor() call world.FollowCursor()
let world.initial_display = 0 let world.initial_display = 0
" TLogDBG 9
endif endif
if world.state =~ '\<hibernate\>' if world.state =~ '\<hibernate\>'
let world.state = 'suspend' let world.state = 'suspend'
@ -548,9 +502,10 @@ function! tlib#input#ListW(world, ...) "{{{3
endif endif
endif endif
" TAssert IsNotEmpty(world.scratch) " TAssert IsNotEmpty(world.scratch)
let world.list_wid = tlib#win#GetID()
let world.list_wnr = winnr() let world.list_wnr = winnr()
" TLogVAR world.state, world.next_state Tlibtrace 'tlib', world.state, world.next_state
if !empty(world.next_state) if !empty(world.next_state)
let world.state = world.next_state let world.state = world.next_state
let world.next_state = '' let world.next_state = ''
@ -568,7 +523,7 @@ function! tlib#input#ListW(world, ...) "{{{3
endif endif
if has('gui_win32') if has('gui_win32')
let exec_cmd = input(query, '') let exec_cmd = input(query, '')
" TLogVAR exec_cmd Tlibtrace 'tlib', exec_cmd
if exec_cmd == '' if exec_cmd == ''
let world.state = 'redisplay' let world.state = 'redisplay'
else else
@ -576,17 +531,15 @@ function! tlib#input#ListW(world, ...) "{{{3
endif endif
elseif has('gui_gtk') || has('gui_gtk2') elseif has('gui_gtk') || has('gui_gtk2')
let c = s:GetModdedChar(world) let c = s:GetModdedChar(world)
" TLogVAR c Tlibtrace 'tlib', c
endif endif
else else
" TLogVAR world.timeout Tlibtrace 'tlib', world.timeout
let c = s:GetModdedChar(world) let c = s:GetModdedChar(world)
" TLogVAR c, has_key(world.key_map[world.key_mode],c) Tlibtrace 'tlib', c, has_key(world.key_map[world.key_mode],c)
endif endif
" TLogVAR c Tlibtrace 'tlib', c
" TLogDBG string(sort(keys(world.key_map[world.key_mode]))) Tlibtrace 'tlib', world.next_agent, world.next_eval
" TLogVAR world.next_agent, world.next_eval
if !empty(world.next_agent) if !empty(world.next_agent)
let nagent = world.next_agent let nagent = world.next_agent
let world.next_agent = '' let world.next_agent = ''
@ -604,19 +557,17 @@ function! tlib#input#ListW(world, ...) "{{{3
elseif has_key(world.key_map[world.key_mode], c) elseif has_key(world.key_map[world.key_mode], c)
let sr = @/ let sr = @/
silent! let @/ = lastsearch silent! let @/ = lastsearch
" TLogVAR c, world.key_map[world.key_mode][c] Tlibtrace 'tlib', c, world.key_map[world.key_mode][c]
" TLog "Agent: ". string(world.key_map[world.key_mode][c]) " TLog "Agent: ". string(world.key_map[world.key_mode][c])
let handler = world.key_map[world.key_mode][c] let handler = world.key_map[world.key_mode][c]
" " TLogVAR handler Tlibtrace 'tlib', handler
" let world = call(handler.agent, [world, world.GetSelectedItems(world.CurrentItem())])
" call s:CheckAgentReturnValue(c, world)
let world = s:CallAgent(handler, world, world.GetSelectedItems(world.CurrentItem())) let world = s:CallAgent(handler, world, world.GetSelectedItems(world.CurrentItem()))
silent! let @/ = sr silent! let @/ = sr
" continue " continue
elseif c == 13 elseif c == 13
throw 'pick' throw 'pick'
elseif c == 27 elseif c == 27
" TLogVAR c, world.key_mode Tlibtrace 'tlib', c, world.key_mode
if world.key_mode != 'default' if world.key_mode != 'default'
let world.key_mode = 'default' let world.key_mode = 'default'
let world.state = 'redisplay' let world.state = 'redisplay'
@ -666,7 +617,7 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.state = 'exit empty' let world.state = 'exit empty'
endif endif
endif endif
" TLogVAR world.prefidx, world.state Tlibtrace 'tlib', world.prefidx, world.state
elseif has_key(world.key_map[world.key_mode], 'unknown_key') elseif has_key(world.key_map[world.key_mode], 'unknown_key')
let agent = world.key_map[world.key_mode].unknown_key.agent let agent = world.key_map[world.key_mode].unknown_key.agent
" let world = call(agent, [world, c]) " let world = call(agent, [world, c])
@ -675,17 +626,17 @@ function! tlib#input#ListW(world, ...) "{{{3
elseif c >= 32 elseif c >= 32
let world.state = 'display' let world.state = 'display'
let numbase = get(world.numeric_chars, c, -99999) let numbase = get(world.numeric_chars, c, -99999)
" TLogVAR numbase, world.numeric_chars, c Tlibtrace 'tlib', numbase, world.numeric_chars, c
if numbase != -99999 if numbase != -99999
let world.idx .= (c - numbase) let world.idx .= (c - numbase)
if len(world.idx) == world.index_width if len(world.idx) == world.index_width
let world.prefidx = world.idx let world.prefidx = world.idx
" TLogVAR world.prefidx Tlibtrace 'tlib', world.prefidx
throw 'pick' throw 'pick'
endif endif
else else
let world.idx = '' let world.idx = ''
" TLogVAR world.filter Tlibtrace 'tlib', world.filter
if world.llen > g:tlib#input#livesearch_threshold if world.llen > g:tlib#input#livesearch_threshold
let pattern = input('Filter: ', world.CleanFilter(world.filter[0][0]) . nr2char(c)) let pattern = input('Filter: ', world.CleanFilter(world.filter[0][0]) . nr2char(c))
if empty(pattern) if empty(pattern)
@ -718,61 +669,50 @@ function! tlib#input#ListW(world, ...) "{{{3
call world.ClearAllMarks() call world.ClearAllMarks()
call world.MarkCurrent(world.prefidx) call world.MarkCurrent(world.prefidx)
let world.state = '' let world.state = ''
" TLogDBG 'Pick item #'. world.prefidx
finally finally
" TLogDBG 'finally 1', world.state
if world.state =~ '\<suspend\>' if world.state =~ '\<suspend\>'
" if !world.allow_suspend " if !world.allow_suspend
" echom "Cannot be suspended" " echom "Cannot be suspended"
" let world.state = 'redisplay' " let world.state = 'redisplay'
" endif " endif
elseif !empty(world.list) && !empty(world.base) elseif !empty(world.list) && !empty(world.base)
" TLogVAR world.list
if empty(world.state) if empty(world.state)
let world.rv = world.CurrentItem() let world.rv = world.CurrentItem()
" TLogVAR world.state, world.rv Tlibtrace 'tlib', world.state, world.rv
endif endif
" TLogVAR "postprocess"
for handler in world.post_handlers for handler in world.post_handlers
let state = get(handler, 'postprocess', '') let state = get(handler, 'postprocess', '')
" TLogVAR handler Tlibtrace 'tlib', handler
" TLogVAR state Tlibtrace 'tlib', state
" TLogVAR world.state Tlibtrace 'tlib', world.state
if state == world.state if state == world.state
let agent = handler.agent let agent = handler.agent
let [world, world.rv] = call(agent, [world, world.rv]) let [world, world.rv] = call(agent, [world, world.rv])
" TLogVAR world.state, world.rv Tlibtrace 'tlib', world.state, world.rv
call s:CheckAgentReturnValue(agent, world) call s:CheckAgentReturnValue(agent, world)
endif endif
endfor endfor
endif endif
" TLogDBG 'state0='. world.state
endtry endtry
" TLogDBG 'state1='. world.state
endwh endwh
" TLogVAR world.state Tlibtrace 'tlib', world.state
" TLogDBG string(tlib#win#List()) Tlibtrace 'tlib', len(world.list)
" TLogDBG 'exit while loop' Tlibtrace 'tlib', world.sel_idx
" TLogVAR world.list Tlibtrace 'tlib', world.idx
" TLogVAR world.sel_idx Tlibtrace 'tlib', world.prefidx
" TLogVAR world.idx Tlibtrace 'tlib', world.rv
" TLogVAR world.prefidx
" TLogVAR world.rv
" TLogVAR world.type, world.state, world.return_agent, world.index_table, world.rv
if world.state =~ '\<\(empty\|escape\)\>' if world.state =~ '\<\(empty\|escape\)\>'
let world.sticky = 0 let world.sticky = 0
endif endif
if world.state =~ '\<suspend\>' if world.state =~ '\<suspend\>'
" TLogDBG 'return suspended' Tlibtrace 'tlib', world.prefidx
" TLogVAR world.prefidx
" exec world.prefidx " exec world.prefidx
return return
elseif world.state =~ '\<empty\>' elseif world.state =~ '\<empty\>'
" TLog "empty" " TLog "empty"
" TLogDBG 'return empty' Tlibtrace 'tlib', world.type
" TLogVAR world.type
if stridx(world.type, 'm') != -1 if stridx(world.type, 'm') != -1
return [] return []
elseif stridx(world.type, 'i') != -1 elseif stridx(world.type, 'i') != -1
@ -781,23 +721,18 @@ function! tlib#input#ListW(world, ...) "{{{3
return '' return ''
endif endif
elseif !empty(world.return_agent) elseif !empty(world.return_agent)
" TLogDBG 'return agent' Tlibtrace 'tlib', world.return_agent
" TLogVAR world.return_agent call world.CloseScratch(1)
call world.CloseScratch()
" TLogDBG "return_agent ". string(tlib#win#List())
" TAssert IsNotEmpty(world.scratch) " TAssert IsNotEmpty(world.scratch)
return call(world.return_agent, [world, world.GetSelectedItems(world.rv)]) return call(world.return_agent, [world, world.GetSelectedItems(world.rv)])
elseif stridx(world.type, 'w') != -1 elseif stridx(world.type, 'w') != -1
" TLog "return_world" " TLog "return_world"
" TLogDBG 'return world'
return world return world
elseif stridx(world.type, 'm') != -1 elseif stridx(world.type, 'm') != -1
" TLog "return_multi" " TLog "return_multi"
" TLogDBG 'return multi'
return world.GetSelectedItems(world.rv) return world.GetSelectedItems(world.rv)
elseif stridx(world.type, 'i') != -1 elseif stridx(world.type, 'i') != -1
" TLog "return_index" " TLog "return_index"
" TLogDBG 'return index'
if empty(world.index_table) if empty(world.index_table)
return world.rv return world.rv
else else
@ -805,14 +740,13 @@ function! tlib#input#ListW(world, ...) "{{{3
endif endif
else else
" TLog "return_else" " TLog "return_else"
" TLogDBG 'return normal'
return world.rv return world.rv
endif endif
finally finally
call world.Leave() call world.Leave()
" TLogVAR statusline " Tlibtrace 'tlib', statusline
" let &l:statusline = statusline " let &l:statusline = statusline
" let &laststatus = laststatus " let &laststatus = laststatus
if &showmode != showmode if &showmode != showmode
@ -824,42 +758,39 @@ function! tlib#input#ListW(world, ...) "{{{3
silent! aunmenu ]TLibInputListPopupMenu silent! aunmenu ]TLibInputListPopupMenu
endif endif
" TLogDBG 'finally 2' Tlibtrace 'tlib', world.state
" TLogDBG string(world.Methods())
" TLogVAR world.state
" TLogDBG string(tlib#win#List())
if world.state !~ '\<suspend\>' if world.state !~ '\<suspend\>'
" redraw " redraw
" TLogVAR world.sticky, bufnr("%") Tlibtrace 'tlib', world.sticky, bufnr("%")
if world.sticky if world.sticky
" TLogDBG "sticky" Tlibtrace 'tlib', world.bufnr
" TLogVAR world.bufnr
" TLogDBG bufwinnr(world.bufnr)
if world.scratch_split > 0 if world.scratch_split > 0
if bufwinnr(world.bufnr) == -1 if bufwinnr(world.bufnr) == -1
" TLogDBG "UseScratch"
call world.UseScratch() call world.UseScratch()
endif endif
let world = tlib#agent#SuspendToParentWindow(world, world.GetSelectedItems(world.rv)) let world = tlib#agent#SuspendToParentWindow(world, world.GetSelectedItems(world.rv))
endif endif
else else
" TLogDBG "non sticky" Tlibtrace 'tlib', world.state, world.win_id, world.bufnr
" TLogVAR world.state, world.win_wnr, world.bufnr if world.CloseScratch(1)
if world.CloseScratch() Tlibtrace 'tlib', get(world,'winview','')
" TLogVAR world.winview
call tlib#win#SetLayout(world.winview) call tlib#win#SetLayout(world.winview)
endif endif
endif endif
endif endif
if world.state !~ '\<norestore\>'
call world.RestoreWindow()
endif
" for i in range(0,5) " for i in range(0,5)
" call getchar(0) " call getchar(0)
" endfor " endfor
echo echo
redraw! redraw!
if !empty(post_keys) if !empty(post_keys)
" TLogVAR post_keys Tlibtrace 'tlib', post_keys
call feedkeys(post_keys) call feedkeys(post_keys)
endif endif
let world.state = ''
endtry endtry
endf endf
@ -871,7 +802,7 @@ function! s:CallAgent(handler, world, list) abort "{{{3
let args += a:handler.args let args += a:handler.args
endif endif
let world = call(agent, args) let world = call(agent, args)
" TLogVAR world.state, world.rv Tlibtrace 'tlib', world.state, world.rv
call s:CheckAgentReturnValue(agent, world) call s:CheckAgentReturnValue(agent, world)
return world return world
endf endf
@ -887,7 +818,7 @@ endf
function! s:Init(world, cmd) "{{{3 function! s:Init(world, cmd) "{{{3
" TLogVAR a:cmd Tlibtrace 'tlib', a:cmd
let a:world.initial_display = 1 let a:world.initial_display = 1
if a:cmd =~ '\<sticky\>' if a:cmd =~ '\<sticky\>'
let a:world.sticky = 1 let a:world.sticky = 1
@ -905,7 +836,7 @@ function! s:Init(world, cmd) "{{{3
" let a:world.state = a:world.resume_state " let a:world.state = a:world.resume_state
" endif " endif
elseif !a:world.initialized elseif !a:world.initialized
" TLogVAR a:world.initialized, a:world.win_wnr, a:world.bufnr Tlibtrace 'tlib', a:world.initialized, a:world.win_id, a:world.bufnr
let a:world.filetype = &filetype let a:world.filetype = &filetype
let a:world.fileencoding = &fileencoding let a:world.fileencoding = &fileencoding
call a:world.SetMatchMode(tlib#var#Get('tlib#input#filter_mode', 'wb')) call a:world.SetMatchMode(tlib#var#Get('tlib#input#filter_mode', 'wb'))
@ -913,9 +844,9 @@ function! s:Init(world, cmd) "{{{3
if !has_key(a:world, 'key_mode') if !has_key(a:world, 'key_mode')
let a:world.key_mode = 'default' let a:world.key_mode = 'default'
endif endif
" TLogVAR has_key(a:world,'key_map') Tlibtrace 'tlib', has_key(a:world,'key_map')
if has_key(a:world, 'key_map') if has_key(a:world, 'key_map')
" TLogVAR has_key(a:world.key_map,a:world.key_mode) Tlibtrace 'tlib', has_key(a:world.key_map,a:world.key_mode)
if has_key(a:world.key_map, a:world.key_mode) if has_key(a:world.key_map, a:world.key_mode)
let a:world.key_map[a:world.key_mode] = extend( let a:world.key_map[a:world.key_mode] = extend(
\ a:world.key_map[a:world.key_mode], \ a:world.key_map[a:world.key_mode],
@ -929,14 +860,14 @@ function! s:Init(world, cmd) "{{{3
\ a:world.key_mode : copy(g:tlib#input#keyagents_InputList_s) \ a:world.key_mode : copy(g:tlib#input#keyagents_InputList_s)
\ } \ }
endif endif
" TLogVAR a:world.type Tlibtrace 'tlib', a:world.type
if stridx(a:world.type, 'm') != -1 if stridx(a:world.type, 'm') != -1
call extend(a:world.key_map[a:world.key_mode], g:tlib#input#keyagents_InputList_m, 'force') call extend(a:world.key_map[a:world.key_mode], g:tlib#input#keyagents_InputList_m, 'force')
endif endif
for key_mode in keys(a:world.key_map) for key_mode in keys(a:world.key_map)
let a:world.key_map[key_mode] = map(a:world.key_map[key_mode], 'type(v:val) == 4 ? v:val : {"agent": v:val}') let a:world.key_map[key_mode] = map(a:world.key_map[key_mode], 'type(v:val) == 4 ? v:val : {"agent": v:val}')
endfor endfor
" TLogVAR a:world.key_mode Tlibtrace 'tlib', a:world.key_mode
if type(a:world.key_handlers) == 3 if type(a:world.key_handlers) == 3
call s:ExtendKeyMap(a:world, a:world.key_mode, a:world.key_handlers) call s:ExtendKeyMap(a:world, a:world.key_mode, a:world.key_handlers)
elseif type(a:world.key_handlers) == 4 elseif type(a:world.key_handlers) == 4
@ -946,12 +877,12 @@ function! s:Init(world, cmd) "{{{3
else else
throw "tlib#input#ListW: key_handlers must be either a list or a dictionary" throw "tlib#input#ListW: key_handlers must be either a list or a dictionary"
endif endif
" TLogVAR a:world.type, a:world.key_map Tlibtrace 'tlib', a:world.type, a:world.key_map
if !empty(a:cmd) if !empty(a:cmd)
let a:world.state .= ' '. a:cmd let a:world.state .= ' '. a:cmd
endif endif
endif endif
" TLogVAR a:world.state, a:world.sticky Tlibtrace 'tlib', a:world.state, a:world.sticky
endf endf
@ -979,7 +910,7 @@ function! s:PopupmenuExists()
let rv = 0 let rv = 0
endtry endtry
endif endif
" TLogVAR rv Tlibtrace 'tlib', rv
return rv return rv
endf endf
@ -1144,9 +1075,9 @@ function! tlib#input#EditList(query, list, ...) "{{{3
let handlers = a:0 >= 1 && !empty(a:1) ? a:1 : g:tlib#input#handlers_EditList let handlers = a:0 >= 1 && !empty(a:1) ? a:1 : g:tlib#input#handlers_EditList
let default = a:0 >= 2 ? a:2 : [] let default = a:0 >= 2 ? a:2 : []
let timeout = a:0 >= 3 ? a:3 : 0 let timeout = a:0 >= 3 ? a:3 : 0
" TLogVAR handlers Tlibtrace 'tlib', handlers
let rv = tlib#input#List('me', a:query, copy(a:list), handlers, default, timeout) let rv = tlib#input#List('me', a:query, copy(a:list), handlers, default, timeout)
" TLogVAR rv Tlibtrace 'tlib', rv
if empty(rv) if empty(rv)
return a:list return a:list
else else
@ -1157,7 +1088,7 @@ endf
function! tlib#input#Resume(name, pick, bufnr) "{{{3 function! tlib#input#Resume(name, pick, bufnr) "{{{3
" TLogVAR a:name, a:pick Tlibtrace 'tlib', a:name, a:pick
echo echo
if bufnr('%') != a:bufnr if bufnr('%') != a:bufnr
if g:tlib#debug if g:tlib#debug
@ -1182,10 +1113,8 @@ function! tlib#input#Resume(name, pick, bufnr) "{{{3
else else
call tlib#autocmdgroup#Init() call tlib#autocmdgroup#Init()
autocmd! TLib BufEnter <buffer> autocmd! TLib BufEnter <buffer>
if b:tlib_{a:name}.state =~ '\<suspend\>' if b:tlib_{a:name}.state !~# 'display\>'
let b:tlib_{a:name}.state = 'redisplay' let b:tlib_{a:name}.state = 'redisplay'
else
let b:tlib_{a:name}.state .= ' redisplay'
endif endif
" call tlib#input#List('resume '. a:name) " call tlib#input#List('resume '. a:name)
let cmd = 'resume '. a:name let cmd = 'resume '. a:name
@ -1245,24 +1174,25 @@ endf
" endif " endif
" endf " endf
" call tlib#input#Edit('foo', b:var, 'FooContinue') " call tlib#input#Edit('foo', b:var, 'FooContinue')
function! tlib#input#Edit(name, value, callback, ...) "{{{3 function! tlib#input#EditW(world, name, value, callback, ...) "{{{3
" TLogVAR a:value Tlibtrace 'tlib', a:value
TVarArg ['args', []] TVarArg ['args', []]
let sargs = {'scratch': '__EDIT__'. a:name .'__', 'win_wnr': winnr()} let sargs = {'scratch': '__EDIT__'. a:name .'__', 'win_id': tlib#win#GetID()}
let scr = tlib#scratch#UseScratch(sargs) let scr = tlib#scratch#UseScratch(sargs)
let b:tlib_world = a:world
" :nodoc: " :nodoc:
map <buffer> <c-w>c :call <SID>EditCallback(0)<cr> map <buffer> <c-w>c :call tlib#input#EditCallback(0)<cr>
" :nodoc: " :nodoc:
imap <buffer> <c-w>c <c-o>call <SID>EditCallback(0)<cr> imap <buffer> <c-w>c <c-o>call tlib#input#EditCallback(0)<cr>
" :nodoc: " :nodoc:
map <buffer> <c-s> :call <SID>EditCallback(1)<cr> map <buffer> <c-s> :call tlib#input#EditCallback(1)<cr>
" :nodoc: " :nodoc:
imap <buffer> <c-s> <c-o>call <SID>EditCallback(1)<cr> imap <buffer> <c-s> <c-o>call tlib#input#EditCallback(1)<cr>
" :nodoc: " :nodoc:
map <buffer> <c-w><cr> :call <SID>EditCallback(1)<cr> map <buffer> <c-w><cr> :call tlib#input#EditCallback(1)<cr>
" :nodoc: " :nodoc:
imap <buffer> <c-w><cr> <c-o>call <SID>EditCallback(1)<cr> imap <buffer> <c-w><cr> <c-o>call tlib#input#EditCallback(1)<cr>
call tlib#normal#WithRegister('gg"tdG', 't') call tlib#normal#WithRegister('gg"tdG', 't')
call append(1, split(a:value, "\<c-j>", 1)) call append(1, split(a:value, "\<c-j>", 1))
@ -1285,14 +1215,17 @@ function! tlib#input#Edit(name, value, callback, ...) "{{{3
endif endif
let b:tlib_scratch_edit_args = args let b:tlib_scratch_edit_args = args
let b:tlib_scratch_edit_scratch = sargs let b:tlib_scratch_edit_scratch = sargs
" exec 'autocmd BufDelete,BufHidden,BufUnload <buffer> call s:EditCallback('. string(a:name) .')' " exec 'autocmd BufDelete,BufHidden,BufUnload <buffer> call tlib#input#EditCallback('. string(a:name) .')'
" echohl MoreMsg " echohl MoreMsg
" echom 'Press <c-s> to enter, <c-w>c to cancel editing.' " echom 'Press <c-s> to enter, <c-w>c to cancel editing.'
" echohl NONE " echohl NONE
let world = getbufvar(scr, 'tlib_world', a:world)
let world.state .= ' norestore'
return world
endf endf
function! s:EditCallback(...) "{{{3 function! tlib#input#EditCallback(...) "{{{3
TVarArg ['ok', -1] TVarArg ['ok', -1]
" , ['bufnr', -1] " , ['bufnr', -1]
" autocmd! BufDelete,BufHidden,BufUnload <buffer> " autocmd! BufDelete,BufHidden,BufUnload <buffer>
@ -1304,10 +1237,11 @@ function! s:EditCallback(...) "{{{3
let cb = b:tlib_scratch_edit_callback let cb = b:tlib_scratch_edit_callback
let args = b:tlib_scratch_edit_args let args = b:tlib_scratch_edit_args
let sargs = b:tlib_scratch_edit_scratch let sargs = b:tlib_scratch_edit_scratch
" TLogVAR cb, args, sargs let world = b:tlib_world
Tlibtrace 'tlib', cb, args, sargs
call call(cb, args + [ok, text, world])
call tlib#scratch#CloseScratch(b:tlib_scratch_edit_scratch) call tlib#scratch#CloseScratch(b:tlib_scratch_edit_scratch)
call tlib#win#Set(sargs.win_wnr) call tlib#win#SetById(sargs.win_id)
call call(cb, args + [ok, text])
endf endf

View file

@ -3,18 +3,18 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30. " @Created: 2007-06-30.
" @Last Change: 2015-10-21. " @Last Change: 2017-03-26.
" @Revision: 61 " @Revision: 71
""" List related functions {{{1 """ List related functions {{{1
" For the following functions please see ../../test/tlib.vim for examples. " For the following functions please see ../../test/tlib.vim for examples.
" :def: function! tlib#list#Inject(list, initial_value, funcref) " :def: function! tlib#list#Inject(list, initial_value, funcref) abort
" EXAMPLES: > " EXAMPLES: >
" echo tlib#list#Inject([1,2,3], 0, function('Add') " echo tlib#list#Inject([1,2,3], 0, function('Add')
" => 6 " => 6
function! tlib#list#Inject(list, value, Function) "{{{3 function! tlib#list#Inject(list, value, Function) abort "{{{3
if empty(a:list) if empty(a:list)
return a:value return a:value
else else
@ -29,7 +29,7 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#list#Compact([0,1,2,3,[], {}, ""]) " tlib#list#Compact([0,1,2,3,[], {}, ""])
" => [1,2,3] " => [1,2,3]
function! tlib#list#Compact(list) "{{{3 function! tlib#list#Compact(list) abort "{{{3
return filter(copy(a:list), '!empty(v:val)') return filter(copy(a:list), '!empty(v:val)')
endf endf
@ -37,7 +37,7 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#list#Flatten([0,[1,2,[3,""]]]) " tlib#list#Flatten([0,[1,2,[3,""]]])
" => [0,1,2,3,""] " => [0,1,2,3,""]
function! tlib#list#Flatten(list) "{{{3 function! tlib#list#Flatten(list) abort "{{{3
let acc = [] let acc = []
for e in a:list for e in a:list
if type(e) == 3 if type(e) == 3
@ -51,27 +51,27 @@ function! tlib#list#Flatten(list) "{{{3
endf endf
" :def: function! tlib#list#FindAll(list, filter, ?process_expr="") " :def: function! tlib#list#FindAll(list, filter, ?process_expr="") abort
" Basically the same as filter() " Basically the same as filter()
" "
" EXAMPLES: > " EXAMPLES: >
" tlib#list#FindAll([1,2,3], 'v:val >= 2') " tlib#list#FindAll([1,2,3], 'v:val >= 2')
" => [2, 3] " => [2, 3]
function! tlib#list#FindAll(list, filter, ...) "{{{3 function! tlib#list#FindAll(list, filter, ...) abort "{{{3
let rv = filter(copy(a:list), a:filter) let rv = filter(copy(a:list), a:filter)
if a:0 >= 1 && a:1 != '' if a:0 >= 1 && !empty(a:1)
let rv = map(rv, a:1) let rv = map(rv, a:1)
endif endif
return rv return rv
endf endf
" :def: function! tlib#list#Find(list, filter, ?default="", ?process_expr="") " :def: function! tlib#list#Find(list, filter, ?default="", ?process_expr="") abort
" "
" EXAMPLES: > " EXAMPLES: >
" tlib#list#Find([1,2,3], 'v:val >= 2') " tlib#list#Find([1,2,3], 'v:val >= 2')
" => 2 " => 2
function! tlib#list#Find(list, filter, ...) "{{{3 function! tlib#list#Find(list, filter, ...) abort "{{{3
let default = a:0 >= 1 ? a:1 : '' let default = a:0 >= 1 ? a:1 : ''
let expr = a:0 >= 2 ? a:2 : '' let expr = a:0 >= 2 ? a:2 : ''
return get(tlib#list#FindAll(a:list, a:filter, expr), 0, default) return get(tlib#list#FindAll(a:list, a:filter, expr), 0, default)
@ -81,7 +81,7 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#list#Any([1,2,3], 'v:val >= 2') " tlib#list#Any([1,2,3], 'v:val >= 2')
" => 1 " => 1
function! tlib#list#Any(list, expr) "{{{3 function! tlib#list#Any(list, expr) abort "{{{3
return !empty(tlib#list#FindAll(a:list, a:expr)) return !empty(tlib#list#FindAll(a:list, a:expr))
endf endf
@ -89,7 +89,7 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#list#All([1,2,3], 'v:val >= 2') " tlib#list#All([1,2,3], 'v:val >= 2')
" => 0 " => 0
function! tlib#list#All(list, expr) "{{{3 function! tlib#list#All(list, expr) abort "{{{3
return len(tlib#list#FindAll(a:list, a:expr)) == len(a:list) return len(tlib#list#FindAll(a:list, a:expr)) == len(a:list)
endf endf
@ -97,7 +97,7 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#list#Remove([1,2,1,2], 2) " tlib#list#Remove([1,2,1,2], 2)
" => [1,1,2] " => [1,1,2]
function! tlib#list#Remove(list, element) "{{{3 function! tlib#list#Remove(list, element) abort "{{{3
let idx = index(a:list, a:element) let idx = index(a:list, a:element)
if idx != -1 if idx != -1
call remove(a:list, idx) call remove(a:list, idx)
@ -109,17 +109,17 @@ endf
" EXAMPLES: > " EXAMPLES: >
" tlib#list#RemoveAll([1,2,1,2], 2) " tlib#list#RemoveAll([1,2,1,2], 2)
" => [1,1] " => [1,1]
function! tlib#list#RemoveAll(list, element) "{{{3 function! tlib#list#RemoveAll(list, element) abort "{{{3
call filter(a:list, 'v:val != a:element') call filter(a:list, 'v:val != a:element')
return a:list return a:list
endf endf
" :def: function! tlib#list#Zip(lists, ?default='') " :def: function! tlib#list#Zip(lists, ?default='') abort
" EXAMPLES: > " EXAMPLES: >
" tlib#list#Zip([[1,2,3], [4,5,6]]) " tlib#list#Zip([[1,2,3], [4,5,6]])
" => [[1,4], [2,5], [3,6]] " => [[1,4], [2,5], [3,6]]
function! tlib#list#Zip(lists, ...) "{{{3 function! tlib#list#Zip(lists, ...) abort "{{{3
TVarArg 'default' TVarArg 'default'
let lists = copy(a:lists) let lists = copy(a:lists)
let max = 0 let max = 0
@ -133,24 +133,30 @@ function! tlib#list#Zip(lists, ...) "{{{3
return map(range(0, max - 1), 's:GetNthElement(v:val, lists, default)') return map(range(0, max - 1), 's:GetNthElement(v:val, lists, default)')
endf endf
function! s:GetNthElement(n, lists, default) "{{{3 function! s:GetNthElement(n, lists, default) abort "{{{3
" TLogVAR a:n, a:lists, a:default " TLogVAR a:n, a:lists, a:default
return map(copy(a:lists), 'get(v:val, a:n, a:default)') return map(copy(a:lists), 'get(v:val, a:n, a:default)')
endf endf
function! tlib#list#Uniq(list, ...) "{{{3 function! tlib#list#Uniq(list, ...) abort "{{{3
" TLogVAR a:list " TLogVAR a:list
TVarArg ['get_value', ''], ['remove_empty', 0] TVarArg ['get_value', ''], ['remove_empty', 0]
if remove_empty if remove_empty
call filter(a:list, 'type(v:val) == 0 || !empty(v:val)') call filter(a:list, 'type(v:val) == 0 || !empty(v:val)')
endif endif
" CREDITS: Based on syntastic#util#unique(list) by scrooloose " CREDITS: Based on syntastic#util#unique(list) by scrooloose
let emptystring = 0
let seen = {} let seen = {}
let uniques = [] let uniques = []
if empty(get_value) if empty(get_value)
for e in a:list for e in a:list
if !has_key(seen, e) if empty(e)
if !emptystring
let emptystring = 1
call add(uniques, e)
endif
elseif !has_key(seen, e)
let seen[e] = 1 let seen[e] = 1
call add(uniques, e) call add(uniques, e)
endif endif
@ -159,18 +165,23 @@ function! tlib#list#Uniq(list, ...) "{{{3
else else
for e in a:list for e in a:list
let v = eval(printf(get_value, string(e))) let v = eval(printf(get_value, string(e)))
if !has_key(seen, v) if empty(v)
if !emptystring
let emptystring = 1
call add(uniques, v)
endif
elseif !has_key(seen, v)
let seen[v] = 1 let seen[v] = 1
call add(uniques, e) call add(uniques, v)
endif endif
unlet e unlet e v
endfor endfor
endif endif
return uniques return uniques
endf endf
function! tlib#list#ToDictionary(list, default, ...) "{{{3 function! tlib#list#ToDictionary(list, default, ...) abort "{{{3
TVarArg ['generator', ''] TVarArg ['generator', '']
let dict = {} let dict = {}
for item in a:list for item in a:list

View file

@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2008-09-19. " @Created: 2008-09-19.
" @Last Change: 2015-04-07. " @Last Change: 2017-09-28.
" @Revision: 0.3.19 " @Revision: 3.3.19
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
@ -24,7 +24,7 @@ function! tlib#notify#Echo(text, ...)
if !empty(style) if !empty(style)
exec 'echohl' style exec 'echohl' style
endif endif
echo strpart(text, 0, &columns - 1) echo tlib#string#Strcharpart(text, 0, &columns - 1)
finally finally
if !empty(style) if !empty(style)
echohl None echohl None
@ -93,13 +93,21 @@ function! tlib#notify#TrimMessage(message) "{{{3
let front = to_fill / 2 - 1 let front = to_fill / 2 - 1
let back = front let back = front
if to_fill % 2 == 0 | let back -= 1 | endif if to_fill % 2 == 0 | let back -= 1 | endif
return strpart(a:message, 0, front) . filler . return tlib#string#Strcharpart(a:message, 0, front) . filler .
\strpart(a:message, strlen(a:message) - back) \ tlib#string#Strcharpart(a:message, strlen(a:message) - back)
else else
return a:message return a:message
endif endif
endfunction endfunction
function! tlib#notify#PrintError() abort "{{{3
echohl ErrorMsg
echom v:exception
echom v:throwpoint
echohl NONE
endf
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo

View file

@ -1,22 +1,21 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 14 " @Revision: 18
function! tlib#number#ConvertBase(num, base, ...) "{{{3 function! tlib#number#ConvertBase(num, base, ...) "{{{3
let rtype = a:0 >= 1 ? a:1 : 'string' let rtype = a:0 >= 1 ? a:1 : 'string'
if a:base > 36
throw 'tlib#number#ConvertBase: base > 36 is not supported'
endif
" TLogVAR a:num, a:base, rtype " TLogVAR a:num, a:base, rtype
let rv = [] let rv = []
let num = 0.0 + a:num let num = 0.0 + a:num
let chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while floor(num) > 0.0 while floor(num) > 0.0
let div = floor(num / a:base) let div = floor(num / a:base)
let num1 = float2nr(num - a:base * div) let num1 = float2nr(num - a:base * div)
if a:base <= 10 call insert(rv, chars[num1])
call insert(rv, num1)
elseif a:base == 16
let char = "0123456789ABCDEF"[num1]
call insert(rv, char)
endif
let num = num / a:base let num = num / a:base
endwh endwh
" TLogVAR rv " TLogVAR rv

View file

@ -2,8 +2,8 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2012-05-11. " @Created: 2012-05-11.
" @Last Change: 2012-05-11. " @Last Change: 2017-03-29.
" @Revision: 12 " @Revision: 15
" The directory for persistent data files. If empty, use " The directory for persistent data files. If empty, use
" |tlib#dir#MyRuntime|.'/share'. " |tlib#dir#MyRuntime|.'/share'.
@ -21,6 +21,13 @@ function! tlib#persistent#Dir() "{{{3
return dir return dir
endf endf
" :display: tlib#persistent#EncodedFilename(type, file, ?mkdir=0, ?dir='')
" Encode `file` and call |tlib#persistent#Filename()|.
function! tlib#persistent#EncodedFilename(type, file, ...) "{{{3
let file = tlib#url#Encode(a:file)
return call(function('tlib#persistent#Filename'), [a:type, file] + a:000)
endf
" :def: function! tlib#persistent#Filename(type, ?file=%, ?mkdir=0) " :def: function! tlib#persistent#Filename(type, ?file=%, ?mkdir=0)
function! tlib#persistent#Filename(type, ...) "{{{3 function! tlib#persistent#Filename(type, ...) "{{{3
" TLogDBG 'bufname='. bufname('.') " TLogDBG 'bufname='. bufname('.')
@ -41,7 +48,7 @@ function! tlib#persistent#Value(...) "{{{3
return call('tlib#cache#Value', a:000) return call('tlib#cache#Value', a:000)
endf endf
function! tlib#persistent#Save(cfile, dictionary) "{{{3 function! tlib#persistent#Save(...) "{{{3
call tlib#cache#Save(a:cfile, a:dictionary) call call(function('tlib#cache#Save'), a:000)
endf endf

View file

@ -1,8 +1,10 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 72 " @Revision: 86
let s:id = 0
let s:ids = []
let s:statusline = [] let s:statusline = []
let s:laststatus = [] let s:laststatus = []
let s:max = [] let s:max = []
@ -23,14 +25,48 @@ let s:timestamp = -1
" endtry " endtry
function! tlib#progressbar#Init(max, ...) "{{{3 function! tlib#progressbar#Init(max, ...) "{{{3
TVarArg ['format', '%s'], ['width', 10] TVarArg ['format', '%s'], ['width', 10]
let s:id += 1
call insert(s:ids, s:id)
call insert(s:statusline, &statusline) call insert(s:statusline, &statusline)
call insert(s:laststatus, &laststatus) call insert(s:laststatus, &laststatus)
call insert(s:max, a:max) call insert(s:max, a:max)
call insert(s:format, format) call insert(s:format, format)
call insert(s:width, width) call insert(s:width, width)
call insert(s:value, -1) call insert(s:value, -1)
let sl = {
\ 'id': s:id,
\ 'statusline': &statusline,
\ 'laststatus': &laststatus,
\ 'max': a:max,
\ 'format': format,
\ 'width': width,
\ 'value': -1
\ }
let &laststatus = 2 let &laststatus = 2
let s:timestamp = localtime() let s:timestamp = localtime()
return sl
endf
function! tlib#progressbar#Restore(...) "{{{3
if a:0 >= 1
let sl = a:1
let idx = index(s:ids, sl.id)
let &statusline = sl.statusline
let &laststatus = sl.laststatus
else
let idx = 0
let &statusline = remove(s:statusline, idx)
let &laststatus = remove(s:laststatus, idx)
endif
call remove(s:ids, idx)
call remove(s:max, idx)
call remove(s:format, idx)
call remove(s:width, idx)
call remove(s:value, idx)
redrawstatus
" redraw
" echo
endf endf
@ -48,7 +84,7 @@ function! tlib#progressbar#Display(value, ...) "{{{3
let pbl = repeat('#', val) let pbl = repeat('#', val)
let pbr = repeat('.', s:width[0] - val) let pbr = repeat('.', s:width[0] - val)
let txt = printf(s:format[0], '['.pbl.pbr.']') . extra let txt = printf(s:format[0], '['.pbl.pbr.']') . extra
let &l:statusline = txt let &statusline = txt
" TLogDBG txt " TLogDBG txt
redrawstatus redrawstatus
" redraw " redraw
@ -57,16 +93,3 @@ function! tlib#progressbar#Display(value, ...) "{{{3
endf endf
function! tlib#progressbar#Restore() "{{{3
let &l:statusline = remove(s:statusline, 0)
let &laststatus = remove(s:laststatus, 0)
redrawstatus
" redraw
" echo
call remove(s:max, 0)
call remove(s:format, 0)
call remove(s:width, 0)
call remove(s:value, 0)
endf

View file

@ -1,8 +1,8 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: https://github.com/tomtom " @Website: https://github.com/tomtom
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2015-11-13 " @Last Change: 2018-02-08
" @Revision: 59 " @Revision: 69
" :nodoc: " :nodoc:
TLet g:tlib#qfl#world = { TLet g:tlib#qfl#world = {
@ -29,7 +29,10 @@ TLet g:tlib#qfl#world = {
function! tlib#qfl#FormatQFLE(qfe) dict abort "{{{3 function! tlib#qfl#FormatQFLE(qfe) dict abort "{{{3
let filename = tlib#qfl#QfeFilename(a:qfe) let filename = tlib#qfl#QfeFilename(a:qfe)
if get(self, 'qfl_short_filename', '') let short_filename = get(self, 'qfl_short_filename', '')
if short_filename ==# 'basename'
let filename = matchstr(filename, '[^\\/]\+$')
elseif !empty(short_filename)
let filename = pathshorten(filename) let filename = pathshorten(filename)
endif endif
return printf("%s|%d| %s", filename, a:qfe.lnum, get(a:qfe, "text")) return printf("%s|%d| %s", filename, a:qfe.lnum, get(a:qfe, "text"))
@ -119,11 +122,11 @@ endf
function! tlib#qfl#AgentEditQFE(world, selected, ...) "{{{3 function! tlib#qfl#AgentEditQFE(world, selected, ...) "{{{3
TVarArg ['cmd_edit', ''], ['cmd_buffer', ''] TVarArg ['cmd_edit', ''], ['cmd_buffer', ''], ['set_origin', 1]
" TVarArg ['cmd_edit', 'edit'], ['cmd_buffer', 'buffer'] " TVarArg ['cmd_edit', 'edit'], ['cmd_buffer', 'buffer']
" TLogVAR a:selected " TLogVAR a:selected
if empty(a:selected) if empty(a:selected)
call a:world.RestoreOrigin() " call a:world.RestoreOrigin()
" call a:world.ResetSelected() " call a:world.ResetSelected()
else else
call a:world.RestoreOrigin() call a:world.RestoreOrigin()
@ -148,11 +151,13 @@ function! tlib#qfl#AgentEditQFE(world, selected, ...) "{{{3
" TLogDBG bufname('%') " TLogDBG bufname('%')
" TLogVAR &filetype " TLogVAR &filetype
call tlib#buffer#ViewLine(qfe.lnum) call tlib#buffer#ViewLine(qfe.lnum)
" call a:world.SetOrigin()
" exec back " exec back
endif endif
endif endif
endfor endfor
if set_origin
call a:world.SetOrigin()
endif
endif endif
return a:world return a:world
endf endf
@ -161,7 +166,7 @@ endf
function! tlib#qfl#AgentPreviewQFE(world, selected) "{{{3 function! tlib#qfl#AgentPreviewQFE(world, selected) "{{{3
" TLogVAR a:selected " TLogVAR a:selected
let back = a:world.SwitchWindow('win') let back = a:world.SwitchWindow('win')
call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0]) call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0], '', '', 0)
exec back exec back
redraw redraw
let a:world.state = 'redisplay' let a:world.state = 'redisplay'
@ -170,14 +175,12 @@ endf
function! tlib#qfl#AgentGotoQFE(world, selected) "{{{3 function! tlib#qfl#AgentGotoQFE(world, selected) "{{{3
let world = a:world
if !empty(a:selected) if !empty(a:selected)
if a:world.win_wnr != winnr() let world = tlib#agent#Suspend(world, a:selected)
let world = tlib#agent#Suspend(a:world, a:selected) call tlib#qfl#AgentEditQFE(world, a:selected[0:0])
exec a:world.win_wnr .'wincmd w'
endif
call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0])
endif endif
return a:world return world
endf endf
@ -201,7 +204,7 @@ function! tlib#qfl#RunCmdOnSelected(world, selected, cmd, ...) "{{{3
" TLogVAR a:cmd " TLogVAR a:cmd
for entry in a:selected for entry in a:selected
" TLogVAR entry, a:world.GetBaseItem(entry) " TLogVAR entry, a:world.GetBaseItem(entry)
call tlib#qfl#AgentEditQFE(a:world, [entry]) call tlib#qfl#AgentEditQFE(a:world, [entry], '', '', 0)
" TLogDBG bufname('%') " TLogDBG bufname('%')
exec a:cmd exec a:cmd
" let item = a:world.data[a:world.GetBaseIdx(entry - 1)] " let item = a:world.data[a:world.GetBaseIdx(entry - 1)]

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 113 " @Revision: 114
" :def: function! tlib#rx#Escape(text, ?magic='m') " :def: function! tlib#rx#Escape(text, ?magic='m')
@ -30,13 +30,7 @@ endf
" Escape return |sub-replace-special|. " Escape return |sub-replace-special|.
function! tlib#rx#EscapeReplace(text, ...) "{{{3 function! tlib#rx#EscapeReplace(text, ...) "{{{3
TVarArg ['magic', 'm'] TVarArg ['magic', 'm']
if magic ==# 'm' || magic ==# 'v' return escape(a:text, '\&~')
return escape(a:text, '\&~')
elseif magic ==# 'M' || magic ==# 'V'
return escape(a:text, '\')
else
echoerr 'magic must be one of: m, v, M, V'
endif
endf endf

View file

@ -0,0 +1,40 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2017-09-28
" @Revision: 4
" :display: tlib#selection#GetSelection(mode, ?mbeg="'<", ?mend="'>", ?opmode='selection')
" mode can be one of: selection, lines, block
function! tlib#selection#GetSelection(mode, ...) range "{{{3
if a:0 >= 2
let mbeg = a:1
let mend = a:2
else
let mbeg = "'<"
let mend = "'>"
endif
let opmode = a:0 >= 3 ? a:3 : 'selection'
let l0 = line(mbeg)
let l1 = line(mend)
let text = getline(l0, l1)
let c0 = col(mbeg)
let c1 = col(mend)
" TLogVAR mbeg, mend, opmode, l0, l1, c0, c1
" TLogVAR text[-1]
" TLogVAR len(text[-1])
if opmode == 'block'
let clen = c1 - c0
call map(text, 'tlib#string#Strcharpart(v:val, c0, clen)')
elseif opmode == 'selection'
if c1 > 1
let text[-1] = tlib#string#Strcharpart(text[-1], 0, c1 - (a:mode == 'o' || c1 > len(text[-1]) ? 0 : 1))
endif
if c0 > 1
let text[0] = tlib#string#Strcharpart(text[0], c0 - 1)
endif
endif
return text
endf

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 121 " @Revision: 148
" :def: function! tlib#string#RemoveBackslashes(text, ?chars=' ') " :def: function! tlib#string#RemoveBackslashes(text, ?chars=' ')
@ -22,11 +22,21 @@ function! tlib#string#Chomp(string, ...) "{{{3
endf endf
function! tlib#string#Format(template, dict) "{{{3 " Format a template string. Placeholders have the format "%{NAME}". A
let parts = split(a:template, '\ze%\({.\{-}}\|.\)') " "%" can be inserted as "%%".
"
" Examples:
" echo tlib#string#Format("foo %{bar} foo", {'bar': 123}, ?prefix='%')
" => foo 123 foo
function! tlib#string#Format(template, dict, ...) "{{{3
let prefix = a:0 >= 1 ? a:1 : '%'
let pesc = prefix . prefix
let prx = tlib#rx#Escape(prefix)
let parts = split(a:template, '\ze'. prx .'\({.\{-}}\|.\)')
let partrx = '^'. prx .'\({\(.\{-}\)}\|\(.\)\)\(.*\)$'
let out = [] let out = []
for part in parts for part in parts
let ml = matchlist(part, '^%\({\(.\{-}\)}\|\(.\)\)\(.*\)$') let ml = matchlist(part, partrx)
if empty(ml) if empty(ml)
let rest = part let rest = part
else else
@ -34,8 +44,8 @@ function! tlib#string#Format(template, dict) "{{{3
let rest = ml[4] let rest = ml[4]
if has_key(a:dict, var) if has_key(a:dict, var)
call add(out, a:dict[var]) call add(out, a:dict[var])
elseif var == '%%' elseif var ==# pesc
call add(out, '%') call add(out, prefix)
else else
call add(out, ml[1]) call add(out, ml[1])
endif endif
@ -156,3 +166,43 @@ function! tlib#string#SplitCommaList(text, ...) abort "{{{3
return parts return parts
endf endf
function! tlib#string#Input(...) abort "{{{3
TVarArg ['text', ''], ['completion', '']
call inputsave()
let rv = call(function('input'), a:000)
call inputrestore()
return rv
endf
" :display: tlib#string#MatchAll(string, sep_regexp, ?item_regexp='') abort
function! tlib#string#MatchAll(string, regexp, ...) abort "{{{3
let eregexp = a:0 >= 1 ? a:1 : ''
Tlibtrace 'tlib', a:string, a:regexp, eregexp
let ms = []
if a:regexp =~ '\\ze'
let regexp1 = substitute(a:regexp, '\\ze.*$', '', '')
else
let regexp1 = a:regexp
endif
for m in split(a:string, '\ze'. regexp1)
let m1 = matchstr(m, !empty(eregexp) ? eregexp : a:regexp)
Tlibtrace 'tlib', m, m1
if !empty(m1)
call add(ms, m1)
endif
endfor
return ms
endf
if exists('*strcharpart')
function! tlib#string#Strcharpart(...) abort "{{{3
return call(function('strcharpart'), a:000)
endf
else
function! tlib#string#Strcharpart(...) abort "{{{3
return call(function('strpart'), a:000)
endf
endif

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2015-11-07. " @Last Change: 2017-04-12.
" @Revision: 51 " @Revision: 62
if !exists('g:tlib#sys#special_protocols') if !exists('g:tlib#sys#special_protocols')
@ -16,14 +16,14 @@ if !exists('g:tlib#sys#special_suffixes')
" A list of |regexp|s matching suffixes that should be handled by " A list of |regexp|s matching suffixes that should be handled by
" |g:tlib#sys#system_browser|. " |g:tlib#sys#system_browser|.
" CAVEAT: Must be a |\V| |regexp|. " CAVEAT: Must be a |\V| |regexp|.
let g:tlib#sys#special_suffixes = ['xlsx\?', 'docx\?', 'pptx\?', 'accdb', 'mdb', 'sqlite', 'pdf', 'jpg', 'png', 'gif'] "{{{2 let g:tlib#sys#special_suffixes = ['xlsx\?', 'docx\?', 'pptx\?', 'accdb', 'mdb', 'sqlite', 'pdf', 'jpg', 'png', 'gif', 'od\[tspg]'] "{{{2
endif endif
if !exists('g:tlib#sys#system_rx') if !exists('g:tlib#sys#system_rx')
" Open links matching this |regexp| with |g:tlib#sys#system_browser|. " Open links matching this |regexp| with |g:tlib#sys#system_browser|.
" CAVEAT: Must be a |\V| |regexp|. " CAVEAT: Must be a |\V| |regexp|.
let g:tlib#sys#system_rx = printf('\V\%(\^\%(%s\):\|.\%(%s\)\)', join(g:tlib#sys#special_protocols, '\|'), join(g:tlib#sys#special_suffixes, '\|')) "{{{2 let g:tlib#sys#system_rx = printf('\V\%(\^\%(%s\):\|.\%(%s\)\$\)', join(g:tlib#sys#special_protocols, '\|'), join(g:tlib#sys#special_suffixes, '\|')) "{{{2
endif endif
@ -39,7 +39,7 @@ if !exists("g:tlib#sys#system_browser")
let g:tlib#sys#system_browser = "exec 'silent !open' shellescape('%s')" let g:tlib#sys#system_browser = "exec 'silent !open' shellescape('%s')"
elseif exists('$XDG_CURRENT_DESKTOP') && !empty($XDG_CURRENT_DESKTOP) elseif exists('$XDG_CURRENT_DESKTOP') && !empty($XDG_CURRENT_DESKTOP)
let g:tlib#sys#system_browser = "exec 'silent !xdg-open' shellescape('%s') '&'" let g:tlib#sys#system_browser = "exec 'silent !xdg-open' shellescape('%s') '&'"
elseif $GNOME_DESKTOP_SESSION_ID != "" || $DESKTOP_SESSION == 'gnome' elseif !empty($GNOME_DESKTOP_SESSION_ID) || $DESKTOP_SESSION ==# 'gnome'
let g:tlib#sys#system_browser = "exec 'silent !gnome-open' shellescape('%s')" let g:tlib#sys#system_browser = "exec 'silent !gnome-open' shellescape('%s')"
elseif exists("$KDEDIR") && !empty($KDEDIR) elseif exists("$KDEDIR") && !empty($KDEDIR)
let g:tlib#sys#system_browser = "exec 'silent !kfmclient exec' shellescape('%s')" let g:tlib#sys#system_browser = "exec 'silent !kfmclient exec' shellescape('%s')"
@ -185,9 +185,7 @@ function! tlib#sys#Open(filename) abort "{{{3
Tlibtrace 'tlib', a:filename Tlibtrace 'tlib', a:filename
if !empty(g:tlib#sys#system_browser) && tlib#sys#IsSpecial(a:filename) if !empty(g:tlib#sys#system_browser) && tlib#sys#IsSpecial(a:filename)
try try
let cmd = printf(g:tlib#sys#system_browser, escape(a:filename, ' %#!')) call tlib#sys#OpenWithSystemViewer(a:filename)
Tlibtrace 'tlib', cmd
exec cmd
return 1 return 1
catch catch
echohl ErrorMsg echohl ErrorMsg
@ -199,13 +197,22 @@ function! tlib#sys#Open(filename) abort "{{{3
endf endf
" Open filename with the default system viewer.
function! tlib#sys#OpenWithSystemViewer(filename) abort "{{{3
let cmd = printf(g:tlib#sys#system_browser, a:filename)
" let cmd = printf(g:tlib#sys#system_browser, escape(a:filename, ' %#!'))
Tlibtrace 'tlib', cmd
exec cmd
endf
" :def: function! tlib#sys#SystemInDir(dir, expr, ?input='') " :def: function! tlib#sys#SystemInDir(dir, expr, ?input='')
function! tlib#sys#SystemInDir(dir, ...) abort "{{{3 function! tlib#sys#SystemInDir(dir, ...) abort "{{{3
call tlib#dir#CD(a:dir) call tlib#dir#CD(a:dir)
try try
return call(function('system'), a:000) return call(function('system'), a:000)
finally finally
cd! - silent cd! -
endtry endtry
endf endf

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 59 " @Revision: 64
" Extra tags for |tlib#tag#Retrieve()| (see there). Can also be buffer-local. " Extra tags for |tlib#tag#Retrieve()| (see there). Can also be buffer-local.
@ -47,7 +47,7 @@ TLet g:tlib_tag_substitute = {
" < tags from the JDK will be included. " < tags from the JDK will be included.
function! tlib#tag#Retrieve(rx, ...) "{{{3 function! tlib#tag#Retrieve(rx, ...) "{{{3
TVarArg ['extra_tags', 0] TVarArg ['extra_tags', 0]
" TLogVAR a:rx, extra_tags Tlibtrace 'tlib', a:rx, extra_tags
if extra_tags if extra_tags
let tags_orig = &l:tags let tags_orig = &l:tags
if empty(tags_orig) if empty(tags_orig)
@ -65,7 +65,8 @@ function! tlib#tag#Retrieve(rx, ...) "{{{3
else else
let taglist = taglist(a:rx) let taglist = taglist(a:rx)
endif endif
return taglist Tlibtrace 'tlib', len(taglist)
return copy(taglist)
endf endf
@ -76,7 +77,7 @@ endf
" :def: function! tlib#tag#Collect(constraints, ?use_extra=1, ?match_front=1) " :def: function! tlib#tag#Collect(constraints, ?use_extra=1, ?match_front=1)
function! tlib#tag#Collect(constraints, ...) "{{{3 function! tlib#tag#Collect(constraints, ...) "{{{3
TVarArg ['use_extra', 0], ['match_end', 1], ['match_front', 1] TVarArg ['use_extra', 0], ['match_end', 1], ['match_front', 1]
" TLogVAR a:constraints, use_extra Tlibtrace 'tlib', a:constraints, use_extra, match_end, match_front
let rx = get(a:constraints, 'name', '') let rx = get(a:constraints, 'name', '')
if empty(rx) || rx == '*' if empty(rx) || rx == '*'
let rx = '.' let rx = '.'
@ -92,9 +93,9 @@ function! tlib#tag#Collect(constraints, ...) "{{{3
endif endif
let rx = join(rxl, '') let rx = join(rxl, '')
endif endif
" TLogVAR rx, use_extra Tlibtrace 'tlib', rx, use_extra
let tags = tlib#tag#Retrieve(rx, use_extra) let tags = tlib#tag#Retrieve(rx, use_extra)
" TLogDBG len(tags) Tlibtrace 'tlib', len(tags)
for [field, rx] in items(a:constraints) for [field, rx] in items(a:constraints)
if !empty(rx) && rx != '*' if !empty(rx) && rx != '*'
" TLogVAR field, rx " TLogVAR field, rx
@ -105,7 +106,7 @@ function! tlib#tag#Collect(constraints, ...) "{{{3
endif endif
endif endif
endfor endfor
" TLogVAR tags Tlibtrace 'tlib', len(tags)
return tags return tags
endf endf

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 36 " @Revision: 42
function! tlib#time#MSecs() "{{{3 function! tlib#time#MSecs() "{{{3
@ -65,3 +65,20 @@ function! tlib#time#DiffMSecs(a, b, ...) "{{{3
endf endf
function! tlib#time#Command(cmd, ...) abort "{{{3
let loops = a:0 >= 1 ? a:1 : 1
let silent = a:0 >= 1 ? a:1 : 0
let start = tlib#time#Now()
for loop in range(loops)
if silent
silent! exec a:cmd
else
exec a:cmd
endif
endfor
let end = tlib#time#Now()
let diff = tlib#time#Diff(end, start)
echom 'Time:' diff
return diff
endf

View file

@ -1,8 +1,8 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: https://github.com/tomtom " @Website: https://github.com/tomtom
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2015-11-23 " @Last Change: 2017-03-09
" @Revision: 134 " @Revision: 205
if !exists('g:tlib#trace#backtrace') if !exists('g:tlib#trace#backtrace')
@ -12,19 +12,42 @@ if !exists('g:tlib#trace#backtrace')
endif endif
if !exists('g:tlib#trace#printf') if !exists('g:tlib#trace#printer')
" The command used for printing traces from |tlib#trace#Print()|. " Possible values:
let g:tlib#trace#printf = 'echom %s' "{{{2 " - 'echom'
" - ['file', FILENAME]
let g:tlib#trace#printer = 'echom' "{{{2
endif endif
let s:trace_hl = {'error': 'ErrorMsg', 'fatal': 'ErrorMsg', 'warning': 'WarningMsg'} if !exists('g:tlib#trace#hl')
let g:tlib#trace#hl = {'error': 'ErrorMsg', 'fatal': 'ErrorMsg', 'warn': 'WarningMsg'} "{{{2
endif
" Set |g:tlib#trace#printf| to make |tlib#trace#Print()| print to " Print traces from |tlib#trace#Print()|.
" `filename`. function! tlib#trace#Printer_echom(type, text, args) abort "{{{3
function! tlib#trace#PrintToFile(filename) abort "{{{3 let hl = get(g:tlib#trace#hl, a:type, '')
let g:tlib#trace#printf = 'call writefile([%s], '. string(a:filename) .', "a")' try
if !empty(hl)
exec 'echohl' hl
endif
echom a:text
finally
if !empty(hl)
echohl NONE
endif
endtry
endf
function! tlib#trace#Printer_file(type, text, args) abort "{{{3
let filename = get(a:args, 0, '')
if exists(filename) && !filewritable(filename)
throw 'tlib#trace#Printer_file: Cannot write to file: '. filename
else
call writefile([a:text], filename, 'a')
endif
endf endf
@ -34,26 +57,58 @@ endf
" Examples: " Examples:
" call tlib#trace#Set(["+foo", "-bar"]) " call tlib#trace#Set(["+foo", "-bar"])
" call tlib#trace#Set("+foo,-bar") " call tlib#trace#Set("+foo,-bar")
function! tlib#trace#Set(vars) abort "{{{3 function! tlib#trace#Set(vars, ...) abort "{{{3
let reset = a:0 >= 1 ? a:1 : 0
if reset
call tlib#trace#Reset()
endif
if empty(a:vars)
return
endif
call tlib#trace#Enable() call tlib#trace#Enable()
if type(a:vars) == 1 if type(a:vars) == v:t_string
let vars = tlib#string#SplitCommaList(a:vars, '[,[:space:]]\+') let vars = tlib#string#SplitCommaList(a:vars, '[,[:space:]]\+')
let opts = {}
elseif type(a:vars) == v:t_dict
let vars = a:vars.__rest__
if has_key(a:vars, 'file')
let g:tlib#trace#printer = ['file', a:vars.file]
endif
if has_key(a:vars, 'echo')
let g:tlib#trace#printer = 'echom'
endif
else else
let vars = a:vars let vars = a:vars
let opts = {}
endif endif
" TLogVAR vars
for rx in vars for rx in vars
let rx1 = substitute(rx, '^[+-]', '', 'g') let rx1 = substitute(rx, '^[+-]', '', 'g')
if rx1 !~# '^\%(error\|fatal\)$' && s:trace_rx !~# '[(|]'. tlib#rx#Escape(rx1) .'\\' if rx1 !~# '^\%(error\|warn\|fatal\)$'
let erx1 = tlib#rx#Escape(rx1)
" TLogVAR rx, rx1 " TLogVAR rx, rx1
if rx =~ '^+' " echom "DBG" s:trace_rx
let s:trace_rx = substitute(s:trace_rx, '\ze\\)\$', '\\|'. tlib#rx#EscapeReplace(rx1), '') if rx =~ '^-'
elseif rx =~ '^-' let erx1 .= '\[0-\d\]\\?'
let s:trace_rx = substitute(s:trace_rx, '\\|'. tlib#rx#Escape(rx1), '', '') if s:trace_rx =~# '[(|]'. erx1 .'\\'
let s:trace_rx = substitute(s:trace_rx, '\\|'. erx1, '', '')
endif
" elseif rx =~ '^+'
else else
echohl WarningMsg if erx1 =~ '\d$'
echom 'tlib#trace#Print: Unsupported syntax:' rx let erx1 = substitute(erx1, '\d$', '[0-\0]\\?', '')
echohl NONE else
let erx1 .= '[0-9]\?'
endif
if s:trace_rx !~# '[(|]'. erx1 .'\\'
let s:trace_rx = substitute(s:trace_rx, '\ze\\)\$', '\\|'. escape(erx1, '\'), '')
endif
" else
" echohl WarningMsg
" echom 'tlib#trace#Print: Unsupported syntax:' rx
" echohl NONE
endif endif
" echom "DBG" s:trace_rx
endif endif
endfor endfor
echom "SetTrace:" s:trace_rx echom "SetTrace:" s:trace_rx
@ -71,6 +126,7 @@ endf
" Print the values of vars. The first value is a "guard" (see " Print the values of vars. The first value is a "guard" (see
" |:Tlibtrace|). " |:Tlibtrace|).
function! tlib#trace#Print(caller, vars, values) abort "{{{3 function! tlib#trace#Print(caller, vars, values) abort "{{{3
" echom "DBG tlib#trace#Print" string(a:vars) string(a:values)
let msg = ['TRACE'] let msg = ['TRACE']
let guard = a:values[0] let guard = a:values[0]
if type(guard) == 0 if type(guard) == 0
@ -88,22 +144,47 @@ function! tlib#trace#Print(caller, vars, values) abort "{{{3
call add(msg, bt .':') call add(msg, bt .':')
endif endif
endif endif
for i in range(1, len(a:vars) - 1) if len(a:vars) == len(a:values)
let v = substitute(a:vars[i], ',$', '', '') for i in range(1, len(a:vars) - 1)
let r = string(a:values[i]) let v = substitute(a:vars[i], ',$', '', '')
call add(msg, v .'='. r .';') if type(a:values[i]) == v:t_func
endfor let r = string(a:values[i])
exec printf(g:tlib#trace#printf, string(join(msg))) else
let r = a:values[i]
endif
if v =~# '^\([''"]\).\{-}\1$'
call add(msg, r .';')
else
call add(msg, v .'='. string(r) .';')
endif
unlet r
endfor
else
call add(msg, join(a:values[1:-1]))
endif
if type(g:tlib#trace#printer) == v:t_string
let printer = g:tlib#trace#printer
let args = []
else
let [printer; args] = g:tlib#trace#printer
endif
call tlib#trace#Printer_{printer}(guard, join(msg), args)
endif endif
endf endf
function! tlib#trace#Reset() abort "{{{3
let s:trace_rx = '^\%(error\|fatal\|warn\|info\)$'
let g:tlib#trace#printer = 'echom'
endf
" Enable tracing via |:Tlibtrace|. " Enable tracing via |:Tlibtrace|.
function! tlib#trace#Enable() abort "{{{3 function! tlib#trace#Enable() abort "{{{3
if !exists('s:trace_rx') if !exists('s:trace_rx')
let s:trace_rx = '^\%(error\)$' call tlib#trace#Reset()
" :nodoc: " :nodoc:
command! -nargs=+ -bar Tlibtrace call tlib#trace#Print(expand('<sfile>'), [<f-args>], [<args>]) command! -nargs=+ -bang Tlibtrace call tlib#trace#Print(expand('<sfile>'), [<f-args>], [<args>])
endif endif
endf endf
@ -111,7 +192,7 @@ endf
" Disable tracing via |:Tlibtrace|. " Disable tracing via |:Tlibtrace|.
function! tlib#trace#Disable() abort "{{{3 function! tlib#trace#Disable() abort "{{{3
" :nodoc: " :nodoc:
command! -nargs=+ -bang -bar Tlibtrace : command! -nargs=+ -bang Tlibtrace :
unlet! s:trace_rx unlet! s:trace_rx
endf endf

View file

@ -2,8 +2,30 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-09-30. " @Created: 2007-09-30.
" @Last Change: 2015-11-23. " @Last Change: 2017-02-22.
" @Revision: 6 " @Revision: 57
let g:tlib#type#nil = []
" Enable type assertiona via |:Tlibtype|.
function! tlib#type#Enable() abort "{{{3
" :nodoc:
command! -nargs=+ Tlibtype call tlib#type#Check(expand('<sfile>'), [<f-args>], [<args>])
endf
" Disable type assertiona via |:Tlibtype|.
function! tlib#type#Disable() abort "{{{3
" :nodoc:
command! -nargs=+ Tlibtype :
endf
function! tlib#type#IsNil(expr) abort "{{{3
return tlib#type#Is(a:expr, v:t_none) || a:expr is g:tlib#type#nil
endf
function! tlib#type#IsNumber(expr) function! tlib#type#IsNumber(expr)
@ -32,25 +54,37 @@ endf
function! tlib#type#Is(val, type) abort "{{{3 function! tlib#type#Is(val, type) abort "{{{3
if type(a:type) == 0 if has_key(s:schemas, a:type)
let type = a:type return tlib#type#Has(a:val, a:type)
elseif a:type =~? '^n\%[umber]'
let type = 0
elseif a:type =~? '^s\%[tring]'
let type = 1
elseif a:type =~? '^fu\%[ncref]'
let type = 2
elseif a:type =~? '^l\%[ist]'
let type = 3
elseif a:type =~? '^d\%[ictionary]'
let type = 4
elseif a:type =~? '^fl\%[oat]'
let type = 5
else else
throw 'tlib#type#Is: Unknown type: ' a:type if type(a:type) == 0
let type = a:type
elseif a:type =~? '^b\%[oolean]$'
let type = v:t_bool
elseif a:type =~? '^c\%[hannel]$'
let type = v:t_channel
elseif a:type =~? '^d\%[ictionary]$'
let type = v:t_dict
elseif a:type =~? '^fl\%[oat]$'
let type = v:t_float
elseif a:type =~? '^fu\%[ncref]$'
let type = v:t_func
elseif a:type =~? '^j\%[ob]$'
let type = v:t_job
elseif a:type =~? '^l\%[ist]$'
let type = v:t_list
elseif a:type =~? '^\%(nil\|null\|none\)$'
let type = v:t_none
elseif a:type =~? '^n\%[umber]$'
let type = v:t_number
elseif a:type =~? '^s\%[tring]$'
let type = v:t_string
else
throw 'tlib#type#Is: Unknown type: ' a:type
endif
Tlibtrace 'tlib', a:val, a:type, type, type(a:val), type(a:val) == a:type
return type(a:val) == type
endif endif
" TLogVAR a:val, a:type, type, type(a:val), type(a:val) == a:type
return type(a:val) == type
endf endf
@ -59,13 +93,50 @@ function! tlib#type#Are(vals, type) abort "{{{3
endf endf
function! tlib#type#Has(val, lst) abort "{{{3 let s:schemas = {}
return tlib#assert#All(map(a:lst, 'has_key(a:val, v:val)'))
function! tlib#type#Define(name, schema) abort "{{{3
let s:schemas[a:name] = deepcopy(a:schema)
endf endf
function! tlib#type#Have(vals, lst) abort "{{{3 function! tlib#type#Has(val, schema) abort "{{{3
return tlib#assert#Map(a:vals, 'tlib#type#Has(v:val,'. string(a:lst) .')') Tlibtrace 'tlib', type(a:val), type(a:schema)
if !tlib#type#IsDictionary(a:val)
Tlibtrace 'tlib', 'not a dictionary', a:val
return 0
endif
if tlib#type#IsString(a:schema)
Tlibtrace 'tlib', a:schema
let schema = copy(s:schemas[a:schema])
else
let schema = copy(a:schema)
endif
if tlib#type#IsDictionary(schema)
return tlib#assert#All(map(schema, 'has_key(a:val, v:key) && tlib#type#Is(a:val[v:key], v:val)'))
else
Tlibtrace 'tlib', keys(a:val), schema
return tlib#assert#All(map(schema, 'has_key(a:val, v:val)'))
endif
endf endf
function! tlib#type#Have(vals, schema) abort "{{{3
return tlib#assert#Map(a:vals, 'tlib#type#Has(v:val,'. string(a:schema) .')')
endf
function! tlib#type#Check(caller, names, vals) abort "{{{3
Tlibtrace 'tlib', a:names, a:vals, len(a:names)
for i in range(0, len(a:names) - 1, 2)
let val = a:vals[i]
let type = a:vals[i + 1]
Tlibtrace 'tlib', i, val, type
if !tlib#type#Is(val, type)
let name = matchstr(a:names[i], '^''\zs.\{-}\ze'',\?$')
throw 'tlib#type#Check: Type mismatch: '. name .':'. a:vals[i + 1]
endif
endfor
endf

View file

@ -1,7 +1,7 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 30 " @Revision: 34
" Define a variable called NAME if yet undefined. " Define a variable called NAME if yet undefined.
@ -52,10 +52,17 @@ endf
function! tlib#var#Get(var, namespace, ...) "{{{3 function! tlib#var#Get(var, namespace, ...) "{{{3
let var_ = substitute(a:var, '#', '_', 'g') let var_ = substitute(a:var, '#', '_', 'g')
for namespace in split(a:namespace, '\zs') for namespace in split(a:namespace, '\zs')
let vname = namespace == 'g' ? a:var : var_ let vname = namespace ==# 'g' ? a:var : var_
let var = namespace .':'. vname let var = namespace .':'. vname
if exists(var) if exists(var)
return {var} return {var}
elseif namespace ==# 'g'
try
let val = {var}
catch /^Vim\%((\a\+)\)\=:E\(121\|15\)/
continue
endtry
return val
endif endif
endfor endfor
return a:0 >= 1 ? a:1 : '' return a:0 >= 1 ? a:1 : ''

View file

@ -1,8 +1,8 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2012-03-08. " @Created: 2012-03-08.
" @Last Change: 2015-11-07. " @Last Change: 2017-04-10.
" @Revision: 190 " @Revision: 224
scriptencoding utf-8 scriptencoding utf-8
@ -14,21 +14,19 @@ TLet g:tlib#vcs#def = {
\ 'dir': '.git', \ 'dir': '.git',
\ 'ls': 'git ls-files --full-name', \ 'ls': 'git ls-files --full-name',
\ 'ls.postprocess': '*tlib#vcs#GitLsPostprocess', \ 'ls.postprocess': '*tlib#vcs#GitLsPostprocess',
\ 'diff': 'git diff --no-ext-diff -U0 %s' \ 'diff': 'git diff --no-ext-diff -U0 %s',
\ }, \ 'status': 'git status -s',
\ 'status.filterrx': '^\C[ MADRCU!?]\{2}\s'},
\ 'hg': { \ 'hg': {
\ 'dir': '.hg', \ 'dir': '.hg',
\ 'diff': 'hg diff -U0 %s', \ 'diff': 'hg diff -U0 %s',
\ 'ls': 'hg manifest' \ 'ls': 'hg manifest'},
\ },
\ 'svn': { \ 'svn': {
\ 'dir': '.svn', \ 'dir': '.svn',
\ 'diff': 'svn diff --diff-cmd diff --extensions -U0 %s', \ 'diff': 'svn diff --diff-cmd diff --extensions -U0 %s'},
\ },
\ 'bzr': { \ 'bzr': {
\ 'dir': '.bzr', \ 'dir': '.bzr',
\ 'diff': 'bzr diff --diff-options=-U0 %s', \ 'diff': 'bzr diff --diff-options=-U0 %s'}
\ }
\ } \ }
@ -60,36 +58,44 @@ function! tlib#vcs#Executable(type) "{{{3
endf endf
let s:vcs_cache = {}
autocmd TLib FocusGained * let s:vcs_cache = {}
function! tlib#vcs#FindVCS(filename) "{{{3 function! tlib#vcs#FindVCS(filename) "{{{3
let type = '' let type = ''
let dir = '' let dir = ''
let dirname = fnamemodify(a:filename, isdirectory(a:filename) ? ':p' : ':p:h') let filename = fnamemodify(a:filename, ':p')
let path = escape(dirname, ';') .';' let dirname = isdirectory(filename) ? filename : fnamemodify(filename, ':h')
" TLogVAR a:filename, dirname, path if !has_key(s:vcs_cache, dirname)
Tlibtrace 'tlib', a:filename, path let path = escape(dirname, ';') .';'
let depth = -1 " TLogVAR filename, dirname, path
for vcs in keys(g:tlib#vcs#def) Tlibtrace 'tlib', filename, path
let subdir = g:tlib#vcs#def[vcs].dir let depth = -1
let vcsdir = finddir(subdir, path) for vcs in keys(g:tlib#vcs#def)
" TLogVAR vcs, subdir, vcsdir let subdir = g:tlib#vcs#def[vcs].dir
Tlibtrace 'tlib', vcs, subdir, vcsdir let vcsdir = finddir(subdir, path)
if !empty(vcsdir) " TLogVAR vcs, subdir, vcsdir
let vcsdir_depth = len(split(fnamemodify(vcsdir, ':p'), '\/')) Tlibtrace 'tlib', vcs, subdir, vcsdir
if vcsdir_depth > depth if !empty(vcsdir)
let depth = vcsdir_depth let vcsdir_depth = len(split(fnamemodify(vcsdir, ':p'), '\/'))
let type = vcs if vcsdir_depth > depth
let dir = vcsdir let depth = vcsdir_depth
" TLogVAR type, depth let type = vcs
let dir = vcsdir
" TLogVAR type, depth
endif
endif endif
endfor
Tlibtrace 'tlib', type, dir
" TLogVAR type, dir
if empty(type)
let s:vcs_cache[dirname] = ['', '']
else
let s:vcs_cache[dirname] = [type, dir]
endif endif
endfor
Tlibtrace 'tlib', type, dir
" TLogVAR type, dir
if empty(type)
return ['', '']
else
return [type, dir]
endif endif
return s:vcs_cache[dirname]
endf endf
@ -97,7 +103,7 @@ function! s:GetCmd(vcstype, cmd)
let vcsdef = get(g:tlib#vcs#def, a:vcstype, {}) let vcsdef = get(g:tlib#vcs#def, a:vcstype, {})
if has_key(vcsdef, a:cmd) if has_key(vcsdef, a:cmd)
let cmd = vcsdef[a:cmd] let cmd = vcsdef[a:cmd]
if cmd =~ '^\*' if cmd =~# '^\*'
let cmd = substitute(cmd, '^\*', '', '') let cmd = substitute(cmd, '^\*', '', '')
else else
let bin = get(g:tlib#vcs#executables, a:vcstype, '') let bin = get(g:tlib#vcs#executables, a:vcstype, '')
@ -134,7 +140,7 @@ function! tlib#vcs#Ls(...) "{{{3
if !empty(ls) if !empty(ls)
let rootdir = fnamemodify(vcsdir, ':p:h:h') let rootdir = fnamemodify(vcsdir, ':p:h:h')
" TLogVAR vcsdir, rootdir " TLogVAR vcsdir, rootdir
if ls =~ '%s' if ls =~# '%s'
let cmd = printf(ls, shellescape(rootdir)) let cmd = printf(ls, shellescape(rootdir))
else else
let cmd = ls let cmd = ls
@ -176,7 +182,7 @@ endf
function! tlib#vcs#GitLsPostprocess(filename) abort "{{{3 function! tlib#vcs#GitLsPostprocess(filename) abort "{{{3
if a:filename =~ '^".\{-}"$' if a:filename =~# '^".\{-}"$'
let filename = matchstr(a:filename, '^"\zs.\{-}\ze"$') let filename = matchstr(a:filename, '^"\zs.\{-}\ze"$')
let filename = substitute(filename, '\%(\\\@<!\\\(\d\d\d\)\)\+', '\=eval(''"''. submatch(0) .''"'')', 'g') let filename = substitute(filename, '\%(\\\@<!\\\(\d\d\d\)\)\+', '\=eval(''"''. submatch(0) .''"'')', 'g')
" let filename = eval(a:filename) " let filename = eval(a:filename)
@ -187,3 +193,38 @@ function! tlib#vcs#GitLsPostprocess(filename) abort "{{{3
endif endif
endf endf
function! tlib#vcs#Status(...) abort "{{{3
let filename = a:0 >= 1 ? a:1 : '%'
let vcs = a:0 >= 2 ? a:2 : tlib#vcs#FindVCS(filename)
if !empty(vcs)
let [vcstype, vcsdir] = vcs
let cstatus = s:GetCmd(vcstype, 'status')
if !empty(cstatus)
let status = exists('*systemlist') ? systemlist(cstatus) : split(system(cstatus), '\n')
let sfilter = s:GetCmd(vcstype, 'status.filterrx')
if !empty(sfilter)
let status = filter(status, 'v:val =~# sfilter')
endif
return status
endif
endif
endf
function! tlib#vcs#IsDirty(...) abort "{{{3
let filename = a:0 >= 1 ? a:1 : '%'
let vcs = a:0 >= 2 ? a:2 : tlib#vcs#FindVCS(filename)
let status = tlib#vcs#Status(filename, vcs)
return empty(status) ? '' : vcs[0] .'!'
endf
" function! tlib#vcs#EnableTStatus() abort "{{{3
" if has('vim_starting')
" autocmd VimEnter * TStatusregister1 --event=FocusGained,BufRead,BufWritePost %s tlib#vcs#IsDirty()
" else
" TStatusregister1 --event=FocusGained,BufRead,BufWritePost %s tlib#vcs#IsDirty()
" endif
" endf

View file

@ -1,7 +1,12 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 55 " @Revision: 84
if !exists('g:tlib#win#use_winid')
let g:tlib#win#use_winid = exists('*win_gotoid') && exists('*win_getid') "{{{2
endif
" Return vim code to jump back to the original window. " Return vim code to jump back to the original window.
@ -22,6 +27,70 @@ function! tlib#win#Set(winnr) "{{{3
endf endf
if g:tlib#win#use_winid
let g:tlib#win#null_id = -1
function! tlib#win#GetID() abort "{{{3
return win_getid()
endf
function! tlib#win#GotoID(win_id) abort "{{{3
call win_gotoid(a:win_id)
endf
else
let s:win_id = 0
let g:tlib#win#null_id = {}
function! tlib#win#GetID() abort "{{{3
if !exists('w:tlib_win_id')
let s:win_id += 1
let w:tlib_win_id = s:win_id
endif
return {'tabpagenr': tabpagenr(), 'bufnr': bufnr('%'), 'winnr': winnr(), 'win_id': w:tlib_win_id}
endf
function! tlib#win#GotoID(win_id) abort "{{{3
Tlibtrace 'tlib', a:win_id
if tabpagenr() != a:win_id.tabpagenr
exec 'tabnext' a:win_id.tabpagenr
endif
for wnr in range(1, winnr('$'))
let win_id = getwinvar(wnr, 'tlib_win_id', -1)
Tlibtrace 'tlib', wnr, win_id
if win_id == a:win_id.win_id
Tlibtrace 'tlib', wnr
exec wnr 'wincmd w'
return
endif
endfor
" Was the window closed? What should we do now?
if winnr() != a:win_id.winnr
exec a:win_id.winnr 'wincmd w'
endif
if bufnr('%') != a:win_id.bufnr
exec 'hide buffer' a:win_id.bufnr
endif
endf
endif
" Return vim code to jump back to the original window.
function! tlib#win#SetById(win_id) "{{{3
if a:win_id != g:tlib#win#null_id
let win_id = tlib#win#GetID()
call tlib#win#GotoID(a:win_id)
return printf('call tlib#win#GotoID(%s)', win_id)
" " TLogVAR a:winnr
" " TLogDBG winnr()
" " TLogDBG string(tlib#win#List())
" if winnr() != a:winnr && winbufnr(a:winnr) != -1
" let rv = winnr().'wincmd w'
" exec a:winnr .'wincmd w'
" " TLogVAR rv
" " TLogDBG string(tlib#win#List())
" return rv
" endif
endif
return ''
endf
" :def: function! tlib#win#GetLayout(?save_view=0) " :def: function! tlib#win#GetLayout(?save_view=0)
function! tlib#win#GetLayout(...) "{{{3 function! tlib#win#GetLayout(...) "{{{3
TVarArg ['save_view', 0] TVarArg ['save_view', 0]

View file

@ -0,0 +1,223 @@
:TBrowseOutput tlib.txt /*:TBrowseOutput*
:TBrowseScriptnames tlib.txt /*:TBrowseScriptnames*
:TLet tlib.txt /*:TLet*
:TScratch tlib.txt /*:TScratch*
:TVarArg tlib.txt /*:TVarArg*
:Tbrowseloc tlib.txt /*:Tbrowseloc*
:Tbrowseqfl tlib.txt /*:Tbrowseqfl*
:Texecloc tlib.txt /*:Texecloc*
:Texecqfl tlib.txt /*:Texecqfl*
:Tlibtrace tlib.txt /*:Tlibtrace*
:Tlibtraceset tlib.txt /*:Tlibtraceset*
autoload/tlib/Filter_cnf.vim tlib.txt /*autoload\/tlib\/Filter_cnf.vim*
autoload/tlib/Filter_cnfd.vim tlib.txt /*autoload\/tlib\/Filter_cnfd.vim*
autoload/tlib/Filter_fuzzy.vim tlib.txt /*autoload\/tlib\/Filter_fuzzy.vim*
autoload/tlib/Filter_glob.vim tlib.txt /*autoload\/tlib\/Filter_glob.vim*
autoload/tlib/Object.vim tlib.txt /*autoload\/tlib\/Object.vim*
autoload/tlib/World.vim tlib.txt /*autoload\/tlib\/World.vim*
autoload/tlib/agent.vim tlib.txt /*autoload\/tlib\/agent.vim*
autoload/tlib/arg.vim tlib.txt /*autoload\/tlib\/arg.vim*
autoload/tlib/assert.vim tlib.txt /*autoload\/tlib\/assert.vim*
autoload/tlib/buffer.vim tlib.txt /*autoload\/tlib\/buffer.vim*
autoload/tlib/cache.vim tlib.txt /*autoload\/tlib\/cache.vim*
autoload/tlib/char.vim tlib.txt /*autoload\/tlib\/char.vim*
autoload/tlib/cmd.vim tlib.txt /*autoload\/tlib\/cmd.vim*
autoload/tlib/comments.vim tlib.txt /*autoload\/tlib\/comments.vim*
autoload/tlib/date.vim tlib.txt /*autoload\/tlib\/date.vim*
autoload/tlib/dir.vim tlib.txt /*autoload\/tlib\/dir.vim*
autoload/tlib/file.vim tlib.txt /*autoload\/tlib\/file.vim*
autoload/tlib/hook.vim tlib.txt /*autoload\/tlib\/hook.vim*
autoload/tlib/input.vim tlib.txt /*autoload\/tlib\/input.vim*
autoload/tlib/list.vim tlib.txt /*autoload\/tlib\/list.vim*
autoload/tlib/map.vim tlib.txt /*autoload\/tlib\/map.vim*
autoload/tlib/normal.vim tlib.txt /*autoload\/tlib\/normal.vim*
autoload/tlib/notify.vim tlib.txt /*autoload\/tlib\/notify.vim*
autoload/tlib/paragraph.vim tlib.txt /*autoload\/tlib\/paragraph.vim*
autoload/tlib/persistent.vim tlib.txt /*autoload\/tlib\/persistent.vim*
autoload/tlib/progressbar.vim tlib.txt /*autoload\/tlib\/progressbar.vim*
autoload/tlib/rx.vim tlib.txt /*autoload\/tlib\/rx.vim*
autoload/tlib/scratch.vim tlib.txt /*autoload\/tlib\/scratch.vim*
autoload/tlib/selection.vim tlib.txt /*autoload\/tlib\/selection.vim*
autoload/tlib/signs.vim tlib.txt /*autoload\/tlib\/signs.vim*
autoload/tlib/string.vim tlib.txt /*autoload\/tlib\/string.vim*
autoload/tlib/sys.vim tlib.txt /*autoload\/tlib\/sys.vim*
autoload/tlib/tab.vim tlib.txt /*autoload\/tlib\/tab.vim*
autoload/tlib/tag.vim tlib.txt /*autoload\/tlib\/tag.vim*
autoload/tlib/textobjects.vim tlib.txt /*autoload\/tlib\/textobjects.vim*
autoload/tlib/trace.vim tlib.txt /*autoload\/tlib\/trace.vim*
autoload/tlib/type.vim tlib.txt /*autoload\/tlib\/type.vim*
autoload/tlib/url.vim tlib.txt /*autoload\/tlib\/url.vim*
autoload/tlib/var.vim tlib.txt /*autoload\/tlib\/var.vim*
autoload/tlib/vcs.vim tlib.txt /*autoload\/tlib\/vcs.vim*
autoload/tlib/vim.vim tlib.txt /*autoload\/tlib\/vim.vim*
autoload/tlib/win.vim tlib.txt /*autoload\/tlib\/win.vim*
g:tlib#Filter_glob#char tlib.txt /*g:tlib#Filter_glob#char*
g:tlib#Filter_glob#seq tlib.txt /*g:tlib#Filter_glob#seq*
g:tlib#cache#dont_purge tlib.txt /*g:tlib#cache#dont_purge*
g:tlib#cache#max_filename tlib.txt /*g:tlib#cache#max_filename*
g:tlib#cache#purge_days tlib.txt /*g:tlib#cache#purge_days*
g:tlib#cache#purge_every_days tlib.txt /*g:tlib#cache#purge_every_days*
g:tlib#cache#run_script tlib.txt /*g:tlib#cache#run_script*
g:tlib#cache#script_encoding tlib.txt /*g:tlib#cache#script_encoding*
g:tlib#cache#verbosity tlib.txt /*g:tlib#cache#verbosity*
g:tlib#dir#sep tlib.txt /*g:tlib#dir#sep*
g:tlib#file#drop tlib.txt /*g:tlib#file#drop*
g:tlib#input#filename_max_width tlib.txt /*g:tlib#input#filename_max_width*
g:tlib#input#filename_padding_r tlib.txt /*g:tlib#input#filename_padding_r*
g:tlib#input#filter_mode tlib.txt /*g:tlib#input#filter_mode*
g:tlib#input#format_filename tlib.txt /*g:tlib#input#format_filename*
g:tlib#input#higroup tlib.txt /*g:tlib#input#higroup*
g:tlib#input#keyagents_InputList_s tlib.txt /*g:tlib#input#keyagents_InputList_s*
g:tlib#input#livesearch_threshold tlib.txt /*g:tlib#input#livesearch_threshold*
g:tlib#input#numeric_chars tlib.txt /*g:tlib#input#numeric_chars*
g:tlib#input#sortprefs_threshold tlib.txt /*g:tlib#input#sortprefs_threshold*
g:tlib#input#use_popup tlib.txt /*g:tlib#input#use_popup*
g:tlib#input#user_shortcuts tlib.txt /*g:tlib#input#user_shortcuts*
g:tlib#scratch#hidden tlib.txt /*g:tlib#scratch#hidden*
g:tlib#sys#check_cygpath tlib.txt /*g:tlib#sys#check_cygpath*
g:tlib#sys#cygwin_expr tlib.txt /*g:tlib#sys#cygwin_expr*
g:tlib#sys#cygwin_path_rx tlib.txt /*g:tlib#sys#cygwin_path_rx*
g:tlib#sys#special_protocols tlib.txt /*g:tlib#sys#special_protocols*
g:tlib#sys#special_suffixes tlib.txt /*g:tlib#sys#special_suffixes*
g:tlib#sys#system_browser tlib.txt /*g:tlib#sys#system_browser*
g:tlib#sys#system_rx tlib.txt /*g:tlib#sys#system_rx*
g:tlib#trace#backtrace tlib.txt /*g:tlib#trace#backtrace*
g:tlib#trace#printer tlib.txt /*g:tlib#trace#printer*
g:tlib#vcs#check tlib.txt /*g:tlib#vcs#check*
g:tlib#vcs#def tlib.txt /*g:tlib#vcs#def*
g:tlib#vcs#executables tlib.txt /*g:tlib#vcs#executables*
g:tlib#vim#simalt_maximize tlib.txt /*g:tlib#vim#simalt_maximize*
g:tlib#vim#simalt_restore tlib.txt /*g:tlib#vim#simalt_restore*
g:tlib#vim#use_vimtweak tlib.txt /*g:tlib#vim#use_vimtweak*
g:tlib#vim#use_wmctrl tlib.txt /*g:tlib#vim#use_wmctrl*
g:tlib_cache tlib.txt /*g:tlib_cache*
g:tlib_inputlist_filename_indicators tlib.txt /*g:tlib_inputlist_filename_indicators*
g:tlib_inputlist_max_cols tlib.txt /*g:tlib_inputlist_max_cols*
g:tlib_inputlist_max_lines tlib.txt /*g:tlib_inputlist_max_lines*
g:tlib_inputlist_pct tlib.txt /*g:tlib_inputlist_pct*
g:tlib_inputlist_shortmessage tlib.txt /*g:tlib_inputlist_shortmessage*
g:tlib_inputlist_width_filename tlib.txt /*g:tlib_inputlist_width_filename*
g:tlib_persistent tlib.txt /*g:tlib_persistent*
g:tlib_pick_last_item tlib.txt /*g:tlib_pick_last_item*
g:tlib_scratch_pos tlib.txt /*g:tlib_scratch_pos*
g:tlib_scroll_lines tlib.txt /*g:tlib_scroll_lines*
g:tlib_tag_substitute tlib.txt /*g:tlib_tag_substitute*
g:tlib_tags_extra tlib.txt /*g:tlib_tags_extra*
g:tlib_viewline_position tlib.txt /*g:tlib_viewline_position*
plugin/02tlib.vim tlib.txt /*plugin\/02tlib.vim*
standard-paragraph tlib.txt /*standard-paragraph*
tlib#Filter_cnf#New() tlib.txt /*tlib#Filter_cnf#New()*
tlib#Filter_cnfd#New() tlib.txt /*tlib#Filter_cnfd#New()*
tlib#Filter_fuzzy#New() tlib.txt /*tlib#Filter_fuzzy#New()*
tlib#Filter_glob#New() tlib.txt /*tlib#Filter_glob#New()*
tlib#Object#New() tlib.txt /*tlib#Object#New()*
tlib#agent#GotoLine() tlib.txt /*tlib#agent#GotoLine()*
tlib#agent#NewItem() tlib.txt /*tlib#agent#NewItem()*
tlib#agent#Suspend() tlib.txt /*tlib#agent#Suspend()*
tlib#agent#SuspendToParentWindow() tlib.txt /*tlib#agent#SuspendToParentWindow()*
tlib#arg#Ex() tlib.txt /*tlib#arg#Ex()*
tlib#arg#Get() tlib.txt /*tlib#arg#Get()*
tlib#arg#GetOpts() tlib.txt /*tlib#arg#GetOpts()*
tlib#arg#Let() tlib.txt /*tlib#arg#Let()*
tlib#assert#Disable() tlib.txt /*tlib#assert#Disable()*
tlib#assert#Enable() tlib.txt /*tlib#assert#Enable()*
tlib#buffer#BufDo() tlib.txt /*tlib#buffer#BufDo()*
tlib#buffer#DeleteRange() tlib.txt /*tlib#buffer#DeleteRange()*
tlib#buffer#Eval() tlib.txt /*tlib#buffer#Eval()*
tlib#buffer#GetList() tlib.txt /*tlib#buffer#GetList()*
tlib#buffer#InsertText() tlib.txt /*tlib#buffer#InsertText()*
tlib#buffer#KeepCursorPosition() tlib.txt /*tlib#buffer#KeepCursorPosition()*
tlib#buffer#ReplaceRange() tlib.txt /*tlib#buffer#ReplaceRange()*
tlib#buffer#ScratchEnd() tlib.txt /*tlib#buffer#ScratchEnd()*
tlib#buffer#ScratchStart() tlib.txt /*tlib#buffer#ScratchStart()*
tlib#buffer#Set() tlib.txt /*tlib#buffer#Set()*
tlib#buffer#ViewLine() tlib.txt /*tlib#buffer#ViewLine()*
tlib#cache#Dir() tlib.txt /*tlib#cache#Dir()*
tlib#cache#EncodedFilename() tlib.txt /*tlib#cache#EncodedFilename()*
tlib#cache#MaybePurge() tlib.txt /*tlib#cache#MaybePurge()*
tlib#cache#Purge() tlib.txt /*tlib#cache#Purge()*
tlib#cache#Value() tlib.txt /*tlib#cache#Value()*
tlib#char#Get() tlib.txt /*tlib#char#Get()*
tlib#cmd#BrowseOutput() tlib.txt /*tlib#cmd#BrowseOutput()*
tlib#cmd#BrowseOutputWithCallback() tlib.txt /*tlib#cmd#BrowseOutputWithCallback()*
tlib#cmd#Time() tlib.txt /*tlib#cmd#Time()*
tlib#cmd#UseVertical() tlib.txt /*tlib#cmd#UseVertical()*
tlib#comments#Comments() tlib.txt /*tlib#comments#Comments()*
tlib#date#SecondsSince1970() tlib.txt /*tlib#date#SecondsSince1970()*
tlib#dir#CanonicName() tlib.txt /*tlib#dir#CanonicName()*
tlib#dir#Ensure() tlib.txt /*tlib#dir#Ensure()*
tlib#dir#MyRuntime() tlib.txt /*tlib#dir#MyRuntime()*
tlib#dir#NativeName() tlib.txt /*tlib#dir#NativeName()*
tlib#dir#PlainName() tlib.txt /*tlib#dir#PlainName()*
tlib#file#Edit() tlib.txt /*tlib#file#Edit()*
tlib#file#Join() tlib.txt /*tlib#file#Join()*
tlib#file#Relative() tlib.txt /*tlib#file#Relative()*
tlib#file#Split() tlib.txt /*tlib#file#Split()*
tlib#hook#Run() tlib.txt /*tlib#hook#Run()*
tlib#input#CommandSelect() tlib.txt /*tlib#input#CommandSelect()*
tlib#input#Edit() tlib.txt /*tlib#input#Edit()*
tlib#input#EditList() tlib.txt /*tlib#input#EditList()*
tlib#input#List() tlib.txt /*tlib#input#List()*
tlib#input#ListD() tlib.txt /*tlib#input#ListD()*
tlib#input#ListW() tlib.txt /*tlib#input#ListW()*
tlib#list#All() tlib.txt /*tlib#list#All()*
tlib#list#Any() tlib.txt /*tlib#list#Any()*
tlib#list#Compact() tlib.txt /*tlib#list#Compact()*
tlib#list#Find() tlib.txt /*tlib#list#Find()*
tlib#list#FindAll() tlib.txt /*tlib#list#FindAll()*
tlib#list#Flatten() tlib.txt /*tlib#list#Flatten()*
tlib#list#Inject() tlib.txt /*tlib#list#Inject()*
tlib#list#Remove() tlib.txt /*tlib#list#Remove()*
tlib#list#RemoveAll() tlib.txt /*tlib#list#RemoveAll()*
tlib#list#Zip() tlib.txt /*tlib#list#Zip()*
tlib#map#PumAccept() tlib.txt /*tlib#map#PumAccept()*
tlib#normal#WithRegister() tlib.txt /*tlib#normal#WithRegister()*
tlib#notify#Echo() tlib.txt /*tlib#notify#Echo()*
tlib#notify#TrimMessage() tlib.txt /*tlib#notify#TrimMessage()*
tlib#paragraph#GetMetric() tlib.txt /*tlib#paragraph#GetMetric()*
tlib#paragraph#Move() tlib.txt /*tlib#paragraph#Move()*
tlib#persistent#Dir() tlib.txt /*tlib#persistent#Dir()*
tlib#persistent#EncodedFilename() tlib.txt /*tlib#persistent#EncodedFilename()*
tlib#progressbar#Init() tlib.txt /*tlib#progressbar#Init()*
tlib#rx#Escape() tlib.txt /*tlib#rx#Escape()*
tlib#rx#EscapeReplace() tlib.txt /*tlib#rx#EscapeReplace()*
tlib#scratch#CloseScratch() tlib.txt /*tlib#scratch#CloseScratch()*
tlib#scratch#UseScratch() tlib.txt /*tlib#scratch#UseScratch()*
tlib#selection#GetSelection() tlib.txt /*tlib#selection#GetSelection()*
tlib#signs#ClearAll() tlib.txt /*tlib#signs#ClearAll()*
tlib#signs#ClearBuffer() tlib.txt /*tlib#signs#ClearBuffer()*
tlib#signs#Mark() tlib.txt /*tlib#signs#Mark()*
tlib#string#Format() tlib.txt /*tlib#string#Format()*
tlib#string#Printf1() tlib.txt /*tlib#string#Printf1()*
tlib#string#RemoveBackslashes() tlib.txt /*tlib#string#RemoveBackslashes()*
tlib#sys#IsSpecial() tlib.txt /*tlib#sys#IsSpecial()*
tlib#sys#MaybeUseCygpath() tlib.txt /*tlib#sys#MaybeUseCygpath()*
tlib#sys#Open() tlib.txt /*tlib#sys#Open()*
tlib#sys#OpenWithSystemViewer() tlib.txt /*tlib#sys#OpenWithSystemViewer()*
tlib#tab#BufMap() tlib.txt /*tlib#tab#BufMap()*
tlib#tab#TabWinNr() tlib.txt /*tlib#tab#TabWinNr()*
tlib#tag#Collect() tlib.txt /*tlib#tag#Collect()*
tlib#tag#Retrieve() tlib.txt /*tlib#tag#Retrieve()*
tlib#trace#Disable() tlib.txt /*tlib#trace#Disable()*
tlib#trace#Enable() tlib.txt /*tlib#trace#Enable()*
tlib#trace#Print() tlib.txt /*tlib#trace#Print()*
tlib#trace#Printer_echom() tlib.txt /*tlib#trace#Printer_echom()*
tlib#trace#Set() tlib.txt /*tlib#trace#Set()*
tlib#type#Disable() tlib.txt /*tlib#type#Disable()*
tlib#type#Enable() tlib.txt /*tlib#type#Enable()*
tlib#url#Decode() tlib.txt /*tlib#url#Decode()*
tlib#url#DecodeChar() tlib.txt /*tlib#url#DecodeChar()*
tlib#url#Encode() tlib.txt /*tlib#url#Encode()*
tlib#url#EncodeChar() tlib.txt /*tlib#url#EncodeChar()*
tlib#var#EGet() tlib.txt /*tlib#var#EGet()*
tlib#var#Get() tlib.txt /*tlib#var#Get()*
tlib#var#Let() tlib.txt /*tlib#var#Let()*
tlib#var#List() tlib.txt /*tlib#var#List()*
tlib#vcs#Diff() tlib.txt /*tlib#vcs#Diff()*
tlib#vcs#Ls() tlib.txt /*tlib#vcs#Ls()*
tlib#vim#Maximize() tlib.txt /*tlib#vim#Maximize()*
tlib#vim#RestoreWindow() tlib.txt /*tlib#vim#RestoreWindow()*
tlib#win#Set() tlib.txt /*tlib#win#Set()*
tlib#win#SetById() tlib.txt /*tlib#win#SetById()*
tlib.txt tlib.txt /*tlib.txt*
v_sp tlib.txt /*v_sp*

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,30 @@
*tlib.txt* tlib -- A library of vim functions
Author: Tom Link, micathom at gmail com
This library provides some utility functions. There isn't much need to
install it unless another plugin requires you to do so.
Most of the library is included in autoload files. No autocommands are
created. With the exception of loading ../plugin/02tlib.vim at startup
the library has no impact on startup time or anything else.
The change-log is included at the bottom of ../plugin/02tlib.vim
(move the cursor over the file name and type gfG)
Demo of |tlib#input#List()|:
http://vimsomnia.blogspot.com/2010/11/selecting-items-from-list-with-tlibs.html
-----------------------------------------------------------------------
Install~
Edit the vba file and type: >
:so %
See :help vimball for details. If you have difficulties, please make
sure, you have the current version of vimball (vimscript #1502)
installed.
%s

View file

@ -0,0 +1,38 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @GIT: http://github.com/tomtom/tlib_vim/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2015-11-09.
" @Revision: 10
if &cp || exists("loaded_tlib_macros")
finish
endif
let loaded_tlib_macros = 1
let s:save_cpo = &cpo
set cpo&vim
" :display: :TRequire NAME [VERSION [FILE]]
" Make a certain vim file is loaded.
"
" Conventions: If FILE isn't defined, plugin/NAME.vim is loaded. The
" file must provide a variable loaded_{NAME} that represents the version
" number.
command! -nargs=+ TRequire let s:require = [<f-args>]
\ | if !exists('loaded_'. get(s:require, 0))
\ | exec 'runtime '. get(s:require, 2, 'plugin/'. get(s:require, 0) .'.vim')
\ | if !exists('loaded_'. get(s:require, 0)) || loaded_{get(s:require, 0)} < get(s:require, 1, loaded_{get(s:require, 0)})
\ | echoerr 'Require '. get(s:require, 0) .' >= '. get(s:require, 1, 'any version will do')
\ | finish
\ | endif
\ | endif | unlet s:require
" :display: :Ttimecommand CMD
" Time the execution time of CMD.
command! -nargs=1 -complete=command Ttimecommand call tlib#cmd#Time(<q-args>)
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -1,8 +1,8 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim]) " @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Created: 2007-04-10. " @Created: 2007-04-10.
" @Last Change: 2015-11-23. " @Last Change: 2019-04-09.
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 808 " @Revision: 836
" @Website: http://www.vim.org/account/profile.php?user_id=4037 " @Website: http://www.vim.org/account/profile.php?user_id=4037
" GetLatestVimScripts: 1863 1 tlib.vim " GetLatestVimScripts: 1863 1 tlib.vim
" tlib.vim -- Some utility functions " tlib.vim -- Some utility functions
@ -14,7 +14,7 @@ if v:version < 700 "{{{2
echoerr "tlib requires Vim >= 7" echoerr "tlib requires Vim >= 7"
finish finish
endif endif
let g:loaded_tlib = 117 let g:loaded_tlib = 127
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
@ -74,7 +74,17 @@ command! -nargs=1 -complete=command TBrowseOutput call tlib#cmd#BrowseOutput(<q-
" "
" EXAMPLES: > " EXAMPLES: >
" TBrowseScriptnames " TBrowseScriptnames
command! -nargs=0 -complete=command TBrowseScriptnames call tlib#cmd#TBrowseScriptnames() command! -nargs=0 TBrowseScriptnames call tlib#cmd#TBrowseScriptnames()
" :display: :Texecqfl CMD
" Run CMD and display the quickfix list.
command! -nargs=1 Texecqfl <args> | call tlib#qfl#QflList(getqflist())
" :display: :Texecloc CMD
" Run CMD and display the quickfix list.
command! -nargs=1 Texecloc <args> | call tlib#qfl#QflList(getloclist(0))
" :display: :Tlibtrace GUARD, VAR1, VAR2... " :display: :Tlibtrace GUARD, VAR1, VAR2...
@ -85,17 +95,31 @@ command! -nargs=0 -complete=command TBrowseScriptnames call tlib#cmd#TBrowseScri
" If GUARD is a number that evaluates to true or if it is a string that " If GUARD is a number that evaluates to true or if it is a string that
" matches a |regexp|, which was added using Tlibtrace! (with '!'), " matches a |regexp|, which was added using Tlibtrace! (with '!'),
" display the values of VAR1, VAR2 ... " display the values of VAR1, VAR2 ...
command! -nargs=+ -bang -bar Tlibtrace : command! -nargs=+ -bang Tlibtrace :
" :Tlibtraceset +RX1, -RX2... " :Tlibtraceset[!] [--file=FILE] +RX1 -RX2...
" If |tlib#trace#Enable()| was called: With the optional <bang>, users " If |tlib#trace#Enable()| was called: With the optional <bang>, users
" can add and remove GUARDs (actually a |regexp|) that should be traced. " can add and remove GUARDs (actually a |regexp|) that should be traced.
command! -nargs=+ -bang -bar Tlibtraceset call tlib#trace#Set(<q-args>) "
" If no `+` or `-` is prepended, assume `+`.
"
" With the optional bang '!', reset any options.
command! -nargs=+ -bang Tlibtraceset call tlib#trace#Set(tlib#arg#GetOpts([<f-args>], {'short': 0}), !empty("<bang>"))
" :display: :Tlibtrace ASSERTION " :display: :Tlibtrace ASSERTION
command! -nargs=+ -bang -bar Tlibassert : command! -nargs=+ -bang Tlibassert :
" :display: :Tlibtype val, 'type', ...
command! -nargs=+ Tlibtype :
" Browse the current |quickfix| list.
command! -bar Tbrowseqfl call tlib#qfl#Browse()
" Browse the current |location-list|.
command! -bar Tbrowseloc call tlib#loclist#Browse()
let &cpo = s:save_cpo let &cpo = s:save_cpo

View file

@ -0,0 +1,50 @@
" The following variable configures the way |tlib#input#ListD()| works.
" In this example, we allow selection of multiple items (we could also
" allow only a single choice and make |tlib#input#ListD()| work on the
" indices, not the items).
"
" We also set a prompt that will be displayed in the command area.
"
" By default, |tlib#input#ListD()| will automatically select an item if
" there is only one item left matching the filter. In this example, we
" disable this feature.
"
" For demonstration purposes, we also define a key handler that prints
" the selected items.
let s:state = {
\ 'type': 'm',
\ 'query': 'Select lines for command output',
\ 'pick_last_item': 0,
\ 'key_handlers': [
\ {'key': 16, 'agent': 'PrintMe', 'key_name': '<c-p>', 'help': 'Print line'},
\ ],
\ }
" A key handler takes two arguments: the current state of the list
" display and a list of selected items/indices (depending on the type
" parameter).
function! PrintMe(state, items) "{{{3
echom "You selected:"
for i in a:items
echom i
endfor
call input("Press ENTER to continue")
let a:state.state = 'redisplay'
return a:state
endf
" In this example, we evaluate an ex-command with |:execute| and display
" the command's output as list. The user can select certain lines by
" typing some pattern or by pressing <a-NUMBER> to select an item by
" number. The user can then press <c-p> to print the lines (see above)
" or <cr> to pick the selected lines.
function! SelectOutput(ex) "{{{3
redir => lines
silent exec a:ex
redir END
let state = copy(s:state)
let state.base = split(lines, '\n')
let picked = tlib#input#ListD(state)
echom "You picked: ". join(picked, ', ')
endf

View file

@ -0,0 +1,67 @@
# @Author: Tom Link (micathom AT gmail com)
# @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
# @Revision: 14
def crc_vim_table
tbl = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
0x2d02ef8d]
tbl.map! do |num|
b = "%b" % num
bits = b.split(//)
bits.map! {|b| b.to_i}
bits.reverse
end
VIM::command("let @t = '#{tbl.inspect}'")
end

View file

@ -0,0 +1,66 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-03.
" @Last Change: 2010-04-03.
" @Revision: 1
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib#arg'
function! TestGetArg(...) "{{{3
exec tlib#arg#Get(1, 'foo', 1)
return foo
endf
function! TestGetArg1(...) "{{{3
exec tlib#arg#Get(1, 'foo', 1, '!= ""')
return foo
endf
Should be equal TestGetArg(), 1
Should be equal TestGetArg(''), ''
Should be equal TestGetArg(2), 2
Should be equal TestGetArg1(), 1
Should be equal TestGetArg1(''), 1
Should be equal TestGetArg1(2), 2
function! TestArgs(...) "{{{3
exec tlib#arg#Let([['foo', "o"], ['bar', 2]])
return repeat(foo, bar)
endf
Should be equal TestArgs(), 'oo'
Should be equal TestArgs('a'), 'aa'
Should be equal TestArgs('a', 3), 'aaa'
function! TestArgs1(...) "{{{3
exec tlib#arg#Let(['foo', ['bar', 2]])
return repeat(foo, bar)
endf
Should be equal TestArgs1(), ''
Should be equal TestArgs1('a'), 'aa'
Should be equal TestArgs1('a', 3), 'aaa'
function! TestArgs2(...) "{{{3
exec tlib#arg#Let(['foo', 'bar'], 1)
return repeat(foo, bar)
endf
Should be equal TestArgs2(), '1'
Should be equal TestArgs2('a'), 'a'
Should be equal TestArgs2('a', 3), 'aaa'
function! TestArgs3(...)
TVarArg ['a', 1], 'b'
return a . b
endf
Should be equal TestArgs3(), '1'
Should be equal TestArgs3('a'), 'a'
Should be equal TestArgs3('a', 3), 'a3'
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,61 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @GIT: http://github.com/tomtom/vimtlib/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-09-17.
" @Last Change: 2016-03-16.
" @Revision: 21
SpecBegin 'title': 'tlib#date'
Should be equal tlib#date#Parse('2000-1-0', 1), [2000, 1, 0]
Should be equal tlib#date#Parse('2000-1-2'), [2000, 1, 2]
Should be equal tlib#date#Parse('2000-01-02'), [2000, 1, 2]
Should be equal tlib#date#Parse('2000-10-20'), [2000, 10, 20]
Should be equal tlib#date#Parse('00-1-0', 1), [2000, 1, 0]
Should be equal tlib#date#Parse('00-1-2'), [2000, 1, 2]
Should be equal tlib#date#Parse('00-01-02'), [2000, 1, 2]
Should be equal tlib#date#Parse('00-10-20'), [2000, 10, 20]
Should be equal tlib#date#Parse('2000/2/1'), [2000, 1, 2]
Should be equal tlib#date#Parse('2000/02/01'), [2000, 1, 2]
Should be equal tlib#date#Parse('2000/20/10'), [2000, 10, 20]
Should be equal tlib#date#Parse('00/2/1'), [2000, 1, 2]
Should be equal tlib#date#Parse('00/02/01'), [2000, 1, 2]
Should be equal tlib#date#Parse('00/20/10'), [2000, 10, 20]
Should be equal tlib#date#Parse('2.1.2000'), [2000, 1, 2]
Should be equal tlib#date#Parse('2. 1. 2000'), [2000, 1, 2]
Should be equal tlib#date#Parse('02.01.2000'), [2000, 1, 2]
Should be equal tlib#date#Parse('02. 01. 2000'), [2000, 1, 2]
Should be equal tlib#date#Parse('20.10.2000'), [2000, 10, 20]
Should be equal tlib#date#Parse('20. 10. 2000'), [2000, 10, 20]
Should throw exception "tlib#date#Parse('2000-14-2')", 'TLib: Invalid date'
Should throw exception "tlib#date#Parse('2000-011-02')", 'TLib: Invalid date'
Should throw exception "tlib#date#Parse('2000-10-40')", 'TLib: Invalid date'
Should throw exception "tlib#date#Parse('2000-10-0')", 'TLib: Invalid date'
Should be equal tlib#date#Shift('2015-10-29', '1m'), '2015-11-29'
Should be equal tlib#date#Shift('2015-11-29', '1m'), '2015-12-29'
Should be equal tlib#date#Shift('2015-12-29', '1m'), '2016-01-29'
Should be equal tlib#date#Shift('2016-01-29', '1m'), '2016-02-29'
Should be equal tlib#date#Shift('2015-10-29', '2m'), '2015-12-29'
Should be equal tlib#date#Shift('2015-10-29', '3m'), '2016-01-29'
Should be equal tlib#date#Shift('2015-10-29', '4m'), '2016-02-29'
Should be equal tlib#date#Shift('2015-12-30', '1d'), '2015-12-31'
Should be equal tlib#date#Shift('2015-12-31', '1d'), '2016-01-01'
Should be equal tlib#date#Shift('2015-12-30', '2d'), '2016-01-01'
Should be equal tlib#date#Shift('2015-12-30', '3d'), '2016-01-02'
Should be equal tlib#date#Shift('2016-03-16', '1b'), '2016-03-17'
Should be equal tlib#date#Shift('2016-03-16', '2b'), '2016-03-18'
Should be equal tlib#date#Shift('2016-03-16', '3b'), '2016-03-21'
Should be equal tlib#date#Shift('2016-03-16', '4b'), '2016-03-22'
Should be equal tlib#date#Shift('2016-03-16', '5b'), '2016-03-23'
Should be equal tlib#date#Shift('2016-03-16', '6b'), '2016-03-24'
Should be equal tlib#date#Shift('2016-03-16', '7b'), '2016-03-25'
Should be equal tlib#date#Shift('2016-03-16', '8b'), '2016-03-28'

View file

@ -0,0 +1,28 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: https://github.com/tomtom
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2016-04-03.
" @Last Change: 2016-04-03.
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib#dictionary'
It should handle basic test cases for tlib#dictionary#Rev properly.
Should be equal tlib#dictionary#Rev({}), {}
Should be equal tlib#dictionary#Rev({1: 2, 3: 4}), {'2': '1', '4': '3'}
Should be equal tlib#dictionary#Rev({1: '', 3: 4}, {'empty': '*'}), {'*': '1', '4': '3'}
Should be equal tlib#dictionary#Rev({1: '', 3: 4}, {'use_string': 1}), {'''''': '1', '4': '3'}
Should be equal tlib#dictionary#Rev({1: '', 3: 4}, {'use_string': 1, 'use_eval': 1}), {'''''': 1, '4': 3}
Should be equal tlib#dictionary#Rev(tlib#dictionary#Rev({1: '', 3: 4}, {'use_string': 1}), {'use_eval': 1}), {1: '', 3: 4}
Should be equal tlib#dictionary#Rev({1: 4, 2: 4}, {'values_as_list': 1}), {'4': ['1', '2']}
Should be equal tlib#dictionary#Rev({1: 4, 2: 4}, {'values_as_list': 1, 'use_eval': 1}), {'4': [1, 2]}
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,27 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: https://github.com/tomtom
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2015-10-26.
" @Last Change: 2015-10-26.
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib#eval'
let g:eval_a = {'foo': range(0, 5), 'd': {'a': range(0, 5)}}
let g:eval_b = {'foo': range(6, 10), 'd': {'a': range(6, 10), 'b': 2}, 'bar': range(5)}
let g:eval_a0 = deepcopy(g:eval_a)
let g:eval_b0 = deepcopy(g:eval_b)
let g:eval_c = {'foo': range(0, 10), 'd': {'a': range(0, 10), 'b': 2}, 'bar': range(5)}
Should be equal tlib#eval#Extend(copy(g:eval_a), g:eval_b), g:eval_c
Should be equal g:eval_a, g:eval_a0
Should be equal g:eval_b, g:eval_b0
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,59 @@
" @Author: Thomas Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @GIT: http://github.com/tomtom/vimtlib/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2009-02-25.
" @Last Change: 2010-04-03.
" @Revision: 13
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib/file',
\ 'sfile': 'autoload/tlib/file.vim'
It should split filenames.
Should be equal tlib#file#Split('foo/bar/filename.txt'), ['foo', 'bar', 'filename.txt']
Should be equal tlib#file#Split('/foo/bar/filename.txt'), ['', 'foo', 'bar', 'filename.txt']
Should be equal tlib#file#Split('ftp://foo/bar/filename.txt'), ['ftp:/', 'foo', 'bar', 'filename.txt']
It should join filenames.
Should be#Equal tlib#file#Join(['foo', 'bar']), 'foo/bar'
Should be#Equal tlib#file#Join(['foo/', 'bar'], 1), 'foo/bar'
Should be#Equal tlib#file#Join(['', 'bar']), '/bar'
Should be#Equal tlib#file#Join(['/', 'bar'], 1), '/bar'
Should be#Equal tlib#file#Join(['foo', 'bar', 'filename.txt']), 'foo/bar/filename.txt'
Should be#Equal tlib#file#Join(['', 'foo', 'bar', 'filename.txt']), '/foo/bar/filename.txt'
Should be#Equal tlib#file#Join(['ftp:/', 'foo', 'bar', 'filename.txt']), 'ftp://foo/bar/filename.txt'
Should be#Equal tlib#file#Join(['ftp://', 'foo', 'bar', 'filename.txt'], 1), 'ftp://foo/bar/filename.txt'
Should be equal tlib#file#Join(['foo', 'bar', 'filename.txt']), 'foo/bar/filename.txt'
Should be equal tlib#file#Join(['', 'foo', 'bar', 'filename.txt']), '/foo/bar/filename.txt'
Should be equal tlib#file#Join(['ftp:/', 'foo', 'bar', 'filename.txt']), 'ftp://foo/bar/filename.txt'
It should construct relative path names.
Should be#Equal tlib#file#Relative('foo/bar/filename.txt', 'foo'), 'bar/filename.txt'
Should be#Equal tlib#file#Relative('foo/bar/filename.txt', 'foo/base'), '../bar/filename.txt'
Should be#Equal tlib#file#Relative('filename.txt', 'foo/base'), '../../filename.txt'
Should be#Equal tlib#file#Relative('/foo/bar/filename.txt', '/boo/base'), '../../foo/bar/filename.txt'
Should be#Equal tlib#file#Relative('/bar/filename.txt', '/boo/base'), '../../bar/filename.txt'
Should be#Equal tlib#file#Relative('/foo/bar/filename.txt', '/base'), '../foo/bar/filename.txt'
Should be#Equal tlib#file#Relative('c:/bar/filename.txt', 'x:/boo/base'), 'c:/bar/filename.txt'
Should be equal tlib#file#Relative('foo/bar/filename.txt', 'foo'), 'bar/filename.txt'
Should be equal tlib#file#Relative('foo/bar/filename.txt', 'foo/base'), '../bar/filename.txt'
Should be equal tlib#file#Relative('filename.txt', 'foo/base'), '../../filename.txt'
Should be equal tlib#file#Relative('/foo/bar/filename.txt', '/boo/base'), '../../foo/bar/filename.txt'
Should be equal tlib#file#Relative('/bar/filename.txt', '/boo/base'), '../../bar/filename.txt'
Should be equal tlib#file#Relative('/foo/bar/filename.txt', '/base'), '../foo/bar/filename.txt'
Should be equal tlib#file#Relative('c:/bar/filename.txt', 'x:/boo/base'), 'c:/bar/filename.txt'
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,58 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 31
SpecBegin 'title': 'tlib#hash'
It should calculate CRC32B checksums.
let g:tlib_hash_use_crc32 = g:tlib#hash#use_crc32
let g:tlib#hash#use_crc32 = 'ruby'
Should be equal tlib#hash#CRC32B('The quick brown fox jumps over the lazy dog'), '414FA339'
Should be equal tlib#hash#CRC32B('foo'), '8C736521'
Should be equal tlib#hash#CRC32B('f'), '76D32BE0'
let g:tlib#hash#use_crc32 = 'vim'
Should be equal tlib#hash#CRC32B('The quick brown fox jumps over the lazy dog'), '414FA339'
Should be equal tlib#hash#CRC32B('foo'), '8C736521'
Should be equal tlib#hash#CRC32B('f'), '76D32BE0'
function! s:CompareHash(text) "{{{3
if !empty(a:text)
exec 'It should calculate the crc32b checksum for:' a:text
let crc32ruby = tlib#hash#CRC32B_ruby(a:text)
let crc32vim = tlib#hash#CRC32B_vim(a:text)
exec 'Should be equal' string(crc32ruby) ',' string(crc32vim)
exec 'It should calculate the adler32 checksum for:' a:text
let adler32tlib = tlib#hash#Adler32_tlib(a:text)
let adler32vim = tlib#hash#Adler32_vim(a:text)
exec 'Should be equal' string(adler32tlib) ',' string(adler32vim)
endif
endf
redir => s:scriptnames
silent scriptnames
redir END
for s:script in split(s:scriptnames, '\n')
let s:scriptfile = matchstr(s:script, '^\s*\d\+:\s\+\zs.*$')
call s:CompareHash(s:scriptfile)
try
let s:scriptlines = readfile(s:scriptfile)
call s:CompareHash(join(s:scriptlines, "\n"))
for s:scriptline in s:scriptlines
call s:CompareHash(s:scriptline)
endfor
catch /^Vim\%((\a\+)\)\=:E484/
endtry
endfor
unlet s:scriptnames, :script, s:scriptfile, s:scriptlines, s:scriptline
delf s:CompareHash
let g:tlib#hash#use_crc32 = g:tlib_hash_use_crc32

View file

@ -0,0 +1,127 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @GIT: http://github.com/tomtom/vimtlib/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2009-02-28.
" @Last Change: 2009-03-14.
" @Revision: 73
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib: Input', 'scratch': '%',
\ 'after': ':unlet! g:spec_lib_rv',
\ 'options': [
\ 'vim',
\ ]
let g:spec_tlib_list = [10, 20, 30, 40, 'a50', 'aa60', 'b70', 'ba80', 90]
It should return empty values when the user presses <escape>.
Replay :let g:spec_lib_rv = tlib#input#List('s', '', g:spec_tlib_list)\<cr>
\ \<Down>\<Down>\<esc>
Should be#Equal g:spec_lib_rv, ''
Replay :let g:spec_lib_rv = tlib#input#List('m', '', g:spec_tlib_list)\<cr>
\ \<Down>\<Down>\<esc>
Should be#Equal g:spec_lib_rv, []
Replay :let g:spec_lib_rv = tlib#input#List('si', '', g:spec_tlib_list)\<cr>
\ \<Down>\<Down>\<esc>
Should be#Equal g:spec_lib_rv, 0
It should pick an item from s-type list.
Replay :let g:spec_lib_rv = tlib#input#List('s', '', g:spec_tlib_list)\<cr>
\ \<Down>\<Down>\<cr>
Should be#Equal g:spec_lib_rv, 30
It should return an index from si-type list.
Replay :let g:spec_lib_rv = tlib#input#List('si', '', g:spec_tlib_list)\<cr>
\ \<Down>\<Down>\<cr>
Should be#Equal g:spec_lib_rv, 3
It should return a list from a m-type list.
Replay :let g:spec_lib_rv = tlib#input#List('m', '', g:spec_tlib_list)\<cr>
\ \<Down>#\<Down>\<Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), [20, 40]
Replay :let g:spec_lib_rv = tlib#input#List('m', '', g:spec_tlib_list)\<cr>
\ \<Down>\<S-Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), [20, 30]
Replay :let g:spec_lib_rv = tlib#input#List('m', '', g:spec_tlib_list)\<cr>
\ \<Down>\<Down>\<S-up>\<cr>
Should be#Equal sort(g:spec_lib_rv), [20, 30]
It should return a list of indices from a mi-type list.
Replay :let g:spec_lib_rv = tlib#input#List('mi', '', g:spec_tlib_list)\<cr>
\ \<Down>#\<Down>\<Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), [2, 4]
Replay :let g:spec_lib_rv = tlib#input#List('mi', '', g:spec_tlib_list)\<cr>
\ \<Down>\<S-Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), [2, 3]
Replay :let g:spec_lib_rv = tlib#input#List('mi', '', g:spec_tlib_list)\<cr>
\ \<Down>\<Down>\<S-up>\<cr>
Should be#Equal sort(g:spec_lib_rv), [2, 3]
It should filter items from a s-type list.
Replay :let g:spec_lib_rv = tlib#input#List('s', '', g:spec_tlib_list)\<cr>
\ \<Down>a\<Down>\<cr>
Should be#Equal g:spec_lib_rv, 'aa60'
It should filter items from a si-type list.
Replay :let g:spec_lib_rv = tlib#input#List('si', '', g:spec_tlib_list)\<cr>
\ \<Down>a\<Down>\<cr>
Should be#Equal g:spec_lib_rv, 6
It should filter items from a m-type list.
Replay :let g:spec_lib_rv = tlib#input#List('m', '', g:spec_tlib_list)\<cr>
\ a\<Down>#\<Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), ['aa60', 'ba80']
Replay :let g:spec_lib_rv = tlib#input#List('m', '', g:spec_tlib_list)\<cr>
\ a\<Down>\<S-Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), ['aa60', 'ba80']
Replay :let g:spec_lib_rv = tlib#input#List('m', '', g:spec_tlib_list)\<cr>
\ a\<Down>\<Down>\<S-up>\<cr>
Should be#Equal sort(g:spec_lib_rv), ['aa60', 'ba80']
It should filter items from a mi-type list.
Replay :let g:spec_lib_rv = tlib#input#List('mi', '', g:spec_tlib_list)\<cr>
\ a\<Down>#\<Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), [6, 8]
Replay :let g:spec_lib_rv = tlib#input#List('mi', '', g:spec_tlib_list)\<cr>
\ a\<Down>\<S-Down>\<cr>
Should be#Equal sort(g:spec_lib_rv), [6, 8]
Replay :let g:spec_lib_rv = tlib#input#List('mi', '', g:spec_tlib_list)\<cr>
\ a\<Down>\<Down>\<S-up>\<cr>
Should be#Equal sort(g:spec_lib_rv), [6, 8]
let &cpo = s:save_cpo

View file

@ -0,0 +1,67 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-03.
" @Last Change: 2010-04-03.
" @Revision: 4
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib: List'
" \, 'options': [vim, <+SET+>]
" \, 'sfile': '<+SCRIPT CONTEXT+>'
" \, 'scratch': '<+SCRATCH FILE+>'
" \, 'before': '<+BEFORE EX COMMANDS+>'
" \, 'after': '<+AFTER EX COMMANDS+>'
" \, 'cleanup': ['<+FUNCTION+>()']
" List {{{2
fun! Add(a,b)
return a:a + a:b
endf
Should be equal tlib#list#Inject([], 0, function('Add')), 0
Should be equal tlib#list#Inject([1,2,3], 0, function('Add')), 6
Should be equal tlib#list#Compact([]), []
Should be equal tlib#list#Compact([0,1,2,3,[], {}, ""]), [1,2,3]
Should be equal tlib#list#Flatten([]), []
Should be equal tlib#list#Flatten([1,2,3]), [1,2,3]
Should be equal tlib#list#Flatten([1,2, [1,2,3], 3]), [1,2,1,2,3,3]
Should be equal tlib#list#Flatten([0,[1,2,[3,""]]]), [0,1,2,3,""]
Should be equal tlib#list#FindAll([1,2,3], 'v:val >= 2'), [2,3]
Should be equal tlib#list#FindAll([1,2,3], 'v:val >= 2', 'v:val * 10'), [20,30]
Should be equal tlib#list#Find([1,2,3], 'v:val >= 2'), 2
Should be equal tlib#list#Find([1,2,3], 'v:val >= 2', 0, 'v:val * 10'), 20
Should be equal tlib#list#Find([1,2,3], 'v:val >= 5', 10), 10
Should be equal tlib#list#Any([1,2,3], 'v:val >= 2'), 1
Should be equal tlib#list#Any([1,2,3], 'v:val >= 5'), 0
Should be equal tlib#list#All([1,2,3], 'v:val < 5'), 1
Should be equal tlib#list#All([1,2,3], 'v:val >= 2'), 0
Should be equal tlib#list#Remove([1,2,1,2], 2), [1,1,2]
Should be equal tlib#list#RemoveAll([1,2,1,2], 2), [1,1]
Should be equal tlib#list#Zip([[1,2,3], [4,5,6]]), [[1,4], [2,5], [3,6]]
Should be equal tlib#list#Zip([[1,2,3], [4,5,6,7]]), [[1,4], [2,5], [3,6], ['', 7]]
Should be equal tlib#list#Zip([[1,2,3], [4,5,6,7]], -1), [[1,4], [2,5], [3,6], [-1,7]]
Should be equal tlib#list#Zip([[1,2,3,7], [4,5,6]], -1), [[1,4], [2,5], [3,6], [7,-1]]
Should be equal tlib#list#Uniq([]), []
Should be equal tlib#list#Uniq([1,1]), [1]
Should be equal tlib#list#Uniq([1,2,2,3,2,3,4,2,1,7,2,3,2,3,7]), [1,2,3,4,7]
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,27 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-03.
" @Last Change: 2010-04-03.
" @Revision: 2
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib#rx'
for c in split('^$.*+\()|{}[]~', '\zs')
let s = printf('%sfoo%sbar%s', c, c, c)
Should be like s, '\m^'. tlib#rx#Escape(s, 'm') .'$'
Should be like s, '\M^'. tlib#rx#Escape(s, 'M') .'$'
Should be like s, '\v^'. tlib#rx#Escape(s, 'v') .'$'
Should be like s, '\V\^'. tlib#rx#Escape(s, 'V') .'\$'
endfor
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,29 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-03.
" @Last Change: 2010-04-03.
" @Revision: 4
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib#string'
Should be equal tlib#string#RemoveBackslashes('foo bar'), 'foo bar'
Should be equal tlib#string#RemoveBackslashes('foo\ bar'), 'foo bar'
Should be equal tlib#string#RemoveBackslashes('foo\ \\bar'), 'foo \\bar'
Should be equal tlib#string#RemoveBackslashes('foo\ \\bar', '\ '), 'foo \bar'
Should be equal tlib#string#Count("fooo", "o"), 3
Should be equal tlib#string#Count("***", "\\*"), 3
Should be equal tlib#string#Count("***foo", "\\*"), 3
Should be equal tlib#string#Count("foo***", "\\*"), 3
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,23 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-03.
" @Last Change: 2010-04-03.
" @Revision: 2
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib#url'
Should be equal tlib#url#Decode('http://example.com/foo+bar%25bar'), 'http://example.com/foo bar%bar'
Should be equal tlib#url#Decode('Hello%20World.%20%20Good%2c%20bye.'), 'Hello World. Good, bye.'
Should be equal tlib#url#Encode('foo bar%bar'), 'foo+bar%%bar'
Should be equal tlib#url#Encode('Hello World. Good, bye.'), 'Hello+World.+Good%2c+bye.'
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,37 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-03.
" @Last Change: 2010-04-03.
" @Revision: 2
let s:save_cpo = &cpo
set cpo&vim
SpecBegin 'title': 'tlib#var'
let g:foo = 1
let g:bar = 2
let b:bar = 3
let s:bar = 4
Should be equal tlib#var#Get('bar', 'bg'), 3
Should be equal tlib#var#Get('bar', 'g'), 2
Should be equal tlib#var#Get('foo', 'bg'), 1
Should be equal tlib#var#Get('foo', 'g'), 1
Should be equal tlib#var#Get('none', 'l'), ''
Should be equal eval(tlib#var#EGet('bar', 'bg')), 3
Should be equal eval(tlib#var#EGet('bar', 'g')), 2
" Should be equal eval(tlib#var#EGet('bar', 'sg')), 4
Should be equal eval(tlib#var#EGet('foo', 'bg')), 1
Should be equal eval(tlib#var#EGet('foo', 'g')), 1
Should be equal eval(tlib#var#EGet('none', 'l')), ''
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -2369,7 +2369,7 @@ function! fugitive#FileReadCmd(...) abort
endfunction endfunction
function! fugitive#FileWriteCmd(...) abort function! fugitive#FileWriteCmd(...) abort
let tmp = tempname() let temp = tempname()
let amatch = a:0 ? a:1 : expand('<amatch>') let amatch = a:0 ? a:1 : expand('<amatch>')
let autype = a:0 > 1 ? 'Buf' : 'File' let autype = a:0 > 1 ? 'Buf' : 'File'
if exists('#' . autype . 'WritePre') if exists('#' . autype . 'WritePre')
@ -2380,17 +2380,13 @@ function! fugitive#FileWriteCmd(...) abort
if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$')) if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$'))
return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch) return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch)
endif endif
if exists('+guioptions') && &guioptions =~# '!' silent execute "noautocmd keepalt '[,']write ".temp
let guioptions = &guioptions let hash = s:TreeChomp([dir, 'hash-object', '-w', '--', temp])
set guioptions-=!
endif
silent execute "'[,']write !".fugitive#Prepare(dir, 'hash-object', '-w', '--stdin', '--').' > '.tmp
let sha1 = readfile(tmp)[0]
let old_mode = matchstr(s:ChompError(['ls-files', '--stage', '.' . file], dir)[0], '^\d\+') let old_mode = matchstr(s:ChompError(['ls-files', '--stage', '.' . file], dir)[0], '^\d\+')
if empty(old_mode) if empty(old_mode)
let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644' let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644'
endif endif
let error = s:UpdateIndex(dir, [old_mode, sha1, commit, file[1:-1]]) let error = s:UpdateIndex(dir, [old_mode, hash, commit, file[1:-1]])
if empty(error) if empty(error)
setlocal nomodified setlocal nomodified
if exists('#' . autype . 'WritePost') if exists('#' . autype . 'WritePost')
@ -2400,11 +2396,10 @@ function! fugitive#FileWriteCmd(...) abort
else else
return 'echoerr '.string('fugitive: '.error) return 'echoerr '.string('fugitive: '.error)
endif endif
catch /^fugitive:/
return 'echoerr ' . string(v:exception)
finally finally
if exists('guioptions') call delete(temp)
let &guioptions = guioptions
endif
call delete(tmp)
endtry endtry
endfunction endfunction

View file

@ -13,7 +13,8 @@ let s:bad_git_dir = '/$\|^fugitive:'
" FugitiveGitDir() returns the detected Git dir for the given buffer number, " FugitiveGitDir() returns the detected Git dir for the given buffer number,
" or the current buffer if no argument is passed. This will be an empty " or the current buffer if no argument is passed. This will be an empty
" string if no Git dir was found. Use !empty(FugitiveGitDir()) to check if " string if no Git dir was found. Use !empty(FugitiveGitDir()) to check if
" Fugitive is active in the current buffer. " Fugitive is active in the current buffer. Do not rely on this for direct
" filesystem access; use FugitiveFind('.git/whatever') instead.
function! FugitiveGitDir(...) abort function! FugitiveGitDir(...) abort
if v:version < 704 if v:version < 704
return '' return ''