summaryrefslogtreecommitdiffstats
path: root/lua/conf/plugins/neorg.lua
blob: f0fec2f205cf0da1cc5abed22e03ed340833fa88 (plain) (blame)
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
-- WARNING: neorg does some pretty stupid stuff when it comes to the plugins it
-- wants (using luarocks), in order to get around all that bullshit I've
-- manually added it's dependencies. Because I don't want this to randomly break
-- I've also pinned neorg to the latest working version that I've messed around
-- with.
--
-- NOTE: for my future self to update this thingy while not breaking
-- dependencies take a look at the build.lua for versioning info. Also make sure
-- to check the release notes on github for info on breaking changes.

local workspace_cache = vim.fs.joinpath(vim.fn.stdpath("data"), "neorg-workspace-cache.lua")

--- populate neorg workspaces from path or cache
---@param path string path to populate workspaces from
---@param cache boolean? if true will re populate the cache from the fs
---@return table workspaces
local function populate_workspaces(path, cache)
  local workspaces = {}
  cache = cache or false

  if vim.fn.filereadable(workspace_cache) == 1 and not cache then
    local ok, ret = pcall(dofile, workspace_cache)
    if ok and type(ret) == "table" then
      return ret
    end
  end

  -- loop through all files in path if path is not empty
  if vim.fn.empty(vim.fn.glob(path)) == 0 then
    for n, t in vim.fs.dir(path) do
      if string.sub(n, 1, 1) == "." or (t ~= "directory" and t ~= "link") then
        goto continue
      end
      -- make sure this still works if the last charachter in the path isn't a '/'
      workspaces[n] = (string.sub(path, #path, #path) == "/") and path..n or path.."/"..n
      ::continue::
    end
  end

  -- write data to cachefile
  local f = io.open(workspace_cache, "w+")
  if not f then
    return workspaces
  end

  f:write("return")
  local ret = vim.inspect(workspaces)
  if type(ret) == "string" then
    f:write(ret)
  else
    f:write("false")
  end

  f:close()

  return workspaces
end

return { 'nvim-neorg/neorg',
  disable = vim.version.lt(vim.version(), { 0, 10, 0 }),
  branch = 'v9.1.1',
  requires = {
    'nvim-lua/plenary.nvim',
    'nvim-treesitter/nvim-treesitter',
    'folke/zen-mode.nvim',
    'hrsh7th/nvim-cmp',
    { 'nvim-neorg/neorg-telescope',
      requires = 'nvim-telescope/telescope.nvim'
    },

    -- NOTE: these are usually installed by neorg via luarocks, the versions
    -- were picked based on the build.lua found in the root of the neorg repo
    { 'nvim-neotest/nvim-nio',
      branch = 'v1.7.0'
    },
    { 'nvim-neorg/lua-utils.nvim',
      branch = 'v1.0.2'
    },
    { 'MunifTanjim/nui.nvim',
      branch = '0.3.0'
    },
    { 'pysan3/pathlib.nvim',
      branch = 'v2.2.2'
    }
  },

  function()
    local wsphome = (os.getenv("XDG_DOCUMENTS_DIR") or
      (os.getenv("HOME").."/Documents")).."/notes/"

    require('neorg').setup {
      load = {
        -- not sure how to sort the modules so ima just put the empty ones first
        ["core.defaults"] = {},
        ["core.export"] = {},
        ["core.export.markdown"] = {},
        ["core.integrations.telescope"] = {},
        ["core.summary"] = {},
        ["core.ui.calendar"] = {},

        ["core.completion"] = {
          config = {
            engine = "nvim-cmp"
          }
        },
        ["core.concealer"] = {
          config = {
            folds = false
          }
        },
        ["core.dirman"] = {
          config = {
            -- a list of available workspaces are generated at runtime >:)
            workspaces = populate_workspaces(wsphome)
          }
        },
        ["core.esupports.metagen"] = {
          config = {
            type = "auto"
          }
        },
        ["core.presenter"] = {
          config = {
            zen_mode = "zen-mode"
          }
        },
        ["core.qol.toc"] = {
          config = {
            close_after_use = true
          }
        },
        ["core.tangle"] = {
          config = {
            tangle_on_write = true
          }
        }
      }
    }
  end
}