on master help sign in
Use `_impl` suffix instead of `_` prefix

Helpers / internal implementations where using the `_` prefix. However, this prefix also suppress unused warnings. I suggest we use the `_impl` suffix instead.

commit6fb2d2679dc63ca34be0d02efb543c3e0b49cb74 authorBenoît CORTIER <benoit.cortier@fried-world.eu> dateTue 15 Jun 2021, 00:29 (5 years ago) parenteb77de6
2 files changed+51−46
helix-term/src/commands.rs+49−44 helix-term/src/ui/editor.rs+2−2
helix-term/src/commands.rs+49−44
@@ -40,7 +40,7 @@ use once_cell::sync::Lazy;
4040
4141pub struct Context<'a> {
4242 pub register: helix_view::RegisterSelection,
43− pub _count: Option<std::num::NonZeroUsize>,
43+ pub count: Option<std::num::NonZeroUsize>,
4444 pub editor: &'a mut Editor,
4545
4646 pub callback: Option<crate::compositor::Callback>,
@@ -103,7 +103,7 @@ impl<'a> Context<'a> {
103103
104104 #[inline]
105105 pub fn count(&self) -> usize {
106− self._count.map_or(1, |v| v.get())
106+ self.count.map_or(1, |v| v.get())
107107 }
108108}
109109
@@ -315,7 +315,7 @@ pub fn extend_next_word_end(cx: &mut Context) {
315315}
316316
317317#[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)
319319where
320320 // TODO: make an options struct for and abstract this Fn into a searcher type
321321 // use the definition for w/b/e too
@@ -359,7 +359,7 @@ where
359359}
360360
361361pub fn find_till_char(cx: &mut Context) {
362− _find_char(
362+ find_char_impl(
363363 cx,
364364 search::find_nth_next,
365365 false, /* inclusive */
@@ -368,7 +368,7 @@ pub fn find_till_char(cx: &mut Context) {
368368}
369369
370370pub fn find_next_char(cx: &mut Context) {
371− _find_char(
371+ find_char_impl(
372372 cx,
373373 search::find_nth_next,
374374 true, /* inclusive */
@@ -377,7 +377,7 @@ pub fn find_next_char(cx: &mut Context) {
377377}
378378
379379pub fn extend_till_char(cx: &mut Context) {
380− _find_char(
380+ find_char_impl(
381381 cx,
382382 search::find_nth_next,
383383 false, /* inclusive */
@@ -386,7 +386,7 @@ pub fn extend_till_char(cx: &mut Context) {
386386}
387387
388388pub fn extend_next_char(cx: &mut Context) {
389− _find_char(
389+ find_char_impl(
390390 cx,
391391 search::find_nth_next,
392392 true, /* inclusive */
@@ -395,7 +395,7 @@ pub fn extend_next_char(cx: &mut Context) {
395395}
396396
397397pub fn till_prev_char(cx: &mut Context) {
398− _find_char(
398+ find_char_impl(
399399 cx,
400400 search::find_nth_prev,
401401 false, /* inclusive */
@@ -404,7 +404,7 @@ pub fn till_prev_char(cx: &mut Context) {
404404}
405405
406406pub fn find_prev_char(cx: &mut Context) {
407− _find_char(
407+ find_char_impl(
408408 cx,
409409 search::find_nth_prev,
410410 true, /* inclusive */
@@ -413,7 +413,7 @@ pub fn find_prev_char(cx: &mut Context) {
413413}
414414
415415pub fn extend_till_prev_char(cx: &mut Context) {
416− _find_char(
416+ find_char_impl(
417417 cx,
418418 search::find_nth_prev,
419419 false, /* inclusive */
@@ -422,7 +422,7 @@ pub fn extend_till_prev_char(cx: &mut Context) {
422422}
423423
424424pub fn extend_prev_char(cx: &mut Context) {
425− _find_char(
425+ find_char_impl(
426426 cx,
427427 search::find_nth_prev,
428428 true, /* inclusive */
@@ -669,7 +669,7 @@ pub fn split_selection_on_newline(cx: &mut Context) {
669669// I'd probably collect all the matches right now and store the current index. The cache needs
670670// wiping if input happens.
671671
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) {
673673 let text = doc.text();
674674 let selection = doc.selection(view.id);
675675 let start = text.char_to_byte(selection.cursor());
@@ -715,8 +715,7 @@ pub fn search(cx: &mut Context) {
715715
716716 let view_id = view.id;
717717 let prompt = ui::regex_prompt(cx, "search:".to_string(), move |view, doc, regex| {
718− _search(doc, view, &contents, &regex, false);
719−
718+ search_impl(doc, view, &contents, &regex, false);
720719 // TODO: only store on enter (accept), not update
721720 register::set('\\', vec![regex.as_str().to_string()]);
722721 });
@@ -725,22 +724,22 @@ pub fn search(cx: &mut Context) {
725724}
726725// can't search next for ""compose"" for some reason
727726
728−pub fn _search_next(cx: &mut Context, extend: bool) {
727+pub fn search_next_impl(cx: &mut Context, extend: bool) {
729728 if let Some(query) = register::get('\\') {
730729 let query = query.first().unwrap();
731730 let (view, doc) = cx.current();
732731 let contents = doc.text().slice(..).to_string();
733732 let regex = Regex::new(query).unwrap();
734− _search(doc, view, &contents, &regex, extend);
733+ search_impl(doc, view, &contents, &regex, extend);
735734 }
736735}
737736
738737pub fn search_next(cx: &mut Context) {
739− _search_next(cx, false);
738+ search_next_impl(cx, false);
740739}
741740
742741pub fn extend_search_next(cx: &mut Context) {
743− _search_next(cx, true);
742+ search_next_impl(cx, true);
744743}
745744
746745pub fn search_selection(cx: &mut Context) {
@@ -795,7 +794,7 @@ pub fn extend_line(cx: &mut Context) {
795794
796795// heuristic: append changes to history after each command, unless we're in insert mode
797796
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) {
799798 // first yank the selection
800799 let values: Vec<String> = doc
801800 .selection(view_id)
@@ -818,7 +817,7 @@ fn _delete_selection(reg: char, doc: &mut Document, view_id: ViewId) {
818817pub fn delete_selection(cx: &mut Context) {
819818 let reg = cx.register.name();
820819 let (view, doc) = cx.current();
821− _delete_selection(reg, doc, view.id);
820+ delete_selection_impl(reg, doc, view.id);
822821
823822 doc.append_changes_to_history(view.id);
824823
@@ -829,7 +828,7 @@ pub fn delete_selection(cx: &mut Context) {
829828pub fn change_selection(cx: &mut Context) {
830829 let reg = cx.register.name();
831830 let (view, doc) = cx.current();
832− _delete_selection(reg, doc, view.id);
831+ delete_selection_impl(reg, doc, view.id);
833832 enter_insert_mode(doc);
834833}
835834
@@ -912,7 +911,7 @@ mod cmd {
912911
913912 fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
914913 // 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) {
916915 return;
917916 }
918917 editor.close(editor.view().id, /* close_buffer */ false);
@@ -934,7 +933,7 @@ mod cmd {
934933 };
935934 }
936935
937− fn _write<P: AsRef<Path>>(
936+ fn write_impl<P: AsRef<Path>>(
938937 view: &View,
939938 doc: &mut Document,
940939 path: Option<P>,
@@ -962,7 +961,7 @@ mod cmd {
962961
963962 fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
964963 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()) {
966965 editor.set_error(e.to_string());
967966 };
968967 }
@@ -1039,7 +1038,7 @@ mod cmd {
10391038
10401039 fn write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
10411040 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()) {
10431042 editor.set_error(e.to_string());
10441043 return;
10451044 };
@@ -1053,7 +1052,7 @@ mod cmd {
10531052
10541053 /// Returns `true` if there are modified buffers remaining and sets editor error,
10551054 /// otherwise returns `false`
1056− fn _buffers_remaining(editor: &mut Editor) -> bool {
1055+ fn buffers_remaining_impl(editor: &mut Editor) -> bool {
10571056 let modified: Vec<_> = editor
10581057 .documents()
10591058 .filter(|doc| doc.is_modified())
@@ -1076,7 +1075,13 @@ mod cmd {
10761075 }
10771076 }
10781077
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+ ) {
10801085 let mut errors = String::new();
10811086
10821087 // save all documents
@@ -1090,7 +1095,7 @@ mod cmd {
10901095 editor.set_error(errors);
10911096
10921097 if quit {
1093− if !force && _buffers_remaining(editor) {
1098+ if !force && buffers_remaining_impl(editor) {
10941099 return;
10951100 }
10961101
@@ -1103,19 +1108,19 @@ mod cmd {
11031108 }
11041109
11051110 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)
11071112 }
11081113
11091114 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)
11111116 }
11121117
11131118 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)
11151120 }
11161121
1117− fn _quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
1118− if !force && _buffers_remaining(editor) {
1122+ fn quit_all_impl(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
1123+ if !force && buffers_remaining_impl(editor) {
11191124 return;
11201125 }
11211126
@@ -1127,11 +1132,11 @@ mod cmd {
11271132 }
11281133
11291134 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)
11311136 }
11321137
11331138 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)
11351140 }
11361141
11371142 pub const COMMAND_LIST: &[Command] = &[
@@ -1578,7 +1583,7 @@ fn switch_to_last_accessed_file(cx: &mut Context) {
15781583}
15791584
15801585pub fn goto_mode(cx: &mut Context) {
1581− if let Some(count) = cx._count {
1586+ if let Some(count) = cx.count {
15821587 push_jump(cx.editor);
15831588
15841589 let (view, doc) = cx.current();
@@ -1646,7 +1651,7 @@ pub fn exit_select_mode(cx: &mut Context) {
16461651 cx.doc().mode = Mode::Normal;
16471652}
16481653
1649−fn _goto(
1654+fn goto_impl(
16501655 editor: &mut Editor,
16511656 compositor: &mut Compositor,
16521657 locations: Vec<lsp::Location>,
@@ -1734,7 +1739,7 @@ pub fn goto_definition(cx: &mut Context) {
17341739 None => Vec::new(),
17351740 };
17361741
1737− _goto(editor, compositor, items, offset_encoding);
1742+ goto_impl(editor, compositor, items, offset_encoding);
17381743 },
17391744 );
17401745}
@@ -1771,7 +1776,7 @@ pub fn goto_type_definition(cx: &mut Context) {
17711776 None => Vec::new(),
17721777 };
17731778
1774− _goto(editor, compositor, items, offset_encoding);
1779+ goto_impl(editor, compositor, items, offset_encoding);
17751780 },
17761781 );
17771782}
@@ -1808,7 +1813,7 @@ pub fn goto_implementation(cx: &mut Context) {
18081813 None => Vec::new(),
18091814 };
18101815
1811− _goto(editor, compositor, items, offset_encoding);
1816+ goto_impl(editor, compositor, items, offset_encoding);
18121817 },
18131818 );
18141819}
@@ -1832,7 +1837,7 @@ pub fn goto_reference(cx: &mut Context) {
18321837 move |editor: &mut Editor,
18331838 compositor: &mut Compositor,
18341839 items: Option<Vec<lsp::Location>>| {
1835− _goto(
1840+ goto_impl(
18361841 editor,
18371842 compositor,
18381843 items.unwrap_or_default(),
@@ -2236,7 +2241,7 @@ enum Paste {
22362241 After,
22372242}
22382243
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> {
22402245 if let Some(values) = register::get(reg) {
22412246 let repeat = std::iter::repeat(
22422247 values
@@ -2305,7 +2310,7 @@ pub fn paste_after(cx: &mut Context) {
23052310 let reg = cx.register.name();
23062311 let (view, doc) = cx.current();
23072312
2308− if let Some(transaction) = _paste(reg, doc, view, Paste::After) {
2313+ if let Some(transaction) = paste_impl(reg, doc, view, Paste::After) {
23092314 doc.apply(&transaction, view.id);
23102315 doc.append_changes_to_history(view.id);
23112316 }
@@ -2315,7 +2320,7 @@ pub fn paste_before(cx: &mut Context) {
23152320 let reg = cx.register.name();
23162321 let (view, doc) = cx.current();
23172322
2318− if let Some(transaction) = _paste(reg, doc, view, Paste::Before) {
2323+ if let Some(transaction) = paste_impl(reg, doc, view, Paste::Before) {
23192324 doc.apply(&transaction, view.id);
23202325 doc.append_changes_to_history(view.id);
23212326 }
helix-term/src/ui/editor.rs+2−2
@@ -564,7 +564,7 @@ impl EditorView {
564564 }
565565 _ => {
566566 // set the count
567− cxt._count = cxt.editor.count.take();
567+ cxt.count = cxt.editor.count.take();
568568 // TODO: edge case: 0j -> reset to 1
569569 // if this fails, count was Some(0)
570570 // debug_assert!(cxt.count != 0);
@@ -612,7 +612,7 @@ impl Component for EditorView {
612612 let mut cxt = commands::Context {
613613 register: helix_view::RegisterSelection::default(),
614614 editor: &mut cx.editor,
615− _count: None,
615+ count: None,
616616 callback: None,
617617 on_next_key_callback: None,
618618 callbacks: cx.callbacks,