Skip to content

Commit

Permalink
Don't use autocmd Lua API on older versions of Nvim
Browse files Browse the repository at this point in the history
It's easy enough to support old versions. Supporting the version
supported by the oldest Ubuntu LTS seems reasonable.

Fixes: #28
  • Loading branch information
gpanders committed Nov 19, 2022
1 parent 91db270 commit 2af8809
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 67 deletions.
29 changes: 0 additions & 29 deletions after/plugin/editorconfig.lua

This file was deleted.

26 changes: 26 additions & 0 deletions after/plugin/editorconfig.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
" Copyright 2022 Gregory Anders
"
" SPDX-License-Identifier: GPL-3.0-or-later
"
" This program is free software: you can redistribute it and/or modify it under
" the terms of the GNU General Public License as published by the Free Software
" Foundation, either version 3 of the License, or (at your option) any later
" version.
"
" This program is distributed in the hope that it will be useful, but WITHOUT
" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
" FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
" details.
"
" You should have received a copy of the GNU General Public License along with
" this program. If not, see <https://www.gnu.org/licenses/>.

if exists('g:loaded_editorconfig')
finish
endif
let g:loaded_editorconfig = 1

augroup editorconfig
autocmd!
autocmd BufNewFile,BufRead,BufFilePost * lua require('editorconfig').config(tonumber(vim.fn.expand('<abuf>')))
augroup END
14 changes: 9 additions & 5 deletions fnl/editorconfig.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@
(fn properties.trim_trailing_whitespace [bufnr val]
(assert (or (= val :true) (= val :false)) "trim_trailing_whitespace must be either 'true' or 'false'")
(when (= val :true)
(vim.api.nvim_create_autocmd :BufWritePre {:group :editorconfig
:buffer bufnr
:callback trim-trailing-whitespace})))
(if (= (vim.fn.has :nvim-0.7) 1)
(vim.api.nvim_create_autocmd :BufWritePre {:group :editorconfig
:buffer bufnr
:callback trim-trailing-whitespace})
(vim.cmd (: "autocmd editorconfig BufWritePre <buffer=%d> lua require('editorconfig').trim_trailing_whitespace()"
:format bufnr)))))

(fn properties.insert_final_newline [bufnr val]
(assert (or (= val :true) (= val :false)) "insert_final_newline must be either 'true' or 'false'")
Expand Down Expand Up @@ -165,8 +168,9 @@
(tset vim.b bufnr :editorconfig applied))))

(fn trim_trailing_whitespace []
(vim.notify_once (debug.traceback "editorconfig.nvim: trim_trailing_whitespace() is deprecated and will soon be removed" 2)
vim.log.levels.WARN)
(when (= (vim.fn.has :nvim-0.7) 1)
(vim.notify_once (debug.traceback "editorconfig.nvim: trim_trailing_whitespace() is deprecated and will soon be removed" 2)
vim.log.levels.WARN))
(trim-trailing-whitespace))

{: config
Expand Down
73 changes: 40 additions & 33 deletions lua/editorconfig.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2af8809

Please sign in to comment.