on master help sign in
Use `_impl` suffix instead of `_` prefix
6fb2d26Benoît CORTIER
helix-term/src/commands.rs+49−44
@@ -40,7 +40,7 @@ use once_cell::sync::Lazy;
40
40
41pub struct Context<'a> {
41pub struct Context<'a> {
42 pub register: helix_view::RegisterSelection,
42 pub register: helix_view::RegisterSelection,
43− pub _count: Option<std::num::NonZeroUsize>,
43+ pub count: Option<std::num::NonZeroUsize>,
44 pub editor: &'a mut Editor,
44 pub editor: &'a mut Editor,
45
45
46 pub callback: Option<crate::compositor::Callback>,
46 pub callback: Option<crate::compositor::Callback>,
@@ -103,7 +103,7 @@ impl<'a> Context<'a> {
103
103
104 #[inline]
104 #[inline]
105 pub fn count(&self) -> usize {
105 pub fn count(&self) -> usize {
106− self._count.map_or(1, |v| v.get())
106+ self.count.map_or(1, |v| v.get())
107 }
107 }
108}
108}
109
109
@@ -315,7 +315,7 @@ pub fn extend_next_word_end(cx: &mut Context) {
315}
315}
316
316
317#[inline]
317#[inline]
318−fn _find_char<F>(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool)
318+fn find_char_impl<F>(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool)
319where
319where
320 // TODO: make an options struct for and abstract this Fn into a searcher type
320 // TODO: make an options struct for and abstract this Fn into a searcher type
321 // use the definition for w/b/e too
321 // use the definition for w/b/e too
@@ -359,7 +359,7 @@ where
359}
359}
360
360
361pub fn find_till_char(cx: &mut Context) {
361pub fn find_till_char(cx: &mut Context) {
362− _find_char(
362+ find_char_impl(
363 cx,
363 cx,
364 search::find_nth_next,
364 search::find_nth_next,
365 false, /* inclusive */
365 false, /* inclusive */
@@ -368,7 +368,7 @@ pub fn find_till_char(cx: &mut Context) {
368}
368}
369
369
370pub fn find_next_char(cx: &mut Context) {
370pub fn find_next_char(cx: &mut Context) {
371− _find_char(
371+ find_char_impl(
372 cx,
372 cx,
373 search::find_nth_next,
373 search::find_nth_next,
374 true, /* inclusive */
374 true, /* inclusive */
@@ -377,7 +377,7 @@ pub fn find_next_char(cx: &mut Context) {
377}
377}
378
378
379pub fn extend_till_char(cx: &mut Context) {
379pub fn extend_till_char(cx: &mut Context) {
380− _find_char(
380+ find_char_impl(
381 cx,
381 cx,
382 search::find_nth_next,
382 search::find_nth_next,
383 false, /* inclusive */
383 false, /* inclusive */
@@ -386,7 +386,7 @@ pub fn extend_till_char(cx: &mut Context) {
386}
386}
387
387
388pub fn extend_next_char(cx: &mut Context) {
388pub fn extend_next_char(cx: &mut Context) {
389− _find_char(
389+ find_char_impl(
390 cx,
390 cx,
391 search::find_nth_next,
391 search::find_nth_next,
392 true, /* inclusive */
392 true, /* inclusive */
@@ -395,7 +395,7 @@ pub fn extend_next_char(cx: &mut Context) {
395}
395}
396
396
397pub fn till_prev_char(cx: &mut Context) {
397pub fn till_prev_char(cx: &mut Context) {
398− _find_char(
398+ find_char_impl(
399 cx,
399 cx,
400 search::find_nth_prev,
400 search::find_nth_prev,
401 false, /* inclusive */
401 false, /* inclusive */
@@ -404,7 +404,7 @@ pub fn till_prev_char(cx: &mut Context) {
404}
404}
405
405
406pub fn find_prev_char(cx: &mut Context) {
406pub fn find_prev_char(cx: &mut Context) {
407− _find_char(
407+ find_char_impl(
408 cx,
408 cx,
409 search::find_nth_prev,
409 search::find_nth_prev,
410 true, /* inclusive */
410 true, /* inclusive */
@@ -413,7 +413,7 @@ pub fn find_prev_char(cx: &mut Context) {
413}
413}
414
414
415pub fn extend_till_prev_char(cx: &mut Context) {
415pub fn extend_till_prev_char(cx: &mut Context) {
416− _find_char(
416+ find_char_impl(
417 cx,
417 cx,
418 search::find_nth_prev,
418 search::find_nth_prev,
419 false, /* inclusive */
419 false, /* inclusive */
@@ -422,7 +422,7 @@ pub fn extend_till_prev_char(cx: &mut Context) {
422}
422}
423
423
424pub fn extend_prev_char(cx: &mut Context) {
424pub fn extend_prev_char(cx: &mut Context) {
425− _find_char(
425+ find_char_impl(
426 cx,
426 cx,
427 search::find_nth_prev,
427 search::find_nth_prev,
428 true, /* inclusive */
428 true, /* inclusive */
@@ -669,7 +669,7 @@ pub fn split_selection_on_newline(cx: &mut Context) {
669// I'd probably collect all the matches right now and store the current index. The cache needs
669// I'd probably collect all the matches right now and store the current index. The cache needs
670// wiping if input happens.
670// wiping if input happens.
671
671
672−fn _search(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) {
672+fn search_impl(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) {
673 let text = doc.text();
673 let text = doc.text();
674 let selection = doc.selection(view.id);
674 let selection = doc.selection(view.id);
675 let start = text.char_to_byte(selection.cursor());
675 let start = text.char_to_byte(selection.cursor());
@@ -715,8 +715,7 @@ pub fn search(cx: &mut Context) {
715
715
716 let view_id = view.id;
716 let view_id = view.id;
717 let prompt = ui::regex_prompt(cx, "search:".to_string(), move |view, doc, regex| {
717 let prompt = ui::regex_prompt(cx, "search:".to_string(), move |view, doc, regex| {
718− _search(doc, view, &contents, &regex, false);
718+ search_impl(doc, view, &contents, &regex, false);
719−
720 // TODO: only store on enter (accept), not update
719 // TODO: only store on enter (accept), not update
721 register::set('\\', vec![regex.as_str().to_string()]);
720 register::set('\\', vec![regex.as_str().to_string()]);
722 });
721 });
@@ -725,22 +724,22 @@ pub fn search(cx: &mut Context) {
725}
724}
726// can't search next for ""compose"" for some reason
725// can't search next for ""compose"" for some reason
727
726
728−pub fn _search_next(cx: &mut Context, extend: bool) {
727+pub fn search_next_impl(cx: &mut Context, extend: bool) {
729 if let Some(query) = register::get('\\') {
728 if let Some(query) = register::get('\\') {
730 let query = query.first().unwrap();
729 let query = query.first().unwrap();
731 let (view, doc) = cx.current();
730 let (view, doc) = cx.current();
732 let contents = doc.text().slice(..).to_string();
731 let contents = doc.text().slice(..).to_string();
733 let regex = Regex::new(query).unwrap();
732 let regex = Regex::new(query).unwrap();
734− _search(doc, view, &contents, &regex, extend);
733+ search_impl(doc, view, &contents, &regex, extend);
735 }
734 }
736}
735}
737
736
738pub fn search_next(cx: &mut Context) {
737pub fn search_next(cx: &mut Context) {
739− _search_next(cx, false);
738+ search_next_impl(cx, false);
740}
739}
741
740
742pub fn extend_search_next(cx: &mut Context) {
741pub fn extend_search_next(cx: &mut Context) {
743− _search_next(cx, true);
742+ search_next_impl(cx, true);
744}
743}
745
744
746pub fn search_selection(cx: &mut Context) {
745pub fn search_selection(cx: &mut Context) {
@@ -795,7 +794,7 @@ pub fn extend_line(cx: &mut Context) {
795
794
796// heuristic: append changes to history after each command, unless we're in insert mode
795// heuristic: append changes to history after each command, unless we're in insert mode
797
796
798−fn _delete_selection(reg: char, doc: &mut Document, view_id: ViewId) {
797+fn delete_selection_impl(reg: char, doc: &mut Document, view_id: ViewId) {
799 // first yank the selection
798 // first yank the selection
800 let values: Vec<String> = doc
799 let values: Vec<String> = doc
801 .selection(view_id)
800 .selection(view_id)
@@ -818,7 +817,7 @@ fn _delete_selection(reg: char, doc: &mut Document, view_id: ViewId) {
818pub fn delete_selection(cx: &mut Context) {
817pub fn delete_selection(cx: &mut Context) {
819 let reg = cx.register.name();
818 let reg = cx.register.name();
820 let (view, doc) = cx.current();
819 let (view, doc) = cx.current();
821− _delete_selection(reg, doc, view.id);
820+ delete_selection_impl(reg, doc, view.id);
822
821
823 doc.append_changes_to_history(view.id);
822 doc.append_changes_to_history(view.id);
824
823
@@ -829,7 +828,7 @@ pub fn delete_selection(cx: &mut Context) {
829pub fn change_selection(cx: &mut Context) {
828pub fn change_selection(cx: &mut Context) {
830 let reg = cx.register.name();
829 let reg = cx.register.name();
831 let (view, doc) = cx.current();
830 let (view, doc) = cx.current();
832− _delete_selection(reg, doc, view.id);
831+ delete_selection_impl(reg, doc, view.id);
833 enter_insert_mode(doc);
832 enter_insert_mode(doc);
834}
833}
835
834
@@ -912,7 +911,7 @@ mod cmd {
912
911
913 fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
912 fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
914 // last view and we have unsaved changes
913 // last view and we have unsaved changes
915− if editor.tree.views().count() == 1 && _buffers_remaining(editor) {
914+ if editor.tree.views().count() == 1 && buffers_remaining_impl(editor) {
916 return;
915 return;
917 }
916 }
918 editor.close(editor.view().id, /* close_buffer */ false);
917 editor.close(editor.view().id, /* close_buffer */ false);
@@ -934,7 +933,7 @@ mod cmd {
934 };
933 };
935 }
934 }
936
935
937− fn _write<P: AsRef<Path>>(
936+ fn write_impl<P: AsRef<Path>>(
938 view: &View,
937 view: &View,
939 doc: &mut Document,
938 doc: &mut Document,
940 path: Option<P>,
939 path: Option<P>,
@@ -962,7 +961,7 @@ mod cmd {
962
961
963 fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
962 fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
964 let (view, doc) = editor.current();
963 let (view, doc) = editor.current();
965− if let Err(e) = _write(view, doc, args.first()) {
964+ if let Err(e) = write_impl(view, doc, args.first()) {
966 editor.set_error(e.to_string());
965 editor.set_error(e.to_string());
967 };
966 };
968 }
967 }
@@ -1039,7 +1038,7 @@ mod cmd {
1039
1038
1040 fn write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1039 fn write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1041 let (view, doc) = editor.current();
1040 let (view, doc) = editor.current();
1042− if let Err(e) = _write(view, doc, args.first()) {
1041+ if let Err(e) = write_impl(view, doc, args.first()) {
1043 editor.set_error(e.to_string());
1042 editor.set_error(e.to_string());
1044 return;
1043 return;
1045 };
1044 };
@@ -1053,7 +1052,7 @@ mod cmd {
1053
1052
1054 /// Returns `true` if there are modified buffers remaining and sets editor error,
1053 /// Returns `true` if there are modified buffers remaining and sets editor error,
1055 /// otherwise returns `false`
1054 /// otherwise returns `false`
1056− fn _buffers_remaining(editor: &mut Editor) -> bool {
1055+ fn buffers_remaining_impl(editor: &mut Editor) -> bool {
1057 let modified: Vec<_> = editor
1056 let modified: Vec<_> = editor
1058 .documents()
1057 .documents()
1059 .filter(|doc| doc.is_modified())
1058 .filter(|doc| doc.is_modified())
@@ -1076,7 +1075,13 @@ mod cmd {
1076 }
1075 }
1077 }
1076 }
1078
1077
1079− fn _write_all(editor: &mut Editor, args: &[&str], event: PromptEvent, quit: bool, force: bool) {
1078+ fn write_all_impl(
1079+ editor: &mut Editor,
1080+ args: &[&str],
1081+ event: PromptEvent,
1082+ quit: bool,
1083+ force: bool,
1084+ ) {
1080 let mut errors = String::new();
1085 let mut errors = String::new();
1081
1086
1082 // save all documents
1087 // save all documents
@@ -1090,7 +1095,7 @@ mod cmd {
1090 editor.set_error(errors);
1095 editor.set_error(errors);
1091
1096
1092 if quit {
1097 if quit {
1093− if !force && _buffers_remaining(editor) {
1098+ if !force && buffers_remaining_impl(editor) {
1094 return;
1099 return;
1095 }
1100 }
1096
1101
@@ -1103,19 +1108,19 @@ mod cmd {
1103 }
1108 }
1104
1109
1105 fn write_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1110 fn write_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1106− _write_all(editor, args, event, false, false)
1111+ write_all_impl(editor, args, event, false, false)
1107 }
1112 }
1108
1113
1109 fn write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1114 fn write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1110− _write_all(editor, args, event, true, false)
1115+ write_all_impl(editor, args, event, true, false)
1111 }
1116 }
1112
1117
1113 fn force_write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1118 fn force_write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1114− _write_all(editor, args, event, true, true)
1119+ write_all_impl(editor, args, event, true, true)
1115 }
1120 }
1116
1121
1117− fn _quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
1122+ fn quit_all_impl(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
1118− if !force && _buffers_remaining(editor) {
1123+ if !force && buffers_remaining_impl(editor) {
1119 return;
1124 return;
1120 }
1125 }
1121
1126
@@ -1127,11 +1132,11 @@ mod cmd {
1127 }
1132 }
1128
1133
1129 fn quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1134 fn quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1130− _quit_all(editor, args, event, false)
1135+ quit_all_impl(editor, args, event, false)
1131 }
1136 }
1132
1137
1133 fn force_quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1138 fn force_quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1134− _quit_all(editor, args, event, true)
1139+ quit_all_impl(editor, args, event, true)
1135 }
1140 }
1136
1141
1137 pub const COMMAND_LIST: &[Command] = &[
1142 pub const COMMAND_LIST: &[Command] = &[
@@ -1578,7 +1583,7 @@ fn switch_to_last_accessed_file(cx: &mut Context) {
1578}
1583}
1579
1584
1580pub fn goto_mode(cx: &mut Context) {
1585pub fn goto_mode(cx: &mut Context) {
1581− if let Some(count) = cx._count {
1586+ if let Some(count) = cx.count {
1582 push_jump(cx.editor);
1587 push_jump(cx.editor);
1583
1588
1584 let (view, doc) = cx.current();
1589 let (view, doc) = cx.current();
@@ -1646,7 +1651,7 @@ pub fn exit_select_mode(cx: &mut Context) {
1646 cx.doc().mode = Mode::Normal;
1651 cx.doc().mode = Mode::Normal;
1647}
1652}
1648
1653
1649−fn _goto(
1654+fn goto_impl(
1650 editor: &mut Editor,
1655 editor: &mut Editor,
1651 compositor: &mut Compositor,
1656 compositor: &mut Compositor,
1652 locations: Vec<lsp::Location>,
1657 locations: Vec<lsp::Location>,
@@ -1734,7 +1739,7 @@ pub fn goto_definition(cx: &mut Context) {
1734 None => Vec::new(),
1739 None => Vec::new(),
1735 };
1740 };
1736
1741
1737− _goto(editor, compositor, items, offset_encoding);
1742+ goto_impl(editor, compositor, items, offset_encoding);
1738 },
1743 },
1739 );
1744 );
1740}
1745}
@@ -1771,7 +1776,7 @@ pub fn goto_type_definition(cx: &mut Context) {
1771 None => Vec::new(),
1776 None => Vec::new(),
1772 };
1777 };
1773
1778
1774− _goto(editor, compositor, items, offset_encoding);
1779+ goto_impl(editor, compositor, items, offset_encoding);
1775 },
1780 },
1776 );
1781 );
1777}
1782}
@@ -1808,7 +1813,7 @@ pub fn goto_implementation(cx: &mut Context) {
1808 None => Vec::new(),
1813 None => Vec::new(),
1809 };
1814 };
1810
1815
1811− _goto(editor, compositor, items, offset_encoding);
1816+ goto_impl(editor, compositor, items, offset_encoding);
1812 },
1817 },
1813 );
1818 );
1814}
1819}
@@ -1832,7 +1837,7 @@ pub fn goto_reference(cx: &mut Context) {
1832 move |editor: &mut Editor,
1837 move |editor: &mut Editor,
1833 compositor: &mut Compositor,
1838 compositor: &mut Compositor,
1834 items: Option<Vec<lsp::Location>>| {
1839 items: Option<Vec<lsp::Location>>| {
1835− _goto(
1840+ goto_impl(
1836 editor,
1841 editor,
1837 compositor,
1842 compositor,
1838 items.unwrap_or_default(),
1843 items.unwrap_or_default(),
@@ -2236,7 +2241,7 @@ enum Paste {
2236 After,
2241 After,
2237}
2242}
2238
2243
2239−fn _paste(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option<Transaction> {
2244+fn paste_impl(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option<Transaction> {
2240 if let Some(values) = register::get(reg) {
2245 if let Some(values) = register::get(reg) {
2241 let repeat = std::iter::repeat(
2246 let repeat = std::iter::repeat(
2242 values
2247 values
@@ -2305,7 +2310,7 @@ pub fn paste_after(cx: &mut Context) {
2305 let reg = cx.register.name();
2310 let reg = cx.register.name();
2306 let (view, doc) = cx.current();
2311 let (view, doc) = cx.current();
2307
2312
2308− if let Some(transaction) = _paste(reg, doc, view, Paste::After) {
2313+ if let Some(transaction) = paste_impl(reg, doc, view, Paste::After) {
2309 doc.apply(&transaction, view.id);
2314 doc.apply(&transaction, view.id);
2310 doc.append_changes_to_history(view.id);
2315 doc.append_changes_to_history(view.id);
2311 }
2316 }
@@ -2315,7 +2320,7 @@ pub fn paste_before(cx: &mut Context) {
2315 let reg = cx.register.name();
2320 let reg = cx.register.name();
2316 let (view, doc) = cx.current();
2321 let (view, doc) = cx.current();
2317
2322
2318− if let Some(transaction) = _paste(reg, doc, view, Paste::Before) {
2323+ if let Some(transaction) = paste_impl(reg, doc, view, Paste::Before) {
2319 doc.apply(&transaction, view.id);
2324 doc.apply(&transaction, view.id);
2320 doc.append_changes_to_history(view.id);
2325 doc.append_changes_to_history(view.id);
2321 }
2326 }
helix-term/src/ui/editor.rs+2−2
@@ -564,7 +564,7 @@ impl EditorView {
564 }
564 }
565 _ => {
565 _ => {
566 // set the count
566 // set the count
567− cxt._count = cxt.editor.count.take();
567+ cxt.count = cxt.editor.count.take();
568 // TODO: edge case: 0j -> reset to 1
568 // TODO: edge case: 0j -> reset to 1
569 // if this fails, count was Some(0)
569 // if this fails, count was Some(0)
570 // debug_assert!(cxt.count != 0);
570 // debug_assert!(cxt.count != 0);
@@ -612,7 +612,7 @@ impl Component for EditorView {
612 let mut cxt = commands::Context {
612 let mut cxt = commands::Context {
613 register: helix_view::RegisterSelection::default(),
613 register: helix_view::RegisterSelection::default(),
614 editor: &mut cx.editor,
614 editor: &mut cx.editor,
615− _count: None,
615+ count: None,
616 callback: None,
616 callback: None,
617 on_next_key_callback: None,
617 on_next_key_callback: None,
618 callbacks: cx.callbacks,
618 callbacks: cx.callbacks,