@@ -28,7 +28,7 @@ use insert::*;
28use movement::Movement;
28use movement::Movement;
30use crate::{
30use crate::{
31− compositor::{Callback, Component, Compositor},
31+ compositor::{self, Callback, Component, Compositor},
32 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
32 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
@@ -1032,30 +1032,32 @@ mod cmd {
1032 pub alias: Option<&'static str>,
1032 pub alias: Option<&'static str>,
1033 pub doc: &'static str,
1033 pub doc: &'static str,
1034 // params, flags, helper, completer
1034 // params, flags, helper, completer
1035− pub fun: fn(&mut Editor, &[&str], PromptEvent),
1035+ pub fun: fn(&mut compositor::Context, &[&str], PromptEvent),
1036 pub completer: Option<Completer>,
1036 pub completer: Option<Completer>,
1039− fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1039+ fn quit(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1040 // last view and we have unsaved changes
1040 // last view and we have unsaved changes
1041− if editor.tree.views().count() == 1 && buffers_remaining_impl(editor) {
1041+ if cx.editor.tree.views().count() == 1 && buffers_remaining_impl(cx.editor) {
1044− editor.close(view!(editor).id, /* close_buffer */ false);
1045+ .close(view!(cx.editor).id, /* close_buffer */ false);
1047− fn force_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1048+ fn force_quit(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1048− editor.close(view!(editor).id, /* close_buffer */ false);
1050+ .close(view!(cx.editor).id, /* close_buffer */ false);
1051− fn open(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1053+ fn open(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1052 match args.get(0) {
1054 match args.get(0) {
1053 Some(path) => {
1055 Some(path) => {
1054 // TODO: handle error
1056 // TODO: handle error
1055− editor.open(path.into(), Action::Replace);
1057+ cx.editor.open(path.into(), Action::Replace);
1057 None => {
1059 None => {
1058− editor.set_error("wrong argument count".to_string());
1060+ cx.editor.set_error("wrong argument count".to_string());
@@ -1086,30 +1088,30 @@ mod cmd {
1089− fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1091+ fn write(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1090− let (view, doc) = current!(editor);
1092+ let (view, doc) = current!(cx.editor);
1091 if let Err(e) = write_impl(view, doc, args.first()) {
1093 if let Err(e) = write_impl(view, doc, args.first()) {
1092− editor.set_error(e.to_string());
1094+ cx.editor.set_error(e.to_string());
1096− fn new_file(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1098+ fn new_file(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1097− editor.new_file(Action::Replace);
1099+ cx.editor.new_file(Action::Replace);
1100− fn format(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1102+ fn format(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1101− let (view, doc) = current!(editor);
1103+ let (view, doc) = current!(cx.editor);
1103 doc.format(view.id)
1105 doc.format(view.id)
1106− fn set_indent_style(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1108+ fn set_indent_style(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1107 use IndentStyle::*;
1109 use IndentStyle::*;
1109 // If no argument, report current indent style.
1111 // If no argument, report current indent style.
1110 if args.is_empty() {
1112 if args.is_empty() {
1111− let style = current!(editor).1.indent_style;
1113+ let style = current!(cx.editor).1.indent_style;
1112− editor.set_status(match style {
1114+ cx.editor.set_status(match style {
1113 Tabs => "tabs".into(),
1115 Tabs => "tabs".into(),
1114 Spaces(1) => "1 space".into(),
1116 Spaces(1) => "1 space".into(),
1115 Spaces(n) if (2..=8).contains(&n) => format!("{} spaces", n),
1117 Spaces(n) if (2..=8).contains(&n) => format!("{} spaces", n),
@@ -1131,22 +1133,23 @@ mod cmd {
1133 if let Some(s) = style {
1135 if let Some(s) = style {
1134− let doc = doc_mut!(editor);
1136+ let doc = doc_mut!(cx.editor);
1135 doc.indent_style = s;
1137 doc.indent_style = s;
1136 } else {
1138 } else {
1137 // Invalid argument.
1139 // Invalid argument.
1138− editor.set_error(format!("invalid indent style '{}'", args[0],));
1141+ .set_error(format!("invalid indent style '{}'", args[0],));
1142 /// Sets or reports the current document's line ending setting.
1145 /// Sets or reports the current document's line ending setting.
1143− fn set_line_ending(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1146+ fn set_line_ending(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1144 use LineEnding::*;
1147 use LineEnding::*;
1146 // If no argument, report current line ending setting.
1149 // If no argument, report current line ending setting.
1147 if args.is_empty() {
1150 if args.is_empty() {
1148− let line_ending = current!(editor).1.line_ending;
1151+ let line_ending = current!(cx.editor).1.line_ending;
1149− editor.set_status(match line_ending {
1152+ cx.editor.set_status(match line_ending {
1150 Crlf => "crlf".into(),
1153 Crlf => "crlf".into(),
1151 LF => "line feed".into(),
1154 LF => "line feed".into(),
1152 FF => "form feed".into(),
1155 FF => "form feed".into(),
@@ -1171,49 +1174,50 @@ mod cmd {
1173 if let Some(le) = line_ending {
1176 if let Some(le) = line_ending {
1174− doc_mut!(editor).line_ending = le;
1177+ doc_mut!(cx.editor).line_ending = le;
1175 } else {
1178 } else {
1176 // Invalid argument.
1179 // Invalid argument.
1177− editor.set_error(format!("invalid line ending '{}'", args[0],));
1181+ .set_error(format!("invalid line ending '{}'", args[0],));
1181− fn earlier(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1185+ fn earlier(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1182 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
1186 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
1183 Ok(uk) => uk,
1187 Ok(uk) => uk,
1184 Err(msg) => {
1188 Err(msg) => {
1185− editor.set_error(msg);
1189+ cx.editor.set_error(msg);
1189− let (view, doc) = current!(editor);
1193+ let (view, doc) = current!(cx.editor);
1190 doc.earlier(view.id, uk)
1194 doc.earlier(view.id, uk)
1193− fn later(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1197+ fn later(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1194 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
1198 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
1195 Ok(uk) => uk,
1199 Ok(uk) => uk,
1196 Err(msg) => {
1200 Err(msg) => {
1197− editor.set_error(msg);
1201+ cx.editor.set_error(msg);
1201− let (view, doc) = current!(editor);
1205+ let (view, doc) = current!(cx.editor);
1202 doc.later(view.id, uk)
1206 doc.later(view.id, uk)
1205− fn write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1209+ fn write_quit(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1206− let (view, doc) = current!(editor);
1210+ let (view, doc) = current!(cx.editor);
1207 if let Err(e) = write_impl(view, doc, args.first()) {
1211 if let Err(e) = write_impl(view, doc, args.first()) {
1208− editor.set_error(e.to_string());
1212+ cx.editor.set_error(e.to_string());
1211− quit(editor, &[], event)
1215+ quit(cx, &[], event)
1214− fn force_write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1218+ fn force_write_quit(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1215− write(editor, args, event);
1219+ write(cx, args, event);
1216− force_quit(editor, &[], event);
1220+ force_quit(cx, &[], event);
1219 /// Returns `true` if there are modified buffers remaining and sets editor error,
1223 /// Returns `true` if there are modified buffers remaining and sets editor error,
@@ -1273,16 +1277,16 @@ mod cmd {
1276− fn write_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1280+ fn write_all(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1277− write_all_impl(editor, args, event, false, false)
1281+ write_all_impl(&mut cx.editor, args, event, false, false)
1280− fn write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1284+ fn write_all_quit(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1281− write_all_impl(editor, args, event, true, false)
1285+ write_all_impl(&mut cx.editor, args, event, true, false)
1284− fn force_write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1288+ fn force_write_all_quit(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1285− write_all_impl(editor, args, event, true, true)
1289+ write_all_impl(&mut cx.editor, args, event, true, true)
1288 fn quit_all_impl(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
1292 fn quit_all_impl(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
@@ -1297,50 +1301,50 @@ mod cmd {
1300− fn quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1304+ fn quit_all(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1301− quit_all_impl(editor, args, event, false)
1305+ quit_all_impl(&mut cx.editor, args, event, false)
1304− fn force_quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1308+ fn force_quit_all(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1305− quit_all_impl(editor, args, event, true)
1309+ quit_all_impl(&mut cx.editor, args, event, true)
1308− fn theme(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1312+ fn theme(cx: &mut compositor::Context, args: &[&str], event: PromptEvent) {
1309 let theme = if let Some(theme) = args.first() {
1313 let theme = if let Some(theme) = args.first() {
1311 } else {
1315 } else {
1312− editor.set_error("theme name not provided".into());
1316+ cx.editor.set_error("theme name not provided".into());
1316− editor.set_theme_from_name(theme);
1320+ cx.editor.set_theme_from_name(theme);
1319− fn yank_main_selection_to_clipboard(editor: &mut Editor, _: &[&str], _: PromptEvent) {
1323+ fn yank_main_selection_to_clipboard(cx: &mut compositor::Context, _: &[&str], _: PromptEvent) {
1320− yank_main_selection_to_clipboard_impl(editor);
1324+ yank_main_selection_to_clipboard_impl(&mut cx.editor);
1323− fn yank_joined_to_clipboard(editor: &mut Editor, args: &[&str], _: PromptEvent) {
1327+ fn yank_joined_to_clipboard(cx: &mut compositor::Context, args: &[&str], _: PromptEvent) {
1324− let (_, doc) = current!(editor);
1328+ let (_, doc) = current!(cx.editor);
1325 let separator = args
1329 let separator = args
1326 .first()
1330 .first()
1327 .copied()
1331 .copied()
1328 .unwrap_or_else(|| doc.line_ending.as_str());
1332 .unwrap_or_else(|| doc.line_ending.as_str());
1329− yank_joined_to_clipboard_impl(editor, separator);
1333+ yank_joined_to_clipboard_impl(&mut cx.editor, separator);
1332− fn paste_clipboard_after(editor: &mut Editor, _: &[&str], _: PromptEvent) {
1336+ fn paste_clipboard_after(cx: &mut compositor::Context, _: &[&str], _: PromptEvent) {
1333− paste_clipboard_impl(editor, Paste::After);
1337+ paste_clipboard_impl(&mut cx.editor, Paste::After);
1336− fn paste_clipboard_before(editor: &mut Editor, _: &[&str], _: PromptEvent) {
1340+ fn paste_clipboard_before(cx: &mut compositor::Context, _: &[&str], _: PromptEvent) {
1337− paste_clipboard_impl(editor, Paste::After);
1341+ paste_clipboard_impl(&mut cx.editor, Paste::After);
1340− fn replace_selections_with_clipboard(editor: &mut Editor, _: &[&str], _: PromptEvent) {
1344+ fn replace_selections_with_clipboard(cx: &mut compositor::Context, _: &[&str], _: PromptEvent) {
1341− let (view, doc) = current!(editor);
1345+ let (view, doc) = current!(cx.editor);
1343− match editor.clipboard_provider.get_contents() {
1347+ match cx.editor.clipboard_provider.get_contents() {
1344 Ok(contents) => {
1348 Ok(contents) => {
1345 let transaction =
1349 let transaction =
1346 Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
1350 Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
@@ -1356,8 +1360,9 @@ mod cmd {
1359− fn show_clipboard_provider(editor: &mut Editor, _: &[&str], _: PromptEvent) {
1363+ fn show_clipboard_provider(cx: &mut compositor::Context, _: &[&str], _: PromptEvent) {
1360− editor.set_status(editor.clipboard_provider.name().into());
1365+ .set_status(cx.editor.clipboard_provider.name().into());
1363 fn change_current_directory(editor: &mut Editor, args: &[&str], _: PromptEvent) {
1368 fn change_current_directory(editor: &mut Editor, args: &[&str], _: PromptEvent) {
@@ -1633,7 +1638,7 @@ fn command_mode(cx: &mut Context) {
1635 }, // completion
1640 }, // completion
1636− move |editor: &mut Editor, input: &str, event: PromptEvent| {
1641+ move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
1637 use helix_view::editor::Action;
1642 use helix_view::editor::Action;
1639 if event != PromptEvent::Validate {
1644 if event != PromptEvent::Validate {
@@ -1646,9 +1651,10 @@ fn command_mode(cx: &mut Context) {
1648 if let Some(cmd) = cmd::COMMANDS.get(parts[0]) {
1653 if let Some(cmd) = cmd::COMMANDS.get(parts[0]) {
1649− (cmd.fun)(editor, &parts[1..], event);
1654+ (cmd.fun)(cx, &parts[1..], event);
1650 } else {
1655 } else {
1651− editor.set_error(format!("no such command: '{}'", parts[0]));
1657+ .set_error(format!("no such command: '{}'", parts[0]));