Skip to content

Commit

Permalink
Initial commit of marlin
Browse files Browse the repository at this point in the history
  • Loading branch information
desdic committed Feb 18, 2024
0 parents commit d550b93
Show file tree
Hide file tree
Showing 22 changed files with 1,125 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# top-most EditorConfig file
root = true

[Makefile]
indent_style = tab

# Unix-style newlines with a newline ending every file
[{*.lua,*.md}]
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true

41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Tests

on: [push, pull_request]

jobs:
unit_tests:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
rev: nightly/nvim-linux64.tar.gz
- os: ubuntu-22.04
rev: v0.9.0/nvim-linux64.tar.gz
steps:
- uses: actions/checkout@v4
- run: date +%F > todays-date
- name: Restore from todays cache
uses: actions/cache@v4
with:
path: _neovim
key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}

- name: Prepare
run: |
test -d _neovim || {
mkdir -p _neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
- name: Dependencies
run: |
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
ln -s "$(pwd)" ~/.local/share/nvim/site/pack/vendor/start
- name: Run tests
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
nvim --version
make test
26 changes: 26 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Format

on: [push, pull_request]

jobs:
format:
name: Stylua
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: date +%W > weekly

- name: Restore cache
id: cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin
key: ${{ runner.os }}-cargo-${{ hashFiles('weekly') }}

- name: Install
if: steps.cache.outputs.cache-hit != 'true'
run: cargo install stylua

- name: Format
run: stylua --check lua/ --config-path=.stylua.toml
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
name: Luacheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
run: |
sudo apt-get update
sudo apt-get install luarocks
sudo luarocks install luacheck
- name: Lint
run: luacheck lua/ --globals vim
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deps/
4 changes: 4 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.workspace.checkThirdParty": false
}
5 changes: 5 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
column_width = 80
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 4
quote_style = "AutoPreferDouble"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023-2024 marlin.nvim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: test fmt link deps documentation

default: all

all: fmt lint test documentation

fmt:
stylua lua/ --config-path=.stylua.toml

lint:
luacheck lua/ --globals vim

test:
nvim --headless --noplugin -u scripts/test/minimal.vim \
-c "PlenaryBustedDirectory lua/marlin/test/ {minimal_init = 'scripts/test/minimal.vim'}"

deps:
@mkdir -p deps
git clone --depth 1 https://github.com/echasnovski/mini.nvim deps/mini.nvim

documentation:
nvim --headless --noplugin -u ./scripts/minimal_init_doc.lua -c "lua require('mini.doc').generate()" -c "qa!"

documentation-ci: deps documentation
131 changes: 131 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# marlin.nvim
##### Smooth sailing between buffers of interest

Persistent and extensible jumps across project buffers of interest with ease.

### Setup

Example using the lazy plugin manager

```lua
{
"desdic/marlin.nvim",
opts = {},
config = function(_, opts)
local marlin = require("marlin")
marlin.setup(opts)

local keymap = vim.keymap.set
keymap("n", "<Leader>fa", function() marlin.add() end, { desc = "add file" })
keymap("n", "<Leader>fd", function() marlin.remove() end, { desc = "remove file" })
keymap("n", "<Leader>fx", function() marlin.remove_all() end, { desc = "remove all for current project" })
keymap("n", "<Leader>f]", function() marlin.move_up() end, { desc = "move up" })
keymap("n", "<Leader>f[", function() marlin.move_down() end, { desc = "move down" })
keymap("n", "<Leader>fs", function() marlin.sort() end, { desc = "sort" })

for index = 1,4 do
keymap("n", "<Leader>"..index, function() marlin.open(index) end, { desc = "goto "..index })
end
end
}
```

### Default configuration

```lua
local default = {
patterns = { ".git", ".svn" }, -- look for root of project
datafile = vim.fn.stdpath("data") .. "/marlin.json", -- location of data file
open_callback = callbacks.change_buffer -- default way to open buffer
sorter = sorter.by_buffer -- sort by bufferid
}
```

### Easy integration with most status lines

Example with [lualine](https://github.com/nvim-lualine/lualine.nvim)

```lua
return {
"nvim-lualine/lualine.nvim",
config = function()
local marlin = require("marlin")

local marlin_component = function()
local indexes = marlin.num_indexes()
if indexes == 0 then
return ""
end
local cur_index = marlin.cur_index()

return "" .. cur_index .. "/" .. indexes
end

require("lualine").setup({
...
sections = {
...
lualine_c = { marlin_component },
...
},
})
end
```

### Extending behaviour

`marlin.callbacks` has a few options like

- change_buffer (which does what it says, default)
- use_split (if file is already open in a split switch to it)

But its possible to change the open_call function to get the behaviour you want. If you want to open new buffers in a vsplit you can

```lua
open_callback = function(bufnr, _)
vim.cmd("vsplit")
vim.api.nvim_set_current_buf(bufnr)
end,
```

Or if want to add an options to open_index that switches to the buffer if already open in a split

```lua
open_callback = function(bufnr, opts)
if opts.use_split then
local wins = vim.api.nvim_tabpage_list_wins(0)
for _, win in ipairs(wins) do
local winbufnr = vim.api.nvim_win_get_buf(win)

if winbufnr == bufnr then
vim.api.nvim_set_current_win(win)
return
end
end
end

vim.api.nvim_set_current_buf(bufnr)
end,
```

Sorting also has a few options like

- by_buffer sorts by buffer id (The order they where opened in)
- by_name (Sorts by path+filename)

But they can also be change if you want to write your own sorter.

Choice is yours

### Why yet another ..

When I first saw harpoon I was immediately hooked but I missed a few key features.

- I use splits and wanted to have it jump to the buffer and not replace the current one.
- I wanted persistent jumps per project and not per directory.

Like anyone else missing a feature I created a patch but it seems that many other did the same.

### Credits

Credit goes to [ThePrimeagen](https://github.com/ThePrimeagen/harpoon/) for the idea.
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TODO

- Currently no GUI and there might not be one
Loading

0 comments on commit d550b93

Please sign in to comment.