From 40384fb526232ae78bd4c0bb5574638784b07141 Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Fri, 21 May 2021 15:51:05 -0700 Subject: [PATCH] feat: add trim bry words config option --- README.md | 13 +++++++++++++ lua/nvim-biscuits/config.lua | 3 ++- lua/nvim-biscuits/init.lua | 19 ++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9f9a6df..8ae3a8d 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,19 @@ You may have tree-sitter set up for some languages in which you don't want nvim- To disable nvim-biscuits for any language, simply add `{ mylanguage = {disabled = true} }` to `language_config` field in setup. (where `mylanguage` is the language that you want to disable. eg: `python`, `dart`, etc) +## Configuration (Trim by words) + +Using this settings, you can dictate the max length of a biscuit using whole words rather than just characters. The `max_length` determines how many words will show when this setting is enabled. + +```lua +lua <= max_length then - text = string.sub(text, 1, max_length) - text = text..'...' + if trim_by_words == true then + local words = {} + for word in string.gmatch(text, "%w+") do + words[#words+1] = word + if #words >= max_length then + break + end + end + text = table.concat(words, " ") + else + if string.len(text) >= max_length then + text = string.sub(text, 1, max_length) + text = text..'...' + end end text = text:gsub("\n", ' ')