aboutsummaryrefslogtreecommitdiff
path: root/config/vis/visrc.lua
blob: da9cca05ee85eabb7d2d3823c7ab151e086b2b09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
-- load standard vis module, providing parts of the Lua API
require('vis')

require('plugins/filetype')
require('plugins/textobject-lexer')
local cursors = require('plugins/vis-cursors')
cursors.cursors_path = string.format('%s/vis/cursors',
  os.getenv('XDG_DATA_HOME') or
  os.getenv('HOME') .. "/.local/share")

local spellcheck = require('plugins/vis-spellcheck')
spellcheck.list_cmd = 'hunspell -l -d %s'
spellcheck.cmd = 'hunspell -d %s'

local commentary = require('plugins/vis-commentary')
commentary.comments_repl['slides'] = commentary.comments_repl.markdown
commentary()

require('plugins/vis-ctags')
-- This hooks vis.events.START so its fine to load it before the default settings
require('plugins/vis-modelines/vis-modelines')
local lspc = require('plugins/vis-lspc')
if next(lspc) then
  lspc.logging = true
  lspc.message_level = 2

  lspc.ls_map.latex = { name = 'latex', cmd = 'texlab' }
  lspc.ls_map.html = { name = 'html', cmd = 'vscode-html-languageserver --stdio' }
  lspc.ls_map.typescript = { name = 'typescript', cmd = 'typescript-language-server --stdio' }
  lspc.ls_map.java = { name = 'java', cmd = 'jdtls' }
  lspc.ls_map.ltex = {
    name = 'ltex',
    cmd = 'ltex-ls --no-endless',
  }
  lspc.ls_map.harper = {
    name = 'harper',
    cmd = 'harper-ls --stdio',
  }
  lspc.ls_map.python = {
          name = 'python-lsp-server',
          cmd = 'pylsp',
          settings = {
            pylsp = {
              plugins = {
                autopep8 = { enabled = false },
                pycodestyle = { enabled = false },
                pyflakes = { enabled = false },
                rope_completion = { enabled = true, eager = true },
                rope_rename = { enabled = true },
                pylsp_rope = { enabled = true },
                pylint = { enabled = true },
              },
            },
          },
      }
  lspc.ls_map.php = { name = 'php', cmd = 'phpactor language-server', roots={'.git'}}

  vis.events.subscribe(lspc.events.LS_DID_OPEN, function(ls, file)
    if ls.name == 'ltex' then
      if not ls.settings then ls.settings = {} end
      if not ls.settings.ltex then ls.settings.ltex = {} end
      if file.spelling_language then
        ls.settings.ltex.language = file.spelling_language:gsub('_', '-') or 'en-US'
      end
    end
  end)

  vis:map(vis.modes.VISUAL, ' rn', function()
    vis:feedkeys(":lspc-rename ")
  end, 'lspc: rename current symbol')

  vis:map(vis.modes.NORMAL, ' n', function()
    vis:command('lspc-next-diagnostic')
    end, 'lspc: jump to next diagnostic')

  vis:map(vis.modes.NORMAL, ' N', function()
    vis:command('lspc-prev-diagnostic')
    end, 'lspc: jump to prev diagnostic')
end

local lockfiles = require('plugins/vis-lockfiles')
lockfiles.change_file_on_abort = true

require('plugins/vis-snippets')
vis:map(vis.modes.NORMAL, "<C-s>", function()
	vis:command('snippet')
end)

local build = require('plugins/vis-build')
build.get_default_build_cmd = function()
  if os.getenv('PWD'):match('Unterricht') then
    return "lesson-make"
  end
  return "make"
end

local fzf_open = require('plugins/vis-fzf-open')
fzf_open.fzf_path = "FZF_DEFAULT_COMMAND='rg --hidden -g !.git -l \"\"' fzf"

vis:map(vis.modes.NORMAL, ";o", function()
  vis:command('fzf')
end)

require('plugins/suw')

local theme = "theme"
vis.events.subscribe(vis.events.INIT, function()
  -- Your global configuration options
  vis:command("set theme " .. theme)
end)

local inotify = require('plugins/vis-inotify')
if inotify.add_recreate_watch then
  inotify.add_recreate_watch('/home/muhq/.config/vis/themes/theme.lua', function(_)
    vis:command("set theme " .. theme) -- reload vis theme
  end, '-P')
end

-- seperate default settings into per file and per window to not override settings from
-- vis-editorconf which are set on FILE_OPEN
-- default file settings
vis.events.subscribe(vis.events.FILE_OPEN, function()
  vis.options.autoindent = true
end)

-- default window settings
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
  local tabwidth = 4
  win.options.tabwidth = tabwidth
  win.options.numbers = true
  win.options.showtabs = true
  win.options.colorcolumn = 80
  if win.file.name then
    if win.file.name:find("COMMIT_EDITMSG") then
      win.options.colorcolumn = 72
      win:set_syntax("diff")
    elseif win.file.name:find('meson.build') and win.syntax ~= 'meson' then
      win:set_syntax('python')
    elseif win.file.name:find('slides.md') then
      win:set_syntax('slides')
    end

    if win.syntax == "python" or win.syntax == "rust" then
      win.options.expandtab = true
      vis:map(vis.modes.INSERT, '<Backspace>', function()
        local found_tab = true
        for selection in vis.win:selections_iterator() do
          local pos = selection.pos
          if not pos or pos < tabwidth or vis.win.file:content(pos - tabwidth, tabwidth) ~= string.rep(' ', tabwidth) then
            found_tab = false
            break
          end
        end
        vis:feedkeys(string.rep('<vis-delete-char-prev>', found_tab and tabwidth or 1))
      end)
    end
  end
end)

-- load plugins that hook FILE_OPEN or WIN_OPEN to change settings after hooks
-- with default settings
if vis:module_exist('editorconfig') then
  require('plugins/vis-editorconfig')
elseif vis:module_exist('plugins/vis-editorconfig-options') then
  require('plugins/vis-editorconfig-options')
else
  vis:info('skip editorconfig plugins: not suitable editorconfig plugin available')
end

vis:map(vis.modes.NORMAL, ";;", "<vis-window-next>")

vis:command_register('ltex', function()
  vis:command('lspc-start-server ltex')
end)

vis:command_register('harper', function()
  vis:command('lspc-start-server harper')
  local open_file_callback
  open_file_callback = function(ls)
    if ls.name == 'harper' then
      vis:command(':lspc-open harper')
      vis.events.unsubscribe(lspc.events.LS_INITIALIZED, open_file_callback)
    end
  end
  vis.events.subscribe(lspc.events.LS_INITIALIZED, open_file_callback)
end)

vis:map(vis.modes.NORMAL, ' x', function()
  vis:message('')
  vis:command(':q')
end)

vis:command_register('faicon', function()
  local win = vis.win
  if not win or not win.file then return end
  local file = win.file
  local icons = {'hands-helping', 'chalkboard-teacher', 'desktop', 'comments', 'lightbulb', 'pencil-alt', 'earlybirds'}
  local choosen = lspc:select(icons)
  if choosen then
    file:insert(win.selection.pos, '\\faIcon{' .. choosen .. '}')
  end
end)

vis:map(vis.modes.NORMAL, 'fa', function()
  vis:command(':faicon')
end)