<commit_before>package edit

import (
	"io"
	"strings"
	"unicode"
	"unicode/utf8"

	"github.com/elves/elvish/edit/ui"
	"github.com/elves/elvish/eval"
	"github.com/elves/elvish/util"
)

// Builtins related to insert and command mode.

var (
	_ = registerBuiltins("", map[string]func(*Editor){
		"kill-line-left":       killLineLeft,
		"kill-line-right":      killLineRight,
		"kill-word-left":       killWordLeft,
		"kill-small-word-left": killSmallWordLeft,
		"kill-rune-left":       killRuneLeft,
		"kill-rune-right":      killRuneRight,

		"move-dot-left":       moveDotLeft,
		"move-dot-right":      moveDotRight,
		"move-dot-left-word":  moveDotLeftWord,
		"move-dot-right-word": moveDotRightWord,
		"move-dot-sol":        moveDotSOL,
		"move-dot-eol":        moveDotEOL,
		"move-dot-up":         moveDotUp,
		"move-dot-down":       moveDotDown,

		"insert-last-word": insertLastWord,
		"insert-key":       insertKey,

		"return-line": returnLine,
		"smart-enter": smartEnter,
		"return-eof":  returnEOF,

		"toggle-quote-paste": toggleQuotePaste,
		"insert-raw":         startInsertRaw,

		"end-of-history": endOfHistory,
		"redraw":         redraw,
	})
	_ = registerBuiltins("insert", map[string]func(*Editor){
		"start":   insertStart,
		"default": insertDefault,
	})
	_ = registerBuiltins("command", map[string]func(*Editor){
		"start":   commandStart,
		"default": commandDefault,
	})
)

func init() {
	registerBindings(modeInsert, "", map[ui.Key]string{
		// Moving.
		{ui.Left, 0}:        "move-dot-left",
		{ui.Right, 0}:       "move-dot-right",
		{ui.Up, ui.Alt}:     "move-dot-up",
		{ui.Down, ui.Alt}:   "move-dot-down",
		{ui.Left, ui.Ctrl}:  "move-dot-left-word",
		{ui.Right, ui.Ctrl}: "move-dot-right-word",
		{ui.Home, 0}:        "move-dot-sol",
		{ui.End, 0}:         "move-dot-eol",
		// Killing.
		{'U', ui.Ctrl}:    "kill-line-left",
		{'K', ui.Ctrl}:    "kill-line-right",
		{'W', ui.Ctrl}:    "kill-word-left",
		{ui.Backspace, 0}: "kill-rune-left",
		// Some terminal send ^H on backspace
		// ui.Key{'H', ui.Ctrl}: "kill-rune-left",
		{ui.Delete, 0}: "kill-rune-right",
		// Inserting.<commit_msg>Bind Alt-{b,f} to edit:move-dot-{left,right}-word by default.<commit_after>package edit

import (
	"io"
	"strings"
	"unicode"
	"unicode/utf8"

	"github.com/elves/elvish/edit/ui"
	"github.com/elves/elvish/eval"
	"github.com/elves/elvish/util"
)

// Builtins related to insert and command mode.

var (
	_ = registerBuiltins("", map[string]func(*Editor){
		"kill-line-left":       killLineLeft,
		"kill-line-right":      killLineRight,
		"kill-word-left":       killWordLeft,
		"kill-small-word-left": killSmallWordLeft,
		"kill-rune-left":       killRuneLeft,
		"kill-rune-right":      killRuneRight,

		"move-dot-left":       moveDotLeft,
		"move-dot-right":      moveDotRight,
		"move-dot-left-word":  moveDotLeftWord,
		"move-dot-right-word": moveDotRightWord,
		"move-dot-sol":        moveDotSOL,
		"move-dot-eol":        moveDotEOL,
		"move-dot-up":         moveDotUp,
		"move-dot-down":       moveDotDown,

		"insert-last-word": insertLastWord,
		"insert-key":       insertKey,

		"return-line": returnLine,
		"smart-enter": smartEnter,
		"return-eof":  returnEOF,

		"toggle-quote-paste": toggleQuotePaste,
		"insert-raw":         startInsertRaw,

		"end-of-history": endOfHistory,
		"redraw":         redraw,
	})
	_ = registerBuiltins("insert", map[string]func(*Editor){
		"start":   insertStart,
		"default": insertDefault,
	})
	_ = registerBuiltins("command", map[string]func(*Editor){
		"start":   commandStart,
		"default": commandDefault,
	})
)

func init() {
	registerBindings(modeInsert, "", map[ui.Key]string{
		// Moving.
		{ui.Left, 0}:        "move-dot-left",
		{ui.Right, 0}:       "move-dot-right",
		{ui.Up, ui.Alt}:     "move-dot-up",
		{ui.Down, ui.Alt}:   "move-dot-down",
		{ui.Left, ui.Ctrl}:  "move-dot-left-word",
		{ui.Right, ui.Ctrl}: "move-dot-right-word",
		{'b', ui.Alt}:       "move-dot-left-word",
		{'f', ui.Alt}:       "move-dot-right-word",
		{ui.Home, 0}:        "move-dot-sol",
		{ui.End, 0}:         "move-dot-eol",
		// Killing.
		{'U', ui.Ctrl}:    "kill-line-left",
		{'K', ui.Ctrl}:    "kill-line-right",
		{'W', ui.Ctrl}:    "kill-word-left",
		{ui.Backspace, 0}: "kill-rune-left",
		// Some terminal send ^H on backspace
		// ui.Key{'H', ui.Ctrl}: "kill-rune-left",
		{ui.Delete, 0}: "kill-rune-right",
		// Inserting.
{'fraction_non_alphanumeric': 0.19457735247208932, 'fraction_numerical': 0.003189792663476874, 'mean_word_length': 3.0018231540565177, 'pattern_counts': {'":': 54, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5345101', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1697, 'n_words': 276}