diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-10-26 01:12:36 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-10-26 01:12:36 +0530 |
| commit | a699f41c228b573ff980927d6807ea2b538c0be0 (patch) | |
| tree | 9690227ac84f8b54b52ab28750b497ba219aa133 | |
| parent | 5d823bbd19dc8589cfacdbe51ee5260042dacab2 (diff) | |
| download | kakoune-config-a699f41c228b573ff980927d6807ea2b538c0be0.tar.gz kakoune-config-a699f41c228b573ff980927d6807ea2b538c0be0.zip | |
Move marks into fnl script
| -rw-r--r-- | README.md | 13 | ||||
| -rw-r--r-- | autoload/+init.kak | 2 | ||||
| -rw-r--r-- | autoload/marks.kak | 62 | ||||
| -rw-r--r-- | scripts/fnl/lib.fnl | 32 | ||||
| -rwxr-xr-x | scripts/marks.fnl | 73 |
5 files changed, 127 insertions, 55 deletions
@@ -1,2 +1,15 @@ # kakoune-config My kakoune configuration + +## Tools +- [tmux](https://github.com/tmux/tmux): Window management +- [daffm](https://github.com/phenax/daffm): File manager +- [gitu](https://github.com/altsem/gitu): Git ui +- [fd](https://github.com/sharkdp/fd): Find files +- [rg](https://github.com/BurntSushi/ripgrep): Grep command +- [./scripts/apply_vimgrep_updates.fnl](./scripts/apply_vimgrep_updates.fnl): Apply changes made to grep buffer +- [kakoune-lsp](https://github.com/kakoune-lsp/kakoune-lsp): LSP client +- [kak-tree-sitter](https://git.sr.ht/~hadronized/kak-tree-sitter): Treesitter syntax highlighting +- [kakoune.cr](https://github.com/alexherbo2/kakoune.cr): Connecting with kakoune session +- [./scripts/marks.fnl](./scripts/marks.fnl): Marking files root per-directory + diff --git a/autoload/+init.kak b/autoload/+init.kak index 8352000..b7e7d27 100644 --- a/autoload/+init.kak +++ b/autoload/+init.kak @@ -13,7 +13,7 @@ set-option global autoreload yes set-option global incsearch true set-option global indentwidth 2 set-option global tabstop 2 -set-option global path -add "**" +set-option -add global path "**" set-option global startup_info_version 20250603 set-option global scrolloff 10,3 set-option -add global ui_options terminal_enable_mouse=false terminal_set_title=true diff --git a/autoload/marks.kak b/autoload/marks.kak index 8eb4117..43e7126 100644 --- a/autoload/marks.kak +++ b/autoload/marks.kak @@ -1,69 +1,27 @@ -declare-option str marks_path -declare-option str marks_name - -hook global KakBegin .* %{ - set-option global marks_path %sh{ - datadir="${XDG_DATA_HOME:-"$HOME/.local/share"}" - echo "$datadir/kak/marks" - } -} - -hook global EnterDirectory .* %{ evaluate-commands %sh{ - if [ -z "$kak_marks_name" ]; then - name=$(pwd | tr '/' '-' | tr ' ' '_') - echo "set-option global marks_name $name" - fi -} } - define-command marks-add -params 1..2 %{ - nop %sh{ - [ -z "$kak_opt_marks_path" ] && exit 1 - mkdir -p "$kak_opt_marks_path" - path="$kak_opt_marks_path/$kak_opt_marks_name" - [ -f "$path" ] || touch "$path" - newfile="$1" - pos="$2" - if [ -z "$pos" ] || [ "$pos" = "0" ]; then - pos="99"; - else - pos="$(echo "$pos" | awk '{printf "%.1f", $1 <= 1 ? 0 : $1 - 0.5}')"; - fi - function append() { cat; echo -e "$pos\t$newfile"; } - newfiles=$(grep -v -F "$newfile" "$path" \ - | nl | sed 's/^\s*//' \ - | append | LC_ALL=C sort -g -b -k 2 | uniq -f1 | LC_ALL=C sort -g -b \ - | sed 's/^\s*[-.0-9]\+\s\+//') - echo -e "$newfiles" > "$path.tmp" - mv "$path.tmp" "$path" || true - rm -f "$path.tmp" || true - } + nop %sh{ "$kak_config/scripts/marks.fnl" add "$1" "$2" } marks-show } define-command marks-delete -params 1 %{ - nop %sh{ - path="$kak_opt_marks_path/$kak_opt_marks_name" - [ -f "$path" ] && sed -i "/$(echo "$1" | tr '/' '.')/d" "$path" || true - } + nop %sh{ "$kak_config/scripts/marks.fnl" delete "$1" } delete-buffer %arg{1} marks-show } define-command marks-clear %{ - nop %sh{ - path="$kak_opt_marks_path/$kak_opt_marks_name" - [ -f "$path" ] && rm -f "$path" || true - } + nop %sh{ "$kak_config/scripts/marks.fnl" clear } } define-command marks-show %{ info -title 'marks' -markup %sh{ path="$kak_opt_marks_path/$kak_opt_marks_name" echo -n "{Default}" - if ! [ -f "$path" ] || [ "$(wc -l "$path")" = "0" ]; then + marks=$("$kak_config/scripts/marks.fnl" show) + if [ -z "$marks" ]; then echo "{comment}<empty>" && exit 0; fi - cat "$path" | while IFS= read file; do + echo "$marks" | while IFS= read file; do short_path=$(echo "$file" | awk -F/ '{if (NF >= 2) {print $(NF-1) "/" $NF} else {print $NF}}') hl=$([ "$file" = "$kak_buffile" ] && echo "{keyword}" || echo "{Default}") echo "${hl}${short_path} {comment}$(realpath -s --relative-to="$PWD" "$file"){Default}" @@ -73,12 +31,8 @@ define-command marks-show %{ define-command marks-switch -params 1 %{ evaluate-commands %sh{ - path="$kak_opt_marks_path/$kak_opt_marks_name" - [ -f "$path" ] || exit 0 - count="${1:-0}" - [ "$count" = "0" ] && exit 0 - file=$(cat "$path" | sed -n "${count}p") - [ -z "$file" ] || echo "edit $file" + mark=$("$kak_config/scripts/marks.fnl" get "${1:-0}") + [ -z "$mark" ] || echo "edit $mark" } marks-show } diff --git a/scripts/fnl/lib.fnl b/scripts/fnl/lib.fnl new file mode 100644 index 0000000..100b447 --- /dev/null +++ b/scripts/fnl/lib.fnl @@ -0,0 +1,32 @@ +(local M {}) + +(lambda M.contains? [tbl elem] + (not= nil (table.index-of tbl elem))) + +(lambda M.index-of [tbl elem] + (each [idx value (pairs tbl)] + (when (= value elem) (lua "return idx"))) + nil) + +(lambda M.exec [cmd args] + (var argstr "") + (each [_ arg (ipairs args)] + (set argstr (.. argstr " \"" (string.gsub arg "\"" "\\\"") "\""))) + (local code (os.execute (.. cmd argstr)))) + +(lambda M.read-lines [filepath] + (local file (io.open filepath :r)) + (if file + (do + (local lines []) + (each [line (file:lines)] (table.insert lines line)) + (file:close) + lines) + [])) + +(lambda M.write-lines [filepath lines] + (local file (io.open filepath :w)) + (file:write (table.concat lines "\n")) + (file:close)) + +M diff --git a/scripts/marks.fnl b/scripts/marks.fnl new file mode 100755 index 0000000..d0ad3db --- /dev/null +++ b/scripts/marks.fnl @@ -0,0 +1,73 @@ +#!/usr/bin/env -S fennel --lua luajit + +(lambda fnl-require [path] + (local fnl (require :fennel)) + (local scriptpath (string.gsub (. arg 0) "[^/]*$" "")) + (fnl.dofile (.. scriptpath "/" path))) + +(local {: index-of : exec : read-lines : write-lines} + (fnl-require :fnl/lib.fnl)) + +(local xdg_data_home + (do + (local path (os.getenv :XDG_DATA_HOME)) + (or path (.. (os.getenv :HOME) :/.local/share)))) + +(local marks_path (.. xdg_data_home :/kak/marks)) + +(local command {}) +(local M {}) + +(lambda command.add [[new-mark ?posstr]] + (local pos (and ?posstr (tonumber ?posstr))) + (local markpaths (M.get-marks)) + (local existing-idx (index-of markpaths new-mark)) + (when (not= nil existing-idx) + (table.remove markpaths existing-idx)) + (if (or (= pos nil) (= pos 0)) + (table.insert markpaths new-mark) + (table.insert markpaths pos new-mark)) + (M.set-marks markpaths)) + +(lambda command.get [[posstr]] + (local pos (and posstr (tonumber posstr))) + (local markpaths (M.get-marks)) + (local existing-idx (. markpaths pos)) + (when (not= nil existing-idx) (print existing-idx))) + +(lambda command.delete [[mark]] + (local markpaths (M.get-marks)) + (local existing-idx (index-of markpaths mark)) + (when (not= nil existing-idx) + (table.remove markpaths existing-idx)) + (M.set-marks markpaths)) + +(fn command.clear [] (M.set-marks [])) + +(fn command.show [] + (print (table.concat (M.get-marks) "\n"))) + +(fn command.show-path [] + (print (.. marks_path "/" (M.path-key)))) + +;; ----- + +(fn M.path-key [] + (string.gsub (os.getenv :PWD) "[^A-Za-z0-9._-]" "-")) + +(fn M.get-marks [?key] + (local path (.. marks_path "/" (or ?key (M.path-key)))) + (read-lines path)) + +(lambda M.set-marks [marks ?key] + (exec :mkdir [:-p marks_path]) ; Create marks path dir if not exists + (local path (.. marks_path "/" (or ?key (M.path-key)))) + (write-lines path marks)) + +(fn M.main [] + (local [cmd & cmdargs] arg) + (if (and cmd (. command cmd)) + ((. command cmd) cmdargs) + (error (.. "invalid command: " (or cmd ""))))) + +(M.main) |
