summaryrefslogtreecommitdiff
path: root/lua/talha/functions.lua
blob: 06a66d541ad7e918cfdb6b0d7f6ef04e63a324e3 (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
function GetCurrFileName()
  local filename = vim.api.nvim_buf_get_name(0)
  return filename
end

function ToggleSpellCheck()
    vim.opt.spell = not(vim.opt.spell:get())
    vim.opt.spelllang = 'en_us'
end

function GetHomeDir()
  -- for linux/mac
  local home = os.getenv("HOME")
  -- for windows
  local user_profile = os.getenv("UserProfile")

  if home ~= nil then
    return home
  elseif user_profile ~= nil then
    return user_profile
  end
  return nil
end

function SafeCListNav(navdir)
  -- dir:
  --  1 is cnext (forwards)
  -- -1 is cprev (backwards)
  local dircmd = ''
  if navdir == 1 then
    dircmd = 'cnext'
  elseif navdir == -1 then
    dircmd = 'cprev'
  end
  local status, result = pcall(vim.cmd, dircmd)

  if status == false then
    return nil
  end
end