diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-08-31 18:12:51 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-08-31 18:12:51 -0400 |
| commit | 8c5bf8c7467cf28da2ac5de4f2eaa966f02b2b48 (patch) | |
| tree | 759150e002a4237cabea5469973323eb7d0cbe7c /lua/telescope/utils.lua | |
| parent | e38589f265a276d431113efcef6fdb157120ce68 (diff) | |
wip: Messing around w/ ffi for some stuff
Diffstat (limited to 'lua/telescope/utils.lua')
| -rw-r--r-- | lua/telescope/utils.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index eba24a6..2533c12 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -74,4 +74,37 @@ utils.new_ngram = function() return require("telescope._private.NGram"):new() end +-- TODO: Figure out how to do this... could include in plenary :) +-- NOTE: Don't use this yet. It will segfault sometimes. +-- +-- opts.shorten_path and function(value) +-- local result = { +-- valid = true, +-- display = utils.path_shorten(value), +-- ordinal = value, +-- value = value +-- } + +-- return result +-- end or nil) +utils.path_shorten = (function() + if jit then + local ffi = require('ffi') + ffi.cdef [[ + typedef unsigned char char_u; + char_u *shorten_dir(char_u *str); + ]] + + return function(path) + local c_str = ffi.new("char[?]", #path) + ffi.copy(c_str, path) + return ffi.string(ffi.C.shorten_dir(c_str)) + end + else + return function(path) + return path + end + end +end)() + return utils |
