Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
feat(modules): make modules very granular
Browse files Browse the repository at this point in the history
These changes have been discussed in #233.

As a side note, I ran stylua and luacheck over the repo.

* From everyone's perpective

- The module structure has been flattened out, removing the category
  grouping. Beyond less iteration scopes, this may help with, in the
  future, allowing the user to write and enable custom modules in
  $DOOMDIR.

* From the user's perpective

- `doom_config.lua` works via overrides now, it can change defaults
  on the global `doom` before everything gets actually configured.
- `doom_modules.lua`  just returns the actual thing it's supposed to,
  without {return value}.source. More on that next.
- Instead of each config file returning a source key with its file
  location, the handlers for each config file actively search for them.
  This is described in the respective files inside `lua/doom/core/config`,
  but it's basicaly a check for two special paths falling back to
  runtimepath.
- `doom_userplugins.lua` is removed in favor of having its
  functionality in `doom_config.lua`. To add a standalone package, add
  its packer spec to `doom.packages` (this is a map-like table of
  package names to packer specs).
- To override the spec of a module package, change the keys in
  `doom.packages[package_name_without_author]`.
  Special attrs: `config` is run after the built-in config.
- To change settings and behavior, override keys in
  `doom[module]`, or just `doom.*` for some core features.
- To add standalone bindings, add them to `doom.binds`. This is
  passed to nest along with the modules' binds. `doom.binds` overrides
  anything you don't like in modules, you can safely replace the bind.
- To add standalone autocmds, add them to `doom.autocmds[augroup_name]`. The
  structure is as passed to `utils.create_augroups`, so:
  ```lua
  doom.autocmds[group_name] = {
    { event1, pattern1, cmd1 },
    ...
  }
  ```
- You shouldn't override any tables, like `doom.autocmds` or `doom.packages`,
  only the leaves, else you remove all that is already there. We could
  use metatables to avoid this in the future.
- The `config.nvim` table is no longer used, most of its functionality is spread
  elsewhere, like autocmds. For variables and options, just use
  vim.opt.*, vim.g.* etc. in `doom_config.lua`
- Settings can also be appended to in `doom_config.lua`, because
  defaults are prepopulated.

* From a maintainer's perpective

- Most things are grouped under the `doom` global, which is populated
  and overriden early in `init.lua`. The exception is enabled modules,
  which you still need to require `doom.core.config.modules` to get.
  However, do so sparingly, and only if you truly mean to iterate over
  enabled modules disregarding user overrides (they may have removed a
  particular package or reset binds).
- Modules are defined in the following folder structure inside
  `lua/doom/modules`:
  `<module>/{init.lua,packages.lua,binds.lua,autocmds.lua}`.
  init.lua and packages.lua are required, even if empty.
- `init.lua` returns: defaults under a `defaults` key; config functions
  under `packer_config[package_name]`. It can access the doom global
  only inside the configs.
- `packages.lua` returns: a map of package names to package specs, with no
  `config` or `disable` keys present. Most things should be lazy-loaded,
  preferably with the `cmd` and `module` keys. It cannot access the doom global.
- `autocmds.lua` returns: a list of autocmds to be applied under the group
  `doom_{module}`. It can use the `doom` global to add things
  conditionally.
- `binds.lua` returns: the keyconfig to be passed to nest. It can use the
  `doom` global to add things conditionally.

What's left:

- Implement lsp wrapping.
- Document the individual modules.
- Write a migration script.
  • Loading branch information
LuigiPiucco committed Dec 31, 2021
1 parent 743890b commit 9c6bcde
Show file tree
Hide file tree
Showing 177 changed files with 4,376 additions and 7,315 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# My temp files
plugin/
sessions/
undodir/
time_cost.txt
tags
# Backup files
Expand All @@ -16,3 +13,5 @@ tags
contribute/doom-nvim-contrib
contribute/local-share-nvim
contribute/workspace
# Editor files
.luarc.json
10 changes: 5 additions & 5 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
stds.nvim = {
globals = {
vim = { fields = { "g" } },
vim = { fields = { "g", "opt" } },
table = { fields = { "unpack" } },
package = { fields = { "searchers" } },
doom = { fields = { "packages", "binds", "autocmds" } },
_doom = { fields = { "cmp_enable" } }
},
read_globals = {
"vim",
"jit",
"packer_plugins",
"doom",
"_doom"
},
}
std = "lua51+nvim"
Expand All @@ -22,8 +26,4 @@ ignore = {
"631", -- Line is too long.
}

exclude_files = {
"plugin/packer_compiled.lua",
}

-- vim: ft=lua sw=2 ts=2
35 changes: 5 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Its design is guided by these mantras:
- `nodejs` and `npm` (optional, required to use some Language Server Protocols)
- `wget`, `unzip` (optional, required for auto installing LSPs)

Doom is comprised of [~40 optional plugins][modules], some of which may have
Doom is comprised of [~40 optional modules][modules], some of which may have
additional dependencies. [Please visit their documentation][modules].

## Install
Expand All @@ -111,9 +111,6 @@ First you'll want to backup your current Neovim configuration if you have one.
>
> 1. Your current configuration will be backed up to `~/.config/nvim.bak`
> or where your `XDG_CONFIG_HOME` environment variable points to.
>
> 2. If you're a cheovim user you can skip this step and go directly to
> [installing with cheovim](#installing-with-cheovim).
```sh
[ -d ${XDG_CONFIG_HOME:-$HOME/.config}/nvim ] && mv ${XDG_CONFIG_HOME:-$HOME/.config}/nvim ${XDG_CONFIG_HOME:-$HOME/.config}/nvim.bak
Expand All @@ -132,35 +129,14 @@ Or if you want to live in the bleeding-edge with the latest features:
git clone --depth 1 -b develop https://github.com/NTBBloodbath/doom-nvim.git ${XDG_CONFIG_HOME:-$HOME/.config}/nvim
```

### Installing with cheovim

If you're using cheovim as your Neovim configurations manager you can install `doom-nvim` and then
use the recipe listed in cheovim documentation:

```sh
# Clone doom-nvim under a specific directory under our '~/.config' directory
git clone --depth 1 https://github.com/NTBBloodbath/doom-nvim.git ${XDG_CONFIG_HOME:-$HOME/.config}/doom-nvim

# Change the doom-nvim internal path
sed -i "37s/nvim/doom-nvim/" ${XDG_CONFIG_HOME:-$HOME/.config}/doom-nvim/lua/doom/core/system/init.lua
```

```lua
-- In your '~/.config/nvim/profiles.lua'
doom_nvim = { "~/.config/doom-nvim", {
plugins = "packer",
preconfigure = "doom-nvim"
}
}
```
---

Then [read our Getting Started guide][getting-started] to be walked through
installing, configuring and maintaining Doom Nvim.

## Getting help

Neovim is not very difficult. Although you will occasionally run into problems
Although Neovim is not very difficult, you will occasionally run into problems
if you are not an advanced vimmer. When you do, here are some places you can look help:

- [Our documentation][documentation] covers many use cases.
Expand All @@ -175,15 +151,14 @@ if you are not an advanced vimmer. When you do, here are some places you can loo

## Acknowledgements

- [hlissner](https://github.com/hlissner) per doing Doom Emacs :heart:.
- [romgrk](https://github.com/romgrk) per doing a port to Vim of Doom One
colorscheme from Doom Emacs (and everyone who improves the colorscheme!).
- [hlissner](https://github.com/hlissner) for making Doom Emacs :heart:.
- [romgrk](https://github.com/romgrk) for making a port of Doom One to Vim :heart:.
- [All our contributors](#contributors) per helping improve Doom :heart:

## Contribute

- I really :heart: pull requests and bug reports (please see the [Contributing Guidelines][contribute] before contributing)!
- Don't hesitate to [tell me my Lua coding style sucks](https://github.com/NTBBloodbath/doom-nvim/issues/new),
- Don't hesitate to [tell me my Lua sucks](https://github.com/NTBBloodbath/doom-nvim/issues/new),
but please tell me why.

## Contributors
Expand Down
7 changes: 7 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- doom_config - Doom Nvim user configurations file
--
-- This file contains the user-defined configurations for Doom nvim.
-- Just override stuff in the `doom` global table (it's injected into scope
-- automatically).

-- vim: sw=2 sts=2 ts=2 expandtab
2 changes: 1 addition & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ thus reach a solution more quickly.
Some important data would be:

- Your custom configuration if you have one
(`doom_modules.lua`, `doom_config.lua` and `doom_userplugins.lua`)
(`modules.lua` and `config.lua`)
- Which branch of Doom Nvim are you using
- Which plugins are you using

Expand Down
33 changes: 4 additions & 29 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,17 @@

### What type of vimmer is Doom Nvim intended for?

Doom Nvim is intended for all types of Vimmer who want a stable and efficient
Doom Nvim is intended for all types of Vimmers who want a stable and efficient
development environment without spending a lot of time setting everything up.

### Why does Doom Nvim only support Neovim 0.5+?

Doom Nvim doesn't support Neovim versions lower than the current stable (0.5) due to:

- some features would be lost
- Not all Lua plugins have good alternatives in Vimscript, so the experience
would not be the same
- performance would not be the same as Lua cannot be used
Doom Nvim doesn't support Neovim versions lower than the current stable (0.5)
due big plugin incompatibilities and performance differences, which would make
the experience not worth it.

### How to version control Doom Nvim?

Doom Nvim makes use of an internal variable called `doom_configs_root` that points
to `/home/user/.config/doom-nvim` path by default. This allows you to move your
configuration files to this path so you can version control your doom setup too.

> **NOTE**: In case that you're using cheovim (with `/home/user/.config/doom-nvim`
> as your Doom Nvim path) then you will need to change this variable value manually
> by tweaking [this](../lua/doom/core/system/init.lua) file.
After changing your configurations path you will surely want to remove your
`~/.config/nvim/plugin/packer_compiled.lua` and running `:PackerCompile` again.

Also you will need to create a symlink from your new path to the old one for
avoiding issues when updating Doom Nvim. Here is a snippet for this task.

```sh
# Change this variable path if you have installed Doom Nvim in other place
DOOM_ROOT="${XDG_CONFIG_HOME:-$HOME/.config}/nvim"
# Change this variable path if you have changed the Doom Nvim doom_configs_root variable
DOOM_CONFIG_ROOT="${XDG_CONFIG_HOME:-$HOME/.config}/doom-nvim"

# Let's iterate over the configurations path directory files and create a symlink for them
for _config_file in $(ls "$DOOM_CONFIG_ROOT"); do
ln -s "${DOOM_CONFIG_ROOT}/$_config_file" "${DOOM_ROOT}/$_config_file"
done
```
Loading

0 comments on commit 9c6bcde

Please sign in to comment.