From 6fb2d2679dc63ca34be0d02efb543c3e0b49cb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Tue, 15 Jun 2021 00:29:03 -0400 Subject: [PATCH] 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. --- helix-term/src/commands.rs | 93 +++++++++++++++++++------------------ helix-term/src/ui/editor.rs | 4 +- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 10d5e2646..382137d16 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -40,7 +40,7 @@ pub struct Context<'a> { pub register: helix_view::RegisterSelection, - pub _count: Option, + pub count: Option, pub editor: &'a mut Editor, pub callback: Option, @@ -103,7 +103,7 @@ pub fn callback( #[inline] pub fn count(&self) -> usize { - self._count.map_or(1, |v| v.get()) + self.count.map_or(1, |v| v.get()) } } @@ -315,7 +315,7 @@ pub fn extend_next_word_end(cx: &mut Context) { } #[inline] -fn _find_char(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool) +fn find_char_impl(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool) where // TODO: make an options struct for and abstract this Fn into a searcher type // use the definition for w/b/e too @@ -359,7 +359,7 @@ fn _find_char(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool) } pub fn find_till_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_next, false, /* inclusive */ @@ -368,7 +368,7 @@ pub fn find_till_char(cx: &mut Context) { } pub fn find_next_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_next, true, /* inclusive */ @@ -377,7 +377,7 @@ pub fn find_next_char(cx: &mut Context) { } pub fn extend_till_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_next, false, /* inclusive */ @@ -386,7 +386,7 @@ pub fn extend_till_char(cx: &mut Context) { } pub fn extend_next_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_next, true, /* inclusive */ @@ -395,7 +395,7 @@ pub fn extend_next_char(cx: &mut Context) { } pub fn till_prev_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_prev, false, /* inclusive */ @@ -404,7 +404,7 @@ pub fn till_prev_char(cx: &mut Context) { } pub fn find_prev_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_prev, true, /* inclusive */ @@ -413,7 +413,7 @@ pub fn find_prev_char(cx: &mut Context) { } pub fn extend_till_prev_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_prev, false, /* inclusive */ @@ -422,7 +422,7 @@ pub fn extend_till_prev_char(cx: &mut Context) { } pub fn extend_prev_char(cx: &mut Context) { - _find_char( + find_char_impl( cx, search::find_nth_prev, true, /* inclusive */ @@ -669,7 +669,7 @@ pub fn split_selection_on_newline(cx: &mut Context) { // I'd probably collect all the matches right now and store the current index. The cache needs // wiping if input happens. -fn _search(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) { +fn search_impl(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) { let text = doc.text(); let selection = doc.selection(view.id); let start = text.char_to_byte(selection.cursor()); @@ -715,8 +715,7 @@ pub fn search(cx: &mut Context) { let view_id = view.id; let prompt = ui::regex_prompt(cx, "search:".to_string(), move |view, doc, regex| { - _search(doc, view, &contents, ®ex, false); - + search_impl(doc, view, &contents, ®ex, false); // TODO: only store on enter (accept), not update register::set('\\', vec![regex.as_str().to_string()]); }); @@ -725,22 +724,22 @@ pub fn search(cx: &mut Context) { } // can't search next for ""compose"" for some reason -pub fn _search_next(cx: &mut Context, extend: bool) { +pub fn search_next_impl(cx: &mut Context, extend: bool) { if let Some(query) = register::get('\\') { let query = query.first().unwrap(); let (view, doc) = cx.current(); let contents = doc.text().slice(..).to_string(); let regex = Regex::new(query).unwrap(); - _search(doc, view, &contents, ®ex, extend); + search_impl(doc, view, &contents, ®ex, extend); } } pub fn search_next(cx: &mut Context) { - _search_next(cx, false); + search_next_impl(cx, false); } pub fn extend_search_next(cx: &mut Context) { - _search_next(cx, true); + search_next_impl(cx, true); } pub fn search_selection(cx: &mut Context) { @@ -795,7 +794,7 @@ pub fn extend_line(cx: &mut Context) { // heuristic: append changes to history after each command, unless we're in insert mode -fn _delete_selection(reg: char, doc: &mut Document, view_id: ViewId) { +fn delete_selection_impl(reg: char, doc: &mut Document, view_id: ViewId) { // first yank the selection let values: Vec = doc .selection(view_id) @@ -818,7 +817,7 @@ fn _delete_selection(reg: char, doc: &mut Document, view_id: ViewId) { pub fn delete_selection(cx: &mut Context) { let reg = cx.register.name(); let (view, doc) = cx.current(); - _delete_selection(reg, doc, view.id); + delete_selection_impl(reg, doc, view.id); doc.append_changes_to_history(view.id); @@ -829,7 +828,7 @@ pub fn delete_selection(cx: &mut Context) { pub fn change_selection(cx: &mut Context) { let reg = cx.register.name(); let (view, doc) = cx.current(); - _delete_selection(reg, doc, view.id); + delete_selection_impl(reg, doc, view.id); enter_insert_mode(doc); } @@ -912,7 +911,7 @@ pub struct Command { fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) { // last view and we have unsaved changes - if editor.tree.views().count() == 1 && _buffers_remaining(editor) { + if editor.tree.views().count() == 1 && buffers_remaining_impl(editor) { return; } editor.close(editor.view().id, /* close_buffer */ false); @@ -934,7 +933,7 @@ fn open(editor: &mut Editor, args: &[&str], event: PromptEvent) { }; } - fn _write>( + fn write_impl>( view: &View, doc: &mut Document, path: Option

, @@ -962,7 +961,7 @@ fn _write>( fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) { let (view, doc) = editor.current(); - if let Err(e) = _write(view, doc, args.first()) { + if let Err(e) = write_impl(view, doc, args.first()) { editor.set_error(e.to_string()); }; } @@ -1039,7 +1038,7 @@ fn later(editor: &mut Editor, args: &[&str], event: PromptEvent) { fn write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) { let (view, doc) = editor.current(); - if let Err(e) = _write(view, doc, args.first()) { + if let Err(e) = write_impl(view, doc, args.first()) { editor.set_error(e.to_string()); return; }; @@ -1053,7 +1052,7 @@ fn force_write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) { /// Returns `true` if there are modified buffers remaining and sets editor error, /// otherwise returns `false` - fn _buffers_remaining(editor: &mut Editor) -> bool { + fn buffers_remaining_impl(editor: &mut Editor) -> bool { let modified: Vec<_> = editor .documents() .filter(|doc| doc.is_modified()) @@ -1076,7 +1075,13 @@ fn _buffers_remaining(editor: &mut Editor) -> bool { } } - fn _write_all(editor: &mut Editor, args: &[&str], event: PromptEvent, quit: bool, force: bool) { + fn write_all_impl( + editor: &mut Editor, + args: &[&str], + event: PromptEvent, + quit: bool, + force: bool, + ) { let mut errors = String::new(); // save all documents @@ -1090,7 +1095,7 @@ fn _write_all(editor: &mut Editor, args: &[&str], event: PromptEvent, quit: bool editor.set_error(errors); if quit { - if !force && _buffers_remaining(editor) { + if !force && buffers_remaining_impl(editor) { return; } @@ -1103,19 +1108,19 @@ fn _write_all(editor: &mut Editor, args: &[&str], event: PromptEvent, quit: bool } fn write_all(editor: &mut Editor, args: &[&str], event: PromptEvent) { - _write_all(editor, args, event, false, false) + write_all_impl(editor, args, event, false, false) } fn write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) { - _write_all(editor, args, event, true, false) + write_all_impl(editor, args, event, true, false) } fn force_write_all_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) { - _write_all(editor, args, event, true, true) + write_all_impl(editor, args, event, true, true) } - fn _quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) { - if !force && _buffers_remaining(editor) { + fn quit_all_impl(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) { + if !force && buffers_remaining_impl(editor) { return; } @@ -1127,11 +1132,11 @@ fn _quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool } fn quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) { - _quit_all(editor, args, event, false) + quit_all_impl(editor, args, event, false) } fn force_quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) { - _quit_all(editor, args, event, true) + quit_all_impl(editor, args, event, true) } pub const COMMAND_LIST: &[Command] = &[ @@ -1578,7 +1583,7 @@ fn switch_to_last_accessed_file(cx: &mut Context) { } pub fn goto_mode(cx: &mut Context) { - if let Some(count) = cx._count { + if let Some(count) = cx.count { push_jump(cx.editor); let (view, doc) = cx.current(); @@ -1646,7 +1651,7 @@ pub fn exit_select_mode(cx: &mut Context) { cx.doc().mode = Mode::Normal; } -fn _goto( +fn goto_impl( editor: &mut Editor, compositor: &mut Compositor, locations: Vec, @@ -1734,7 +1739,7 @@ pub fn goto_definition(cx: &mut Context) { None => Vec::new(), }; - _goto(editor, compositor, items, offset_encoding); + goto_impl(editor, compositor, items, offset_encoding); }, ); } @@ -1771,7 +1776,7 @@ pub fn goto_type_definition(cx: &mut Context) { None => Vec::new(), }; - _goto(editor, compositor, items, offset_encoding); + goto_impl(editor, compositor, items, offset_encoding); }, ); } @@ -1808,7 +1813,7 @@ pub fn goto_implementation(cx: &mut Context) { None => Vec::new(), }; - _goto(editor, compositor, items, offset_encoding); + goto_impl(editor, compositor, items, offset_encoding); }, ); } @@ -1832,7 +1837,7 @@ pub fn goto_reference(cx: &mut Context) { move |editor: &mut Editor, compositor: &mut Compositor, items: Option>| { - _goto( + goto_impl( editor, compositor, items.unwrap_or_default(), @@ -2236,7 +2241,7 @@ enum Paste { After, } -fn _paste(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option { +fn paste_impl(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option { if let Some(values) = register::get(reg) { let repeat = std::iter::repeat( values @@ -2305,7 +2310,7 @@ pub fn paste_after(cx: &mut Context) { let reg = cx.register.name(); let (view, doc) = cx.current(); - if let Some(transaction) = _paste(reg, doc, view, Paste::After) { + if let Some(transaction) = paste_impl(reg, doc, view, Paste::After) { doc.apply(&transaction, view.id); doc.append_changes_to_history(view.id); } @@ -2315,7 +2320,7 @@ pub fn paste_before(cx: &mut Context) { let reg = cx.register.name(); let (view, doc) = cx.current(); - if let Some(transaction) = _paste(reg, doc, view, Paste::Before) { + if let Some(transaction) = paste_impl(reg, doc, view, Paste::Before) { doc.apply(&transaction, view.id); doc.append_changes_to_history(view.id); } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 838684ba3..4b4b9fb26 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -564,7 +564,7 @@ fn command_mode(&self, mode: Mode, cxt: &mut commands::Context, event: KeyEvent) } _ => { // set the count - cxt._count = cxt.editor.count.take(); + cxt.count = cxt.editor.count.take(); // TODO: edge case: 0j -> reset to 1 // if this fails, count was Some(0) // debug_assert!(cxt.count != 0); @@ -612,7 +612,7 @@ fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult { let mut cxt = commands::Context { register: helix_view::RegisterSelection::default(), editor: &mut cx.editor, - _count: None, + count: None, callback: None, on_next_key_callback: None, callbacks: cx.callbacks,