diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-10-20 15:24:16 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-10-21 13:39:46 +0530 |
| commit | dff6bdcbd6951a38d1d4f43b4ab5342fbe4ca258 (patch) | |
| tree | c9c4fc0f432e6aca5c9b4c60cd46390dacd87078 /autoload | |
| parent | 9fe68adda01dd932b76b55f727edd8f42937b812 (diff) | |
| download | kakoune-config-dff6bdcbd6951a38d1d4f43b4ab5342fbe4ca258.tar.gz kakoune-config-dff6bdcbd6951a38d1d4f43b4ab5342fbe4ca258.zip | |
Add org syntax + some commands
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/git.kak | 64 | ||||
| -rw-r--r-- | autoload/orgmode/orgmode.kak | 102 |
2 files changed, 119 insertions, 47 deletions
diff --git a/autoload/git.kak b/autoload/git.kak index 6f4015c..e0db3c4 100644 --- a/autoload/git.kak +++ b/autoload/git.kak @@ -3,12 +3,16 @@ define-command gitui -params .. %{ } declare-user-mode git +declare-user-mode git-r map global user g ': enter-user-mode git<ret>' -docstring 'Git mode' map global git s ': gitui<ret>' -docstring 'Git tui' map global git A ': git add %val{buffile}<ret>' -docstring 'Add file' map global git c ': git add commit<ret>' -docstring 'Commit' map global git C ': git add commit --amend<ret>' -docstring 'Amend commit' +map global git r ': enter-user-mode git-r<ret>' -docstring 'Git re(base/set) mode' +map global git-r f ': git reset HEAD^1 -- %val{buffile}<ret>' -docstring 'Split file out of last commit' + # Hunk map global git n ': git next-hunk<ret>' -docstring 'Next hunk' map global git p ': git prev-hunk<ret>' -docstring 'Previous hunk' @@ -20,56 +24,22 @@ set-option global git_diff_mod_char "~" set-option global git_diff_top_char "^" define-command git-toggle-diff %{ - try %{ remove-highlighter window/git-diff } catch %{ git show-diff } + try %{ remove-highlighter window/git-diff } catch %{ git show-diff } catch %{ } } # TODO: Toggle this -hook global -group git-diff-if-repo EnterDirectory .* %{ - remove-hooks global git-diff - evaluate-commands %sh{ - if (git rev-parse --is-inside-work-tree >/dev/null 2>&1); then - echo " - hook global -group git-diff ModeChange .*:.*:normal %{ try %{git update-diff} } - hook global -group git-diff WinCreate .* %{ try %{git update-diff} } - hook global -group git-diff BufReload .* %{ try %{git update-diff} } - " - fi - } -} - -# Git window actions - -# declare-option -hidden str git_file -# define-command -hidden git-eval-status-line %{ -# evaluate-commands %sh{ -# file=$(echo "$kak_selection" | sed 's/^\s*[A-Z?]\+\s\+//') -# echo "set-option window git_file '$file'" +# hook global -group git-diff-if-repo EnterDirectory .* %{ +# remove-hooks global git-diff +# try %{ +# evaluate-commands %sh{ +# if (git rev-parse --is-inside-work-tree >/dev/null 2>&1); then +# echo " +# hook global -group git-diff ModeChange .*:.*:normal %{ try %{git update-diff} } +# hook global -group git-diff WinCreate .* %{ try %{git update-diff} } +# hook global -group git-diff BufReload .* %{ try %{git update-diff} } +# " +# fi +# } # } # } -# declare-user-mode git-status-commit -# declare-user-mode git-status-log -# map global git s ':git status -bs<ret>' -docstring 'Git status UI' -# hook -group git-status global WinSetOption filetype=git-status %{ -# set-option buffer readonly true -# map window normal R ':git status -bs<ret>' -# map window normal q ': delete-buffer %val{buffile}<ret>' - -# map window user l ': enter-user-mode git-status-log<ret>' -# map window git-status-log l ': git log --oneline<ret>' -# map window normal d 'x: git-eval-status-line<ret>: git diff -- %opt{git_file}' - -# map window normal c ': enter-user-mode git-status-commit<ret>' -# map window git-status-commit c ': git commit<ret>' -# map window git-status-commit a ': git commit --amend<ret>' -# } - -# hook -group git-log global WinSetOption filetype=git-log %{ -# set-option buffer readonly true -# map window normal q ': git status -bs<ret>' -# } - -# hook -group git-diff global WinSetOption filetype=git-diff %{ -# set-option buffer readonly true -# map window normal q ': git status -bs<ret>' -# } diff --git a/autoload/orgmode/orgmode.kak b/autoload/orgmode/orgmode.kak new file mode 100644 index 0000000..15e3ba3 --- /dev/null +++ b/autoload/orgmode/orgmode.kak @@ -0,0 +1,102 @@ +hook global BufCreate .*[.]org %{ + set-option buffer filetype org +} + +declare-user-mode org +hook global WinSetOption filetype=org %{ + add-highlighter window/org ref org + require-module orgmode-highlight + + map window normal <ret> ': orgmode-jump-link<ret>' + map window user o ': enter-user-mode org<ret>' -docstring 'Org mode' + map window org <tab> ': orgmode-toggle<ret>' -docstring 'Toggle checkbox/task' +} + +define-command orgmode-toggle %{ + evaluate-commands -save-regs '#/' %{ + try %{ orgmode-toggle-checkbox } catch %{ orgmode-toggle-task-state } catch %{ } + } +} + +define-command orgmode-jump-link %{ + # TODO: support multiple links in single line + evaluate-commands -draft %{ try %{ + execute-keys ',xs\[\[([^\n\]]+)\]<ret>' + set-register a %reg{1} + } } + evaluate-commands %sh{ + [ -z "$kak_reg_a" ] && exit 0 + case "$kak_reg_a" in + https://*|http://*) xdg-open "$kak_reg_a" >/dev/null 2>&1 ;; + /*|~/*) echo "edit %{$kak_reg_a}" ;; + *) + current_path="${kak_buffile:-"$kak_bufname"}" + path="$(realpath -s "$(dirname "$kak_buffile")/$kak_reg_a")" + echo "edit %{$path}" + ;; + esac + } +} + +define-command orgmode-toggle-checkbox %{ + evaluate-commands %{ + execute-keys ',xs^(\h*-\h+)\[([Xx\- ])\]<ret>' + evaluate-commands %sh{ + next="$kak_reg_2" + case "$kak_reg_2" in + X|x) next=" " ;; + -) next="X" ;; + *) next="-" ;; + esac + echo "execute-keys 'c<c-r>1[$next]<esc>'" + } + } +} + +define-command orgmode-toggle-task-state %{ + evaluate-commands %{ + execute-keys ',xs^(\*+\h+)(TODO|ACTIVE|DONE)?<ret>' + evaluate-commands %sh{ + next="TODO " # Add space at end when no state + case "$kak_reg_2" in + TODO) next="ACTIVE" ;; + ACTIVE) next="DONE" ;; + DONE) next="TODO" ;; + esac + echo "execute-keys 'c<c-r>1$next<esc>'" + } + } +} + +provide-module orgmode-highlight %{ + add-highlighter shared/org regions + add-highlighter shared/org/inline default-region regions + add-highlighter shared/org/inline/text default-region group + + add-highlighter shared/org/inline/text/ regex \*[^\n*]+\* 0:inlineBold + add-highlighter shared/org/inline/text/ regex /[^\n/]+/ 0:inlineItalic + add-highlighter shared/org/inline/text/ regex _[^\n_]+_ 0:inlineUnderline + add-highlighter shared/org/inline/text/ regex \+[^\n+]+\+ 0:inlineStrikethrough + add-highlighter shared/org/inline/text/ regex ~[^\n~]+~ 0:inlineCode + add-highlighter shared/org/inline/text/ regex \[\[[^\n]+\]\] 0:inlineLink + add-highlighter shared/org/codeblock region -match-capture \ + ^\h*#\+(?:begin|BEGIN)_([a-zA-Z]*)[^\n]*$ \ + ^\h*#\+(?:end|END)_([a-zA-Z]*)[^\n]*$ \ + regions + add-highlighter shared/org/codeblock/ default-region fill orgCodeBlock + + add-highlighter shared/org/inline/text/ regex ^[*]{1}[^\n]* 0:header1 + add-highlighter shared/org/inline/text/ regex ^[*]{2}[^\n]* 0:header2 + add-highlighter shared/org/inline/text/ regex ^[*]{3}[^\n]* 0:header3 + add-highlighter shared/org/inline/text/ regex ^[*]{4}[^\n]* 0:header4 + add-highlighter shared/org/inline/text/ regex ^[*]{5}[^\n]* 0:header5 + add-highlighter shared/org/inline/text/ regex ^[*]{6}[^\n]* 0:header6 + + add-highlighter shared/org/inline/text/ regex ^[*]*\s+(TODO) 1:orgTaskStateTodo + add-highlighter shared/org/inline/text/ regex ^[*]*\s+(DONE) 1:orgTaskStateDone + add-highlighter shared/org/inline/text/ regex ^[*]*\s+(ACTIVE) 1:orgTaskStateActive + + add-highlighter shared/org/inline/text/ regex ^\s*-\s*(\[[xX]\])\h([^\n]+)$ 1:checkboxChecked 2:checkboxCheckedText + add-highlighter shared/org/inline/text/ regex ^\s*-\s*(\[[\s]\]) 1:checkboxTodo + add-highlighter shared/org/inline/text/ regex ^\s*-\s*(\[[-]\]) 1:checkboxPending +} |
