add kakoune config

This commit is contained in:
Johann Dreo 2021-04-04 12:02:26 +02:00
commit 558a6cfd90
7 changed files with 484 additions and 9 deletions

44
.bashrc
View file

@ -113,7 +113,7 @@ alias mkdir='mkdir -p'
# The 'ls' family (this assumes you use the GNU ls)) # The 'ls' family (this assumes you use the GNU ls))
# Mispelling on azerty keyboards # Mispelling on azerty keyboards
alias lks='ls' alias lks='ls'
alias ks='ls' # alias ks='ls'
alias ms='ls' alias ms='ls'
alias ls='ls -hF --color' # add colors for filetype recognition alias ls='ls -hF --color' # add colors for filetype recognition
@ -216,6 +216,18 @@ function ended() {
notify notify
} }
function forever() {
cmd="$1"
while [[ 1 ]]; do
echo "$cmd"
$cmd
if [[ $? > 128 ]]; then
break;
fi
done
}
########## ##########
# Coding # # Coding #
########## ##########
@ -240,7 +252,8 @@ export EDITOR='gvim --nofork'
# aliases to manage vim in server mode # aliases to manage vim in server mode
alias latexed="gvim --servername LATEX " alias latexed="gvim --servername LATEX "
alias ide="gvim --servername IDE " # alias ide="gvim --servername IDE "
alias ide="kak -s ide -e 'rename-client main'"
# print a vim fortune at startup # print a vim fortune at startup
#/usr/games/fortune vimtips #/usr/games/fortune vimtips
@ -275,6 +288,12 @@ function m()
cm cmake .. && cm make $@ && ./$@ cm cmake .. && cm make $@ && ./$@
} }
function ma()
{
set -o pipefail
N=$(($(nproc)-1))
cm cmake .. && cm make -j $N $@ && cm ctest -j $N
}
# shortcut to display the url config of remote repo in a git root # shortcut to display the url config of remote repo in a git root
@ -298,9 +317,11 @@ function git_archive()
{ {
last_commit_date=$(git log -1 --format=%ci | awk '{print $1"_"$2;}' | sed "s/:/-/g") last_commit_date=$(git log -1 --format=%ci | awk '{print $1"_"$2;}' | sed "s/:/-/g")
project=$(basename $(pwd)) project=$(basename $(pwd))
name=${project}_${last_commit_date} branch=$(git rev-parse --abbrev-ref HEAD)
git archive --prefix=$name/ --format zip master > $name.zip name=${project}_${branch}_${last_commit_date}
echo $name.zip git config tar.tar.xz.command "xz -c"
git archive --prefix=$name/ --format tar.xz ${branch} > $name.tar.xz
echo $name.tar.xz
} }
@ -345,7 +366,8 @@ echo "rcp : copy with rsync/ssh"
} }
# do not permits to recall dangerous commands in bash history # do not permits to recall dangerous commands in bash history
export HISTIGNORE='&:[bf]g:exit:*>|*:*rm*-rf*' # export HISTIGNORE='&:[bf]g:exit:*>|*:*rm*-rf*'
export HISTIGNORE='&:[bf]g:exit:*>|*'
# append history rather than overwrite # append history rather than overwrite
shopt -s histappend shopt -s histappend
# one command per line # one command per line
@ -368,8 +390,10 @@ eval $(thefuck --alias fuck)
# Use liquidprompt only if in an interactive shell # Use liquidprompt only if in an interactive shell
if [[ $- == *i* ]]; then if [[ $- == *i* ]]; then
# Super nice prompt # Super nice prompt
source ~/.liquidpromptrc source ~/.liquidprompt --no-activate
source ~/.liquidprompt lp_activate #--no-config
DOTMATRIX_VARIANT="chevron"
source ~/code/liquidprompt/themes/dotmatrix/dotmatrix.theme && lp_theme dotmatrix
fi fi
# Use autojump only if in an interactive shell # Use autojump only if in an interactive shell
@ -379,3 +403,7 @@ fi
export TCLLIBPATH="~/.local/share/tkthemes" export TCLLIBPATH="~/.local/share/tkthemes"
# Add pip bin dir to path:
export PATH="$PATH:/home/nojhan/.local/bin/"
# export PYTHONPATH="$PYTHONPATH:/home/nojhan/code/terminator/"

93
kak/autoload/cpp.kak Normal file
View file

@ -0,0 +1,93 @@
hook global WinSetOption filetype=(cpp) %[
require-module c-family
evaluate-commands %sh{
# Grammar
flow='
break case catch
continue do
else for goto if
return switch
throw try while
assert static_assert
'
state='
alignas alignof asm compl const_cast decltype
delete dynamic_cast export new operator reinterpret_cast
sizeof static_cast typeid
'
operators='
and and_eq bitand bitor not not_eq or or_eq xor xor_eq
'
attributes='
audit axiom const consteval constexpr default explicit
extern final friend inline mutable noexcept override private
protected public register requires static thread_local typename
virtual volatile
'
entities='auto class concept enum namespace struct template union typedef using'
types='
bool byte char char8_t char16_t char32_t double float int long
max_align_t nullptr_t ptrdiff_t short signed size_t size_type unsigned void
wchar_t uint32_t
'
values='NULL false nullptr this true'
STL='
abort abs accumulate acos adjacent_difference adjacent_find adjacent_find_if any append
asctime asin assign at atan atan2 atexit atof atoi atol auto_ptr back back_inserter bad bad_alloc
bad_cast bad_exception bad_typeid badbit beg begin binary_compose binary_negate binary_search bind2nd
binder1st binder2nd bitset bsearch c_str calloc capacity ceil cerr cin clear clearerr clock clog
close compare compose1 compose2 const_iterator construct copy copy_backward copy_n cos cosh count
count_if cout ctime data deque destroy difference_type difftime div divides domain_error empty end
endl eof eofbit equal equal_range erase exception exit exp fabs fail failbit failure fclose feof
ferror fflush fgetc fgetpos fgets fill fill_n find find_end find_first_not_of find_first_of find_if
find_last_not_of find_last_of first flags flip floor flush fmod fopen for_each fprintf fputc fputs
fread free freopen frexp front fscanf fseek fsetpos fstream ftell fwrite gcount generate generate_n
get get_temporary_buffer getc getchar getenv getline gets gmtime good goodbit greater greater_equal
hash_map hash_multimap hash_multiset hash_set ifstream ignore in includes inner_product inplace_merge
insert inserter invalid_argument ios ios_base iostate iota is_heap is_open is_sorted isalnum isalpha
iscntrl isdigit isgraph islower isprint ispunct isspace istream istream_iterator istringstream
isupper isxdigit iter_swap iterator iterator_category key_comp ldiv length length_error less
less_equal lexicographical_compare lexicographical_compare_3way list localtime log log10 logic_error
logical_and logical_not logical_or longjmp lower_bound make_heap malloc map max max_element max_size
mem_fun mem_fun1 mem_fun1_ref mem_fun_ref memchr memcpy memmove memset merge min min_element minus
mismatch mktime modf modulus multimap multiplies multiset negate next_permutation npos nth_element
numeric_limits ofstream open ostream ostream_iterator ostringstream out_of_range overflow_error
pair make_pair partial_sort partial_sort_copy partial_sum partition peek perror plus pointer
pointer_to_binary_function pointer_to_unary_function pop pop_back pop_front pop_heap pow power
precision prev_permutation printf ptr_fun push push_back push_front push_heap put putback putc
putchar puts qsort raise rand random_sample random_sample_n random_shuffle range_error rbegin
rdbuf rdstate read realloc ref reference remove remove_copy remove_copy_if remove_if rename rend
replace replace_copy replace_copy_if replace_if reserve reset resize return_temporary_buffer
reverse reverse_copy reverse_iterator rewind rfind rotate rotate_copy runtime_error scanf search
search_n second seekg seekp set set_difference set_intersection set_symmetric_difference set_union
setbuf setf setjmp setlocale setvbuf shared_ptr signal sin sinh size sort sort_heap splice
sprintf sqrt srand sscanf stable_partition stable_sort std str strcat strchr strcmp strcoll strcpy
strcspn strerror strftime string strlen strncat strncmp strncpy strpbrk strrchr strspn strstr strtod
strtok strtol strtoul strxfrm substr swap swap_ranges sync_with_stdio system tan tanh tellg tellp
temporary_buffer test time time_t tmpfile tmpnam to_string to_ulong tolower top toupper transform
unary_compose unary_negate underflow_error unget ungetc uninitialized_copy uninitialized_copy_n
uninitialized_fill uninitialized_fill_n unique unique_ptr unique_copy unsetf upper_bound va_arg value_comp
value_type vector vfprintf vprintf vsprintf width write round initializer_list function make_unique
make_shared forward filesystem
'
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
# Add the language's grammar to the static completion list
printf %s\\n "declare-option str-list cpp_static_words $(join "${flow} ${state} ${operators} ${attributes} ${entities} ${types} ${values} ${STL}" ' ')"
# Highlight keywords
printf %s "
add-highlighter -override shared/cpp/code/flow regex \b($(join "${flow}" '|'))\b 0:flow
add-highlighter -override shared/cpp/code/state regex \b($(join "${state}" '|'))\b 0:state
add-highlighter -override shared/cpp/code/attributes regex \b($(join "${attributes}" '|'))\b 0:attribute
add-highlighter -override shared/cpp/code/entities regex \b($(join "${entities}" '|'))\b 0:entity
add-highlighter -override shared/cpp/code/types regex \b($(join "${types}" '|'))\b 0:type
add-highlighter -override shared/cpp/code/values regex \b($(join "${values}" '|'))\b 0:value
add-highlighter -override shared/cpp/code/STL regex \bstd::[\w:]*\b 0:builtin
add-highlighter -override shared/cpp/code/operators1 regex \b($(join "${operators}" '|'))\b 0:operator
add-highlighter -override shared/cpp/code/operators2 regex (\+|-|\*|&|=|\\|\?|%|\|-|!|\||->|\.|,|<|>|:|\^|/|~) 0:operator
add-highlighter -override shared/cpp/code/delimiters regex (\(|\)|\[|\]|\{|\}|\;|') 0:delimiter
"
}
]

88
kak/colors/nojhan.kak Normal file
View file

@ -0,0 +1,88 @@
evaluate-commands %sh{
light_blue="rgb:87bbff"
blue="rgb:6f9dfe"
dark_blue="rgb:5f8dee"
light_magenta="rgb:c6b3fb"
light_yellow="rgb:ffeb85"
yellow="rgb:efcd45"
dark_yellow="rgb:cf8200"
green="rgb:a5c261"
dark_green="rgb:529f50"
red="rgb:db4939"
cream="rgb:bf8753"
dark_cream="rgb:363037"
light_white="rgb:f8f8f8"
white="rgb:d3d0cc"
dark_white="rgb:93907c"
light_black="rgb:4b4b4b"
black="rgb:2b2b2b"
dark_black="rgb:000000"
# code
echo "
face global value ${dark_green},default
face global type ${blue},default
face global entity ${blue},default+b
face global variable ${light_blue},default
face global module ${light_blue},default
face global string ${cream},${dark_cream}
face global keyword ${red},default
face global flow ${red},default+b
face global state ${red},default
face global operator ${light_magenta},default
face global attribute rgb:ffc66d,default
face global comment ${green},default
face global documentation ${green},default+b
face global meta rgb:787878,default
face global identifier rgb:ffc66b,default
face global error rgb:000000,rgb:ff0000
face global builtin ${light_white},default
face global delimiter ${light_yellow},default
"
# text
echo "
face global title rgb:ffffff,default+b
face global header rgb:ffffff,default
face global bold rgb:ffffff,default+b
face global italic rgb:121212,default+i
face global mono rgb:333333,rgb:dedede
face global block rgb:333333,rgb:dedede
face global link rgb:ffffff,default
face global bullet rgb:ffffff,default
face global list rgb:212121,default
"
# kakoune UI
echo "
face global Default ${white},${black}
face global PrimarySelection ${light_white},${dark_yellow}
face global SecondarySelection ${light_white},${light_blue}
face global PrimaryCursor ${black},${yellow}+Fb
face global SecondaryCursor ${light_white},${blue}+Fb
face global MatchingChar default,${blue}
face global Whitespace ${dark_white},default
face global BufferPadding rgb:cccccc,rgb:262121
face global LineNumbers rgb:8a8a8a,default
face global LineNumberCursor rgb:999999,default
face global MenuForeground ${light_white},${dark_yellow}+b
face global MenuBackground ${light_white},${blue}
face global MenuInfo ${white},${dark_blue}
face global Information ${white},${light_black}
face global Error rgb:ededed,rgb:212121
face global StatusLine ${light_white},${dark_blue}
face global StatusLineMode ${light_white},${dark_yellow}+b
face global StatusLineInfo ${light_white},${black}
face global StatusLineValue ${black},${dark_yellow}
face global StatusCursor ${light_white},${yellow}
face global Prompt ${dark_black},${dark_blue}+b
face global Search ${black},${light_yellow}+Fi
"
}

223
kak/kakrc Normal file
View file

@ -0,0 +1,223 @@
#################################
# Convenience functions
#################################
define-command filetype-hook -params 2 %{
hook global WinSetOption "filetype=(%arg{1})" "%arg(2)"
}
#################################
# Generic mappings
#################################
# Comments
map global normal '$' -docstring 'Comment the selected lines' ': comment-line<ret>'
map global normal '<a-$>' -docstring 'Comment the selected block with begin/end characters' ': comment-block<ret>'
map global normal '*' -docstring 'Select all occurrences of the current selection set' 'bw*%s<ret>'
define-command cq -docstring 'Quit with an (arbitrary) error code' %{q 666}
# define-command pwd -docstring 'Print the current working directory' %{ evaluate-commands %sh{ echo "echo -markup {Information}$PWD" } }
# Use Tab and Shift-Tab to navigate completion in insert mode.
hook global InsertCompletionShow .* %{
try %{
execute-keys -draft 'h<a-K>\h<ret>'
map window insert <tab> <c-n>
map window insert <s-tab> <c-p>
hook -once -always window InsertCompletionHide .* %{
map window insert <tab> <tab>
map window insert <s-tab> <s-tab>
}
}
}
map global normal <tab> -docstring 'Swap selections cursor and anchor' '<a-;>'
map global normal <a-tab> -docstring 'Ensure selection cursor is after anchor' '<a-:>'
#################################
# Generic config
#################################
set-option -add global ui_options ncurses_assistant=none
set-option -add global ui_options ncurses_set_title=yes
# Indent with 2 spaces and make tabs appear as 2 spaces.
set-option global tabstop 4
set-option global indentwidth 4
# tabs to spaces
hook global InsertChar \t %{
exec -draft h@
}
# keep space around cursor
set-option global scrolloff 10,10
# Add characters as matching pairs
set-option -add global matching_pairs « » “ ”
# Autoformat (indent) line (if formatcmd is defined for the current filetype).
map global normal '=' ': format<ret>' -docstring 'format'
# Paths
map global prompt <a-?> -docstring 'Current buffer name' '<c-r>%'
map global prompt <a-/> -docstring 'Current buffer directory' '%sh(dirname "$kak_bufname")<a-!>/'
hook global ModuleLoaded x11 %{
set global termcmd 'terminator -e '
alias global terminal x11-terminal
}
# Persistent history across sessions.
hook global KakEnd .* %{ echo -to-file .kak_history -quoting kakoune reg : %reg{:} }
hook global KakBegin .* %{ try %{ source .kak_history } }
#################################
# Highlighting
#################################
add-highlighter global/matching show-matching
add-highlighter global/wrap wrap -word -indent -marker ⤷
add-highlighter global/suspicicous-whitespaces show-whitespaces -tab ⭲ -nbsp · -spc " " -lf " "
add-highlighter global/trailing-whitespaces regex '\h+$' 0:error
colorscheme nojhan
# Highlight generic tags
hook global WinSetOption comment_line=(.+) %{
add-highlighter -override window/here regex "(HERE)" 1:rgb:ffff00,rgb:ff0000+FB
add-highlighter -override window/fixme regex "(FIXME)" 1:rgb:ffff00,rgb:ff0000+Fb
add-highlighter -override window/todo regex "(TODO)" 1:rgb:000000,rgb:ff00ff+Fb
add-highlighter -override window/note regex "(NOTE)" 1:rgb:000000,rgb:a5c261+Fb
}
# Show line numbers (and highlight current cursor line)
hook global WinCreate ^[^*]+$ %{
add-highlighter window/ number-lines # -hlcursor
}
#################################
# Language specifics
#################################
filetype-hook makefile %{
set-option window indentwidth 0
}
filetype-hook latex %{
set-option buffer autowrap_column 80
autowrap-enable
}
filetype-hook markdown %{
set-option buffer autowrap_column 80
autowrap-enable
}
filetype-hook c|cpp %{
clang-enable-autocomplete
clang-enable-diagnostics
alias window lint clang-parse
alias window lint-next-error clang-diagnostics-next
set-option buffer formatcmd "clang-format -style='WebKit'"
map global normal A ': c-family-alternative-file'
}
filetype-hook python %{
jedi-enable-autocomplete
lint-enable
set-option global lintcmd 'flake8'
}
#################################
# Plugins
#################################
# Autoinstall plug.kak if necessary.
evaluate-commands %sh{
plugins="$HOME/.config/kak/plugins"
mkdir -p $plugins
[ ! -e "$plugins/plug.kak" ] && \
git clone -q https://github.com/andreyorst/plug.kak "$plugins/plug.kak"
printf "%s\n" "source '$plugins/plug.kak/rc/plug.kak'"
}
# Load the plugin manager.
plug "andreyorst/plug.kak" noload
# Buffers list.
plug 'delapouite/kakoune-buffers' %{
hook global WinDisplay .* info-buffers
map global normal à ': enter-buffers-mode<ret>' -docstring 'buffers'
map global normal À ': enter-user-mode -lock buffers<ret>' -docstring 'buffers (lock)'
}
# Multi-select all identical characters in the column.
plug 'occivink/kakoune-vertical-selection' %{
map global user <down> -docstring "Select all identical characters in the column downward" ': vertical-selection-down<ret>'
map global user <up> -docstring "Select all identical characters in the column upward" ': vertical-selection-up<ret>'
}
# System clipboard integration.
plug "lePerdu/kakboard" %{
hook global WinCreate .* %{ kakboard-enable }
}
# Fuzzy search
plug "andreyorst/fzf.kak" %{
map global normal <c-p> ': fzf-mode<ret>'
}
# ctags tagbar FIXME does not work out of tmux
plug "andreyorst/tagbar.kak" defer "tagbar" %{
set-option global tagbar_sort false
set-option global tagbar_size 40
set-option global tagbar_display_anon false
} config %{
# if you have wrap highlighter enamled in you configuration
# files it's better to turn it off for tagbar, using this hook:
hook global WinSetOption filetype=tagbar %{
remove-highlighter window/wrap
# you can also disable rendering whitespaces here, line numbers, and
# matching characters
}
}
plug 'delapouite/kakoune-cd' %{
# Suggested mapping
map global user c ': enter-user-mode cd<ret>' -docstring 'cd'
# Suggested aliases
alias global cdb change-directory-current-buffer
alias global cdr change-directory-project-root
alias global ecd edit-current-buffer-directory
alias global pwd print-working-directory
}
# Automatically change working directory to be the buffer's one.
hook global WinDisplay .* %{
# require delapouite/kakoune-cd
change-directory-current-buffer
}
# Like alexherbo2/search-highlighter.kak, but which actually works.
# face global Search white,yellow
def search-highlight-enable %{
hook window -group search-highlight NormalKey [/?*nN]|<a-[/?*nN]> %{ try %{
addhl window/search dynregex '%reg{/}' 0:Search
}}
hook window -group search-highlight NormalKey <esc> %{ rmhl window/search}
}
def search-highlight-disable %{
rmhl window/search
rmhooks window search-highlight
}
# Always highlight search.
hook global WinDisplay .* %{
search-highlight-enable
}

22
kak_ide_open.sh Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
# Forget the Oth argument (name of the script).
if [[ $# > 0 ]] ; then
files="$@"
else
files=""
while read line
do
files="$files $line"
done < /dev/stdin
fi
if kak -l | grep -q "ide" ; then
# Open files in the `main` window of the `ide` session of kakoune.
for file in "${files}"; do
echo "evaluate-commands -client main edit ${file}" | kak -p ide
done
else
terminator -p kakoune -e kak -s ide ${files}
fi

11
kak_ide_open_at_line.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
file="$1"
line="$2"
if kak -l | grep -q "ide" ; then
# Open files in the `main` window of the `ide` session of kakoune.
echo "evaluate-commands -client main edit ${file} ${line}" | kak -p ide
else
terminator -p kakoune -e kak -s ide +${line} ${file}
fi

10
kak_ide_start.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
kak -clear
if kak -l | grep -q "ide" ; then
kak -c ide
else
kak -s ide -e "rename-client main"
fi