I would like to disable a filetype completely. I use kakoune for editing email and the file filetype/mail.kak is activated. Specifically it overrides the binding of the <ret> key:
hook global WinSetOption filetype=mail %{
require-module mail
map buffer normal <ret> %{: diff-jump<ret>}
hook -once -always window WinSetOption filetype=.* %{
unmap buffer normal <ret> %{: diff-jump<ret>}
}
}
I have my own binding for <ret> in my kakrc which I would like to use instead. It is an irritation to have this overridden.
I know I could edit filetype/mail.kak but this is an installed file and I should be able to do it in files in my home directory.
Is there a quick and easy way to override or disable kak’s defaults for a filetype?
As explained in the FILES section of man kak, on startup Kakoune reads all of the *.kak files/scripts present in your autoload directory (or any subdirectory of it). If you have no custom autoload directory, then Kakoune falls back on the default, system-wise autoload directory, which you can probably find as /usr/share/kak/autoload on your system.
Judging from what you say, it seems you have no custom autoload directory, which would explain why the systemwise mail.kak file is loaded by default.
One way to get rid of this behavior is to create an autoload subdirectory in your HOME/.config/kak directory, and then to create a filetype folder in this custom autoload subdirectory. You can then populate this custom filetype folder with symlinks to all of the systemwise files that you want to use unmodified. For any file that you do want to modify (e.g., mail.kak), do not include a symlink to it; rather, copy the actual file to filetype, then modify this local copy as you wish.
I doubt you’ll find this solution “easy”, but it is recommended in the man page, as it gives you full control over what is vs. is not sourced when starting Kakoune.
Thanks for your reply. I have an autoload directory that has a symlink to the installed autoload directory in it. I guess what I need to do is create a tree of symlinks instead.
(I initially tried copying DATADIR/kak/autoload but this didn’t work, as it itself is a symbolic link to rc.)
I can then simply rm autoload-links/filetype/mail.kak.
The only downside of this approach is that if in the future, I upgraded Kakoune to a new version, it might have default support for more filetypes and I wouldn’t have access to them until I created more symlinks to the installation config folder.
There is no file association when Kakoune reads from stdin, i.e. cat somefile|kak.
There is no connection to somefile either, but cat somefile|kak -e"rename-buffer -file somefile" will reconnect the buffer to the file. I tested this on a shell script and Kakoune continued to ignore the filetype after rename-buffer.
I had previously run into this same issue (with a different filetype), and wrote a script to make these links. Although your solution is more elegant, sharing what I’m doing in case it’s useful to anyone.
#!/bin/bash
#
# This script should go in kakoune's config directory ~/.config/kak/
# Creates, in the '~/.config/kak/autoload/rc/' directory, symlinks to the default rc .kak files, which are at /usr/local/share/kak/rc/ (or /usr/local/Cellar/kakoune if installed via homebrew). The directory structure is mirrored, so links to directories are not created, only links to files.
# file in same dir as this script, named rc-blocklist.txt, defines files or directories not to link, one file/dir per line, containining only the path portion coming after the path into the rc. ex:
#
# tools/git.kak
# tools/go/
# filetypes/
#
# would exclude from being linked:
# the file: /usr/local/share/kak/rc/tools/git.kak
# the entire dir: /usr/local/share/kak/rc/tools/go/
# the entire dir: /usr/local/share/kak/rc/filetypes/
shopt -s nullglob
readonly KAK_LINK_DEST=~/.config/kak/autoload/rc/
readonly KAK_RC_DIR=/usr/local/share/kak/rc/
readonly KAK_BLOCKLIST_FILE=~/.config/kak/rc-blocklist.txt
# Create a directory and symlink structure in the first arg that mirrors the
# structure under the directory specified in the 2nd arg, filtering out directories
# and/or files specified in $KAK_BLOCKLIST_FILE c
# only creates links to files, not dirs, creating a dir tree in the dest that matches the source
# Arguments:
# 1. source dir containing dirs and files to link to
# 2. destination dir to create dirs/links in
function create_link_mirror () {
for dir in "$1"*/; do
local dir_name
dir_name=$(basename "$dir")
local dir_relative="${dir#"$KAK_RC_DIR"}"
if ! grep -q "${dir_relative}$" "$KAK_BLOCKLIST_FILE"; then
mkdir "${2}${dir_name}"
create_link_mirror "$dir" "${2}${dir_name}/"
else
echo "did not link dir $dir"
fi
done
for file in "$1"*; do
local file_relative="${file#"$KAK_RC_DIR"}"
if [ -f "$file" ]; then
if ! grep -q "${file_relative}$" "$KAK_BLOCKLIST_FILE"; then
ln -s "$file" "$2"
else
echo "did not link file $file"
fi
fi
done
}
ORANGE='\033[0;33m'
NORMAL='\033[0m'
echo "creating symlinks to: $KAK_RC_DIR"
echo "at destination: $KAK_LINK_DEST"
echo "not linking files listed in: $KAK_BLOCKLIST_FILE"
printf "%b! this will delete and recreate the destination dir !%b\n" $ORANGE $NORMAL
read -p "proceed? [y/n]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -rf -- "$KAK_LINK_DEST"
mkdir -p -- "$KAK_LINK_DEST"
create_link_mirror "$KAK_RC_DIR" "$KAK_LINK_DEST"
echo "linking complete"
else
echo "cancelled, links not created"
fi