]> git.wincent.com - pinnacle.git/commitdiff
refactor!: remove sub_newlines and capture_line from Lua API
authorGreg Hurrell <greg@hurrell.net>
Mon, 12 Oct 2020 14:19:57 +0000 (16:19 +0200)
committerGreg Hurrell <greg@hurrell.net>
Mon, 12 Oct 2020 14:19:57 +0000 (16:19 +0200)
Because these are ancient methods that were only added to support
ancient versions of Vim (ie. before `execute()` existed). For context,
see:

- https://github.com/wincent/wincent/commit/3b0b2950cdcb09d23c87f0167c207d8c837cb1b2
- https://github.com/wincent/wincent/commit/386edd17854e609fe9dd9736524798e7057eefe7

Back in the old days, we used to capture the output of `:highlight`
with `:redir`, and it was sensitive to terminal width, which meant that
lines could wrap and wreak havoc. In newer Vim we just use `execute()`
which is width-agnostic, and in Neovim we can be even more direct
and call `nvim_exec()`. ie. instead of going Lua to Vimscript (eg.
`vim.fn.execute`) to turn a string into a command to run, we can go from
Lua directly to running the command.

README.md
autoload/pinnacle.vim
doc/pinnacle.txt
lua/wincent/pinnacle.lua

index 53bdd9f97967443a73f9c0b701bc933be49c55d1..f959b78b4f4a57c7d00d696fc717d55ae87e8353 100644 (file)
--- a/README.md
+++ b/README.md
@@ -35,6 +35,8 @@ To generate help tags under Pathogen, you can do so from inside Vim with:
 
 Replaces newlines with spaces.
 
+Note that this function is not implemented in the Lua API, because it is required only for support on legacy Vim versions.
+
 <p align="right"><a name="pinnaclecaptureline" href="#user-content-pinnaclecaptureline"><code>pinnacle#capture_line()</code></a></p>
 
 ### `pinnacle#capture_line()`<a name="pinnacle-pinnaclecaptureline" href="#user-content-pinnacle-pinnaclecaptureline"></a>
@@ -43,6 +45,8 @@ Runs a command and returns the captured output as a single line.
 
 Useful when we don't want to let long lines on narrow windows produce unwanted embedded newlines.
 
+Note that this function is not implemented in the Lua API, because it is required only for support on legacy Vim versions.
+
 <p align="right"><a name="pinnaclecapturehighlight" href="#user-content-pinnaclecapturehighlight"><code>pinnacle#capture_highlight()</code></a></p>
 
 ### `pinnacle#capture_highlight()`<a name="pinnacle-pinnaclecapturehighlight" href="#user-content-pinnacle-pinnaclecapturehighlight"></a>
index 2177ad7739eb4376c0e35bb39d2f80be87e652cb..e8d8a5cafffa1228f36f5582f003f96cc012bf23 100644 (file)
 "
 " Replaces newlines with spaces.
 "
+" Note that this function is not implemented in the Lua API, because it is
+" required only for support on legacy Vim versions.
+"
 function! pinnacle#sub_newlines(string) abort
   return tr(a:string, "\r\n", '  ')
 endfunction
@@ -180,6 +183,9 @@ endfunction
 " Useful when we don't want to let long lines on narrow windows produce unwanted
 " embedded newlines.
 "
+" Note that this function is not implemented in the Lua API, because it is
+" required only for support on legacy Vim versions.
+"
 function! pinnacle#capture_line(command) abort
   if exists('*execute')
     let l:capture=execute(a:command)
index 0f24f446215dadc00792fca4814a658ff462891d..b8a7efa75af445f7929354b93f0719adfdf78c02 100644 (file)
@@ -44,6 +44,9 @@ pinnacle#sub_newlines() ~
 
 Replaces newlines with spaces.
 
+Note that this function is not implemented in the Lua API, because it is
+required only for support on legacy Vim versions.
+
                                                        *pinnacle#capture_line()*
 pinnacle#capture_line() ~
 
@@ -52,6 +55,9 @@ Runs a command and returns the captured output as a single line.
 Useful when we don't want to let long lines on narrow windows produce
 unwanted embedded newlines.
 
+Note that this function is not implemented in the Lua API, because it is
+required only for support on legacy Vim versions.
+
                                                   *pinnacle#capture_highlight()*
 pinnacle#capture_highlight() ~
 
index ed998791c5a02ee6bc42664795e4c173c4348cab..d8486e99e80ba0766c411ae503c3d480f150f1ce 100644 (file)
@@ -10,17 +10,7 @@ end
 
 -- Gets the current value of a highlight group.
 pinnacle.capture_highlight = function(group)
-  return pinnacle.capture_line('0verbose silent highlight ' .. group)
-end
-
--- Runs a command and returns the captured output as a single line.
---
--- Useful when we don't want to let long lines on narrow windows produce
--- unwanted embedded newlines.
-pinnacle.capture_line = function(command)
-  local capture = vim.fn.execute(command)
-
-  return pinnacle.sub_newlines(capture)
+  return vim.api.nvim_exec('0verbose silent highlight ' .. group, true)
 end
 
 -- Returns a copy of `group` decorated with `style` (eg. "bold",
@@ -51,7 +41,7 @@ pinnacle.decorate = function(style, group)
       original = before .. setting .. after
     end
 
-    return pinnacle.sub_newlines(original)
+    return original
   end
 end
 
@@ -150,11 +140,6 @@ pinnacle.italicize = function(group)
   return pinnacle.decorate('italic', group)
 end
 
--- Replaces newlines with spaces.
-pinnacle.sub_newlines = function(string)
-  return ({string:gsub('[\r\n]', ' ')})[1]
-end
-
 -- Returns an underlined copy of `group` suitable for passing to
 -- `:highlight`.
 pinnacle.underline = function(group)