Compare commits

...

10 Commits

Author SHA1 Message Date
70e991e51c
ajout correspondance utf8 2025-05-29 20:22:58 +02:00
Clément Joly
4eda76f40c doc: add installation instructions
This was requested in #5
2024-04-16 13:57:39 +02:00
Clément Joly
40226016a3
doc: update Readme.md 2024-03-11 11:37:37 +00:00
Clément Joly
801b6f556a style: rename macro to improve formatting with fnlfmt 2023-12-20 22:12:43 +00:00
Clément Joly
babf417ed5 doc: add instructions to reproduce bugs 2023-12-16 14:32:10 +00:00
Clément Joly
c019760081 refactor: use fennel case, as it’s a bit safer 2023-06-15 21:57:47 +00:00
Clément Joly
090b4fdb16 doc: make section order actually stable
We were already trying to achieve that by sorting the table, but we were
actually sorting by values (i.e. documentation text of a particular
section). To fix this, we now extract the keys, sort them and get back
the items from the initial table, in alphabetical order now.
2023-06-15 21:54:17 +00:00
Clément Joly
5d68c5666b Revert "feat: add <C-é> mapping for <C-w>"
This is not supported widely enough, the <C-é> mapping does not work.

This reverts commit 9491e9efa56f6004bcc19f7a5985e417e4d3c195.
2023-06-15 21:53:48 +00:00
Clément Joly
354a6b5ea5 feat: add <C-é> mapping for <C-w>
<C-é> is much more acessible.
2023-06-15 21:53:48 +00:00
Clément Joly
efce15ecd4 fix: Visual & Select mode mappings
Currently, Visual mappings are defined using “v”, which according to
`map-table`:

         Mode  | Norm | Ins | Cmd | Vis | Sel | Opr | Term | Lang |
Command        +------+-----+-----+-----+-----+-----+------+------+
[nore]map      | yes  |  -  |  -  | yes | yes | yes |  -   |  -   |
n[nore]map     | yes  |  -  |  -  |  -  |  -  |  -  |  -   |  -   |
[nore]map!     |  -   | yes | yes |  -  |  -  |  -  |  -   |  -   |
i[nore]map     |  -   | yes |  -  |  -  |  -  |  -  |  -   |  -   |
c[nore]map     |  -   |  -  | yes |  -  |  -  |  -  |  -   |  -   |
v[nore]map     |  -   |  -  |  -  | yes | yes |  -  |  -   |  -   | <--
x[nore]map     |  -   |  -  |  -  | yes |  -  |  -  |  -   |  -   | <--
s[nore]map     |  -   |  -  |  -  |  -  | yes |  -  |  -   |  -   |
o[nore]map     |  -   |  -  |  -  |  -  |  -  | yes |  -   |  -   |
t[nore]map     |  -   |  -  |  -  |  -  |  -  |  -  | yes  |  -   |
l[nore]map     |  -   | yes | yes |  -  |  -  |  -  |  -   | yes  |

This means that we define mappings for both the Visual and the Select
mode. This however pollutes the Select mode and violates the intent
behind the mode. Quoting the documentation:

> Users will expect printable characters to replace the selected area.
> Therefore avoid mapping printable characters in Select mode.
:h Select-mode-mapping

Using “x”, we will only map for Visual mode.
2023-06-15 21:17:20 +00:00
7 changed files with 200 additions and 100 deletions

View File

@ -13,9 +13,6 @@ tags:
- Bepo
- Lisp
- Fennel
#images:
#- /telescope-repo-nvim/opengraph.png
#- /telescope-repo-nvim/opengraph.webp
---
{{< github_badge >}}
@ -27,7 +24,7 @@ end_insert -->
# ⌨️ bepo.nvim
<!-- end_remove -->
![Neovim version](https://img.shields.io/badge/Neovim-0.5-57A143?style=flat&logo=neovim) [![](https://img.shields.io/badge/powered%20by-riss-lightgrey)](https://cj.rs/riss) ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/cljoly/bepo.nvim?color=darkgreen&sort=semver)
![Neovim version](https://img.shields.io/badge/Neovim-0.5-57A143?style=flat&logo=neovim) [![](https://img.shields.io/badge/powered%20by-riss-lightgrey)](https://cj.rs/riss) ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/cljoly/bepo.nvim?color=darkgreen&sort=semver) ![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fd.cj.rs%2Fnvim%2Fbepo.json&cacheSeconds=90000)
<!-- insert
{{< rawhtml >}}
@ -39,13 +36,32 @@ Mappings for the [bepo][] layout in Lua, inspired by [vim-bepo][vb]
It aims to be faster (takes only 0.4ms at startup on my machine, while [vim-bepo][vb] requires 1.6ms) and more customizable (see `:help bepo.nvim-cherry-pick`)
## Example Use
## Installation
You should call the extension early in your config, so that you can erase mappings later (or with later extensions) more easily.
Add the plugin `cljoly/bepo.nvim` to your package manager.
If you dont have a package manager yet, I use [paq.nvim][paq].
You can give it a try :).
Look at the [installation instructions][paq_install] and then add the following to your config:
```lua
require "paq" {
"cljoly/bepo.nvim",
-- ... other packages
}
```
Then restart neovim and run `PaqInstall`. That will install the bepo.nvim plugin.
## Usage
Once the plugin is installed, you can add a call to set up the bepo mappings to your config:
``` lua
require("bepo").setup()
```
You should call the extension early in your `init.lua`, so that you can erase mappings later (or with other extensions) more easily.
## Advanced Usage
You can also apply only some mapping groups:
``` lua
@ -57,6 +73,24 @@ require("bepo").window()
See [the help file][help] for more details and the mappings installed.
[vb]: https://github.com/michamos/vim-bepo
[help]: https://github.com/cljoly/bepo.nvim/blob/main/doc/bepo-nvim.txt
## Reporting bugs
Thanks for considering reporting a bug!
We want to know if the issue is caused by:
1. the plugin itself
2. your user configuration
3. the system configuration
Please try to reproduce the bug in nvim stripped of your user configuration by running:
```
nvim --clean -u test/mock_setup.lua
```
If you cant reproduce the bug in that “clean” nvim instance, it suggests that the bug comes from an interaction of the plugin with your user configuration. Please feel free to open an issue, mentioning that.
[bepo]: https://bepo.fr/
[help]: https://github.com/cljoly/bepo.nvim/blob/main/doc/bepo-nvim.txt
[paq]: https://github.com/savq/paq-nvim
[paq_install]: https://github.com/savq/paq-nvim?tab=readme-ov-file#installation
[vb]: https://github.com/michamos/vim-bepo

View File

@ -43,6 +43,23 @@ only the “window” and “movement” groups of mapping, use this instead of
The following subsections go into details of exactly what mappings are
in each group. “Modes” have the same meaning as in the |map-table|.
--------------------------------------------------------------------------------
require("bepo").easy_access() *bepo.nvim-easy_access*
Modes Bepo Qwerty
n « <
x « <gv
n » >
x » >gv
nx g, g;
nx g; g,
nx é w
nx É W
ox aé aw
ox aÉ aW
ox ié iw
ox iÉ iW
--------------------------------------------------------------------------------
require("bepo").movement() *bepo.nvim-movement*
on préserve {hjkl} pour les directions
@ -101,22 +118,5 @@ require("bepo").window() *bepo.nvim-windo
n wé <C-w>t
n wÉ <C-w>T
--------------------------------------------------------------------------------
require("bepo").easy_access() *bepo.nvim-easy_access*
Modes Bepo Qwerty
n « <
v « <gv
n » >
v » >gv
nx g, g;
nx g; g,
nx é w
nx É W
ox aé aw
ox aÉ aW
ox ié iw
ox iÉ iW
vim:tw=78:ts=8:ft=help:norl:

10
doc/tags Normal file
View File

@ -0,0 +1,10 @@
!_TAG_FILE_ENCODING utf-8 //
bepo.nvim bepo-nvim.txt /*bepo.nvim*
bepo.nvim-always-free bepo-nvim.txt /*bepo.nvim-always-free*
bepo.nvim-cherry-pick bepo-nvim.txt /*bepo.nvim-cherry-pick*
bepo.nvim-easy_access bepo-nvim.txt /*bepo.nvim-easy_access*
bepo.nvim-movement bepo-nvim.txt /*bepo.nvim-movement*
bepo.nvim-setup bepo-nvim.txt /*bepo.nvim-setup*
bepo.nvim-tabs bepo-nvim.txt /*bepo.nvim-tabs*
bepo.nvim-usage bepo-nvim.txt /*bepo.nvim-usage*
bepo.nvim-window bepo-nvim.txt /*bepo.nvim-window*

View File

@ -1,4 +1,5 @@
;;; bepo.nvim: bepo mapping for neovim
;; Copyright 2022 Clément Joly
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
@ -22,8 +23,8 @@
nil)
(fn map-visual [key target]
"For normal mode mappings"
(vim.api.nvim_set_keymap :v key target {:noremap true})
"For visual mode mappings"
(vim.api.nvim_set_keymap :x key target {:noremap true})
nil)
(fn map-normal [key target]
@ -36,16 +37,16 @@
(map-normal key target)
(map-text-object key target))
(macro 𝛅 [...]
(macro def-documented [...]
"When called with the right context, this will print the documentation of the
mappings, instead of attempting to bind. Since we access _G, this needs to be
called with --no-compiler-sandbox (see
https://fennel-lang.org/reference#compiler-environment)"
(fn fun-to-mods [fun]
"Converts a function to the modes it sets mappings for"
(match (tostring fun)
(case (tostring fun)
:map-text-object :ox
:map-visual :v
:map-visual :x
:map-normal :n
:map-all :nx
other (error (.. "Unsupported function " other))))
@ -68,56 +69,99 @@
`(local ,doc-struct.fname ,doc-struct))
`(fn ,(unpack [...]))))
(𝛅 mapping-movement [] "on préserve {hjkl} pour les directions"
(map-all :c :h) (map-all :t :j) (map-all :s :k) (map-all :r :l)
(map-all :C :H) ;; ------
;; {JKL} devient [TSR]
(map-all :T :J) (map-all :S :K) (map-all :R :L) ;; ------
;; on préserve les variantes avec 'g'
(map-all :gt :gj) (map-all :gs :gk) ;; ------
;; on préserve les variantes avec 'z'
(map-all :zT :zt) (map-all :zt :zj) (map-all :zk :zs) (map-all :zs :zk)
;; ------
;; {t} devient [h] pour être proche de [f]
(map-all :h :t) ;; idem pour {T} et [H]
(map-all :H :T) ;; {c} devient [l]
(map-all :l :c) ;; {C} devient [L]
(map-all :L :C) ;; {j} devient [r]
(map-all :j :r) ;; {J} devient [R]
(map-all :J :R) ;; {k} devient [s]
(map-all :k :s) ;; {K} devient [S]
(map-all :K :S))
(def-documented mapping-movement []
"on préserve {hjkl} pour les directions"
(map-all :c :h)
(map-all :t :j)
(map-all :s :k)
(map-all :r :l)
(map-all :C :H)
;; ------
;; {JKL} devient [TSR]
(map-all :T :J)
(map-all :S :K)
(map-all :R :L)
;; ------
;; on préserve les variantes avec 'g'
(map-all :gt :gj)
(map-all :gs :gk)
;; ------
;; on préserve les variantes avec 'z'
(map-all :zT :zt)
(map-all :zt :zj)
(map-all :zk :zs)
(map-all :zs :zk)
;; ------
;; {t} devient [h] pour être proche de [f]
(map-all :h :t)
;; idem pour {T} et [H]
(map-all :H :T)
;; {c} devient [l]
(map-all :l :c)
;; {C} devient [L]
(map-all :L :C)
;; {j} devient [r]
(map-all :j :r)
;; {J} devient [R]
(map-all :J :R)
;; {k} devient [s]
(map-all :k :s)
;; {K} devient [S]
(map-all :K :S))
(𝛅 mapping-tabs [] "le couple [gb]/[gé] agit sur les tabs"
(map-normal :gb :gT) (map-normal "gé" :gt) ;; [gB] va au premier tab
(map-normal :gB ":execute \"silent! tabfirst\"<CR>") ;; [gÉ] au dernier
(map-normal "gÉ" ":execute \"silent! tablast\"<CR>")
;; [gT] est libéré et peut agir sur les tags
(map-normal :gT "<C-]>"))
(def-documented mapping-tabs []
"le couple [gb]/[gé] agit sur les tabs"
(map-normal :gb :gT)
(map-normal "gé" :gt)
;; [gB] va au premier tab
(map-normal :gB ":execute \"silent! tabfirst\"<CR>")
;; [gÉ] au dernier
(map-normal "gÉ" ":execute \"silent! tablast\"<CR>")
;; [gT] est libéré et peut agir sur les tags
(map-normal :gT "<C-]>"))
(𝛅 mapping-easy-access [] ;; [<] est moins accessible que [«]
(map-normal "«" "<") (map-visual "«" :<gv) ;; idem pour [»] et [>]
(map-normal "»" ">") (map-visual "»" :>gv)
;; idem pour [g,] et [g;] qui sont permutés
(map-all "g," "g;") (map-all "g;" "g,")
;; [w] est peu accessible, on utilise [é]
(map-all "é" :w) ;; idem pour [W] et [É]
(map-all "É" :W) ;; idem pour [aw] et [aé]
(map-text-object "aé" :aw) ;; idem pour [aW] et [aÉ]
(map-text-object "aÉ" :aW) ;; idem pour [iw] et [ié]
(map-text-object "ié" :iw) ;; idem pour [iW] et [iÉ]
(map-text-object "iÉ" :iW))
(def-documented mapping-easy-access [] ;; [<] est moins accessible que [«]
(map-normal "«" "<")
(map-visual "«" :<gv)
;; idem pour [»] et [>]
(map-normal "»" ">")
(map-visual "»" :>gv)
;; idem pour [g,] et [g;] qui sont permutés
(map-all "g," "g;")
(map-all "g;" "g,")
;; [w] est peu accessible, on utilise [é]
(map-all "é" :w)
;; idem pour [W] et [É]
(map-all "É" :W)
;; idem pour [aw] et [aé]
(map-text-object "aé" :aw)
;; idem pour [aW] et [aÉ]
(map-text-object "aÉ" :aW)
;; idem pour [iw] et [ié]
(map-text-object "ié" :iw)
;; idem pour [iW] et [iÉ]
(map-text-object "iÉ" :iW))
(𝛅 mapping-window [] "[w] est libre pour faire <C-w>, grâce à easy_access"
(map-normal :w :<C-w>) ;; et [w] pour faire <C-w><C-w>
(map-normal :W :<C-w><C-w>) ;; on map [w]+direction, miniscule + majuscule
(map-normal :wc :<C-w>h) (map-normal :wt :<C-w>j) (map-normal :ws :<C-w>k)
(map-normal :wr :<C-w>l) (map-normal :wC :<C-w>H) (map-normal :wT :<C-w>J)
(map-normal :wS :<C-w>K) (map-normal :wR :<C-w>L)
;; crée un split _h_orizontal
(map-normal :wh :<C-w>s) ;; va en haut à gauche
(map-normal "wé" :<C-w>t) ;; déplace sur un nouveau tab
(map-normal "wÉ" :<C-w>T))
(def-documented mapping-window []
"[w] est libre pour faire <C-w>, grâce à easy_access"
(map-normal :w :<C-w>)
;; et [w] pour faire <C-w><C-w>
(map-normal :W :<C-w><C-w>)
;; on map [w]+direction, miniscule + majuscule
(map-normal :wc :<C-w>h)
(map-normal :wt :<C-w>j)
(map-normal :ws :<C-w>k)
(map-normal :wr :<C-w>l)
(map-normal :wC :<C-w>H)
(map-normal :wT :<C-w>J)
(map-normal :wS :<C-w>K)
(map-normal :wR :<C-w>L)
;; crée un split _h_orizontal
(map-normal :wh :<C-w>s)
;; va en haut à gauche
(map-normal "wé" :<C-w>t)
;; déplace sur un nouveau tab
(map-normal "wÉ" :<C-w>T))
(fn setup []
"In any case, the following keys are always free for you to remap as you see fit:

26
lua/bepo.lua generated
View File

@ -4,7 +4,7 @@ local function map_text_object(key, target)
return nil
end
local function map_visual(key, target)
vim.api.nvim_set_keymap("v", key, target, {noremap = true})
vim.api.nvim_set_keymap("x", key, target, {noremap = true})
return nil
end
local function map_normal(key, target)
@ -41,24 +41,24 @@ local function mapping_movement()
end
local function mapping_tabs()
map_normal("gb", "gT")
map_normal("g\195\169", "gt")
map_normal("g\195\169", "gt") -- \195\169 = gé
map_normal("gB", ":execute \"silent! tabfirst\"<CR>")
map_normal("g\195\137", ":execute \"silent! tablast\"<CR>")
map_normal("g\195\137", ":execute \"silent! tablast\"<CR>") -- \195\137 = gÉ
return map_normal("gT", "<C-]>")
end
local function mapping_easy_access()
map_normal("\194\171", "<")
map_visual("\194\171", "<gv")
map_normal("\194\187", ">")
map_visual("\194\187", ">gv")
map_normal("\194\171", "<") -- \194\171 = «
map_visual("\194\171", "<gv") -- \194\171 = «
map_normal("\194\187", ">") -- \194\187 = »
map_visual("\194\187", ">gv") -- \194\187 = »
map_all("g,", "g;")
map_all("g;", "g,")
map_all("\195\169", "w")
map_all("\195\137", "W")
map_text_object("a\195\169", "aw")
map_text_object("a\195\137", "aW")
map_text_object("i\195\169", "iw")
return map_text_object("i\195\137", "iW")
map_all("\195\169", "w") -- \195\169 = é
map_all("\195\137", "W") -- \195\137 = É
map_text_object("a\195\169", "aw") -- \195\169 = é
map_text_object("a\195\137", "aW") -- \195\137 = É
map_text_object("i\195\169", "iw") -- \195\169 = é
return map_text_object("i\195\137", "iW") -- \195\137 = É
end
local function mapping_window()
map_normal("w", "<C-w>")

View File

@ -37,11 +37,12 @@
(local mapping-struct-header {:bepo :Bepo :modes :Modes :qwerty :Qwerty})
(fn print-mapping-struct [struct]
(match struct
(case struct
{: bepo : modes : qwerty}
(let [qw (if (= ">" qwerty) "> " qwerty)]
(print (.. (right-align modes 6) " " (left-align bepo 4) " " qw)))
_ (error (.. "Received an invalid struct" (fennel.view struct)))))
_
(error (.. "Received an invalid struct" (fennel.view struct)))))
(fn print-lua-import [name]
(->> (values (left-align (string.format "require(\"bepo\").%s()" name) 46)
@ -102,12 +103,16 @@ in each group. “Modes” have the same meaning as in the |map-table|.
(let [tbl (collect [name docstruct (pairs bepo)]
(if (= name :setup) nil
(= (type docstruct) :table) (values name docstruct)
(error (.. "Invalid type for " name))))]
(error (.. "Invalid type for " name))))
tbl_keys (icollect [name docstructy (pairs tbl)]
name)]
(do
(table.sort tbl)
(each [name docstruct (pairs tbl)]
(table.sort tbl_keys)
(each [_ name (pairs tbl_keys)]
(do
(local docstruct (. tbl name))
(var need-header true)
(fn print-header []
(do
(print-mapping-struct mapping-struct-header)
@ -121,11 +126,13 @@ in each group. “Modes” have the same meaning as in the |map-table|.
(print-header))
(each [i mapping-struct (pairs docstruct.body)]
(if need-header (print-hedear))
(match mapping-struct
{:comment c} (do
(print (.. "\n" c))
(set need-header true))
_ (print-mapping-struct mapping-struct)))
(case mapping-struct
{:comment c}
(do
(print (.. "\n" c))
(set need-header true))
_
(print-mapping-struct mapping-struct)))
(print "")))))
;; We split the vim and the : to prevent vim from picking up that for the fennel file

5
test/mock_setup.lua Normal file
View File

@ -0,0 +1,5 @@
-- The assumption is that this file will be used as configuration file with nvim
-- running from the root of the repository
vim.opt.runtimepath:append(vim.fn.getcwd())
require("bepo").setup()