Skip to content

Commit

Permalink
Use _impl suffix instead of _ prefix
Browse files Browse the repository at this point in the history
Helpers / internal implementations where using the `_` prefix.
However, this prefix also suppress unused warnings.
I suggest we use the `_impl` suffix instead.
  • Loading branch information
CBenoit committed Jun 15, 2021
1 parent eb77de6 commit 6fb2d26
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
93 changes: 49 additions & 44 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use once_cell::sync::Lazy;

pub struct Context<'a> {
pub register: helix_view::RegisterSelection,
pub _count: Option<std::num::NonZeroUsize>,
pub count: Option<std::num::NonZeroUsize>,
pub editor: &'a mut Editor,

pub callback: Option<crate::compositor::Callback>,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<'a> Context<'a> {

#[inline]
pub fn count(&self) -> usize {
self._count.map_or(1, |v| v.get())
self.count.map_or(1, |v| v.get())
}
}

Expand Down Expand Up @@ -315,7 +315,7 @@ pub fn extend_next_word_end(cx: &mut Context) {
}

#[inline]
fn _find_char<F>(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool)
fn find_char_impl<F>(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
Expand Down Expand Up @@ -359,7 +359,7 @@ where
}

pub fn find_till_char(cx: &mut Context) {
_find_char(
find_char_impl(
cx,
search::find_nth_next,
false, /* inclusive */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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, &regex, false);

search_impl(doc, view, &contents, &regex, false);
// TODO: only store on enter (accept), not update
register::set('\\', vec![regex.as_str().to_string()]);
});
Expand All @@ -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, &regex, extend);
search_impl(doc, view, &contents, &regex, 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) {
Expand Down Expand Up @@ -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<String> = doc
.selection(view_id)
Expand All @@ -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);

Expand All @@ -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);
}

Expand Down Expand Up @@ -912,7 +911,7 @@ mod cmd {

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);
Expand All @@ -934,7 +933,7 @@ mod cmd {
};
}

fn _write<P: AsRef<Path>>(
fn write_impl<P: AsRef<Path>>(
view: &View,
doc: &mut Document,
path: Option<P>,
Expand Down Expand Up @@ -962,7 +961,7 @@ mod cmd {

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());
};
}
Expand Down Expand Up @@ -1039,7 +1038,7 @@ mod cmd {

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;
};
Expand All @@ -1053,7 +1052,7 @@ mod cmd {

/// 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())
Expand All @@ -1076,7 +1075,13 @@ mod cmd {
}
}

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
Expand All @@ -1090,7 +1095,7 @@ mod cmd {
editor.set_error(errors);

if quit {
if !force && _buffers_remaining(editor) {
if !force && buffers_remaining_impl(editor) {
return;
}

Expand All @@ -1103,19 +1108,19 @@ mod cmd {
}

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;
}

Expand All @@ -1127,11 +1132,11 @@ mod cmd {
}

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] = &[
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<lsp::Location>,
Expand Down Expand Up @@ -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);
},
);
}
Expand Down Expand Up @@ -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);
},
);
}
Expand Down Expand Up @@ -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);
},
);
}
Expand All @@ -1832,7 +1837,7 @@ pub fn goto_reference(cx: &mut Context) {
move |editor: &mut Editor,
compositor: &mut Compositor,
items: Option<Vec<lsp::Location>>| {
_goto(
goto_impl(
editor,
compositor,
items.unwrap_or_default(),
Expand Down Expand Up @@ -2236,7 +2241,7 @@ enum Paste {
After,
}

fn _paste(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option<Transaction> {
fn paste_impl(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option<Transaction> {
if let Some(values) = register::get(reg) {
let repeat = std::iter::repeat(
values
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ impl EditorView {
}
_ => {
// 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);
Expand Down Expand Up @@ -612,7 +612,7 @@ impl Component for EditorView {
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,
Expand Down

0 comments on commit 6fb2d26

Please sign in to comment.