From 8c5bf8c7467cf28da2ac5de4f2eaa966f02b2b48 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 31 Aug 2020 18:12:51 -0400 Subject: wip: Messing around w/ ffi for some stuff --- lua/telescope/utils.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lua/telescope/utils.lua') 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 -- cgit v1.2.3