Mercurial > dotfiles
changeset 617:d130c5c8b4e9
improve indent trimming on copy
author | zegervdv <zegervdv@me.com> |
---|---|
date | Tue, 26 Jul 2022 09:30:08 +0200 |
parents | 08bb1c92e5e5 |
children | 7d581ebd5508 |
files | .chezmoitemplates/init.lua |
diffstat | 1 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/.chezmoitemplates/init.lua Sun Jul 24 14:48:01 2022 +0200 +++ b/.chezmoitemplates/init.lua Tue Jul 26 09:30:08 2022 +0200 @@ -32,9 +32,18 @@ require('osc52').setup { trim = false } local copy = function(lines, _) -- Trim indent before copying - local indent, _ = lines[1]:find '[^ ]' - for key, line in ipairs(lines) do - lines[key] = line:sub(indent) + local indent = 0 + for _, line in ipairs(lines) do + local index, _ = line:find '[^ ]' + if index ~= nil then + indent = index + break + end + end + if indent ~= nil then + for key, line in ipairs(lines) do + lines[key] = line:sub(indent) + end end require('osc52').copy(table.concat(lines, '\n')) end