Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-morano committed Jul 30, 2022
0 parents commit 3d1e4d3
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
12 changes: 12 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
std = luajit
cache = true
codes = true

globals = {
"SkipConfig",
"Skip_bufh",
"Skip_win_id",
"Skip_cmd_win_id",
"Skip_cmd_bufh",
}
read_globals = { "vim" }
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) José Morano

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.
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<div align="center">

# peruse.nvim
##### A lightweight plugin to easily navigate open buffers

[![Neovim](https://img.shields.io/badge/Neovim%200.5+-green.svg?style=for-the-badge&logo=neovim)](https://neovim.io)
[![Lua](https://img.shields.io/badge/Lua-blue.svg?style=for-the-badge&logo=lua)](http://www.lua.org)

</div>


## The never-ending problem

I want to move easily between buffers, without relying on heavy plugins with a thousand features or thinking in advance about marking buffers to access them later.

And what about `:buffers<CR>:b<space>`? For me, it's not an option. Certain plugins cause the buffer ids to grow out of proportion. The same happens after hours of working on a project opening and closing files... Besides, remembering portions of filenames to access them seems to me to be an excessive mental overhead.


## The proposed solution

Use a buffer-like floating window where all the open buffers are listed. To select one buffer, just move to it and press `<CR>`.


## Installation

* Neovim 0.5.0+ required
* Install peruse using your favorite plugin manager. E.g. `Packer.nvim`:

```lua
use 'nvim-lua/plenary.nvim' -- basic dependency
use 'sonarom/peruse.nvim'
```

## Usage

View all buffers using
```lua
:lua require("peruse.ui").toggle_quick_menu()
```
move to one of them, and open it with `<CR>`. _Finis_.


## Configuration

peruse can be configured through the setup function:

```lua
require("peruse").setup({ ... })
```


## Logging

- Logs are written to `peruse.log` within the nvim cache path (`:echo stdpath("cache")`)
- Available log levels are `trace`, `debug`, `info`, `warn`, `error`, or `fatal`. `warn` is default
- Log level can be set with `vim.g.peruse_log_level` (must be **before** `setup()`)
- Launching nvim with `PERUSE_LOG=debug nvim` takes precedence over `vim.g.peruse_log_level`.
- Invalid values default back to `warn`.

## Others

### Use a dynamic width for the peruse popup menu

Sometimes the default width of `60` is not wide enough.
The following example demonstrates how to configure a custom width by setting
the menu's width relative to the current window's width.

```lua
require("peruse").setup({
menu = {
width = vim.api.nvim_win_get_width(0) - 4,
}
})
```

## TODO

### Actions on listed buffers
* Add, delete, remove, etc.


## Acknowledgements

This plugin is based on [Harpoon](https://github.com/ThePrimeagen/harpoon), an amazing plugin written by ThePrimeagen to easily navigate marked terminals and files.
48 changes: 48 additions & 0 deletions lua/peruse/dev.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- Don't include this file, we should manually include it via
-- require("peruse.dev").reload();
--
-- A quick mapping can be setup using something like:
-- :nmap <leader>rr :lua require("peruse.dev").reload()<CR>
local M = {}

function M.reload()
require("plenary.reload").reload_module("peruse")
end

local log_levels = { "trace", "debug", "info", "warn", "error", "fatal" }
local function set_log_level()
local log_level = vim.env.PERUSE_LOG or vim.g.peruse_log_level

for _, level in pairs(log_levels) do
if level == log_level then
return log_level
end
end

return "warn" -- default, if user hasn't set to one from log_levels
end

local log_level = set_log_level()
M.log = require("plenary.log").new({
plugin = "peruse",
level = log_level,
})

local log_key = os.time()

local function override(key)
local fn = M.log[key]
M.log[key] = function(...)
fn(log_key, ...)
end
end

for _, v in pairs(log_levels) do
override(v)
end

function M.get_log_key()
return log_key
end

return M
35 changes: 35 additions & 0 deletions lua/peruse/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local Dev = require("peruse.dev")
local log = Dev.log

local M = {}

PeruseConfig = PeruseConfig or {}

-- 1. saved. Where do we save?
function M.setup(config)
log.trace("setup(): Setting up...")

if not config then
config = {}
end

-- TODO: add defaults here
-- config = {
-- borderchars = borderchars,
-- ...
-- }

PeruseConfig = config
log.debug("setup(): Config", PeruseConfig)
end


function M.get_config()
log.trace("get_config()")
return PeruseConfig or {}
end

-- Sets a default config with no values
M.setup()

return M
Loading

0 comments on commit 3d1e4d3

Please sign in to comment.