mirror of https://github.com/helix-editor/helix
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.pull/270/head
parent
eb77de6a51
commit
6fb2d2679d
|
@ -40,7 +40,7 @@ use once_cell::sync::Lazy;
|
||||||
|
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
pub register: helix_view::RegisterSelection,
|
pub register: helix_view::RegisterSelection,
|
||||||
pub _count: Option<std::num::NonZeroUsize>,
|
pub count: Option<std::num::NonZeroUsize>,
|
||||||
pub editor: &'a mut Editor,
|
pub editor: &'a mut Editor,
|
||||||
|
|
||||||
pub callback: Option<crate::compositor::Callback>,
|
pub callback: Option<crate::compositor::Callback>,
|
||||||
|
@ -103,7 +103,7 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn count(&self) -> usize {
|
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]
|
#[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
|
where
|
||||||
// TODO: make an options struct for and abstract this Fn into a searcher type
|
// TODO: make an options struct for and abstract this Fn into a searcher type
|
||||||
// use the definition for w/b/e too
|
// use the definition for w/b/e too
|
||||||
|
@ -359,7 +359,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_till_char(cx: &mut Context) {
|
pub fn find_till_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_next,
|
search::find_nth_next,
|
||||||
false, /* inclusive */
|
false, /* inclusive */
|
||||||
|
@ -368,7 +368,7 @@ pub fn find_till_char(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_next_char(cx: &mut Context) {
|
pub fn find_next_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_next,
|
search::find_nth_next,
|
||||||
true, /* inclusive */
|
true, /* inclusive */
|
||||||
|
@ -377,7 +377,7 @@ pub fn find_next_char(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend_till_char(cx: &mut Context) {
|
pub fn extend_till_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_next,
|
search::find_nth_next,
|
||||||
false, /* inclusive */
|
false, /* inclusive */
|
||||||
|
@ -386,7 +386,7 @@ pub fn extend_till_char(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend_next_char(cx: &mut Context) {
|
pub fn extend_next_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_next,
|
search::find_nth_next,
|
||||||
true, /* inclusive */
|
true, /* inclusive */
|
||||||
|
@ -395,7 +395,7 @@ pub fn extend_next_char(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn till_prev_char(cx: &mut Context) {
|
pub fn till_prev_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_prev,
|
search::find_nth_prev,
|
||||||
false, /* inclusive */
|
false, /* inclusive */
|
||||||
|
@ -404,7 +404,7 @@ pub fn till_prev_char(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_prev_char(cx: &mut Context) {
|
pub fn find_prev_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_prev,
|
search::find_nth_prev,
|
||||||
true, /* inclusive */
|
true, /* inclusive */
|
||||||
|
@ -413,7 +413,7 @@ pub fn find_prev_char(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend_till_prev_char(cx: &mut Context) {
|
pub fn extend_till_prev_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_prev,
|
search::find_nth_prev,
|
||||||
false, /* inclusive */
|
false, /* inclusive */
|
||||||
|
@ -422,7 +422,7 @@ pub fn extend_till_prev_char(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend_prev_char(cx: &mut Context) {
|
pub fn extend_prev_char(cx: &mut Context) {
|
||||||
_find_char(
|
find_char_impl(
|
||||||
cx,
|
cx,
|
||||||
search::find_nth_prev,
|
search::find_nth_prev,
|
||||||
true, /* inclusive */
|
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
|
// I'd probably collect all the matches right now and store the current index. The cache needs
|
||||||
// wiping if input happens.
|
// 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 text = doc.text();
|
||||||
let selection = doc.selection(view.id);
|
let selection = doc.selection(view.id);
|
||||||
let start = text.char_to_byte(selection.cursor());
|
let start = text.char_to_byte(selection.cursor());
|
||||||
|
@ -715,8 +715,7 @@ pub fn search(cx: &mut Context) {
|
||||||
|
|
||||||
let view_id = view.id;
|
let view_id = view.id;
|
||||||
let prompt = ui::regex_prompt(cx, "search:".to_string(), move |view, doc, regex| {
|
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
|
// TODO: only store on enter (accept), not update
|
||||||
register::set('\\', vec![regex.as_str().to_string()]);
|
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
|
// 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('\\') {
|
if let Some(query) = register::get('\\') {
|
||||||
let query = query.first().unwrap();
|
let query = query.first().unwrap();
|
||||||
let (view, doc) = cx.current();
|
let (view, doc) = cx.current();
|
||||||
let contents = doc.text().slice(..).to_string();
|
let contents = doc.text().slice(..).to_string();
|
||||||
let regex = Regex::new(query).unwrap();
|
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) {
|
pub fn search_next(cx: &mut Context) {
|
||||||
_search_next(cx, false);
|
search_next_impl(cx, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend_search_next(cx: &mut Context) {
|
pub fn extend_search_next(cx: &mut Context) {
|
||||||
_search_next(cx, true);
|
search_next_impl(cx, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search_selection(cx: &mut Context) {
|
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
|
// 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
|
// first yank the selection
|
||||||
let values: Vec<String> = doc
|
let values: Vec<String> = doc
|
||||||
.selection(view_id)
|
.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) {
|
pub fn delete_selection(cx: &mut Context) {
|
||||||
let reg = cx.register.name();
|
let reg = cx.register.name();
|
||||||
let (view, doc) = cx.current();
|
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);
|
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) {
|
pub fn change_selection(cx: &mut Context) {
|
||||||
let reg = cx.register.name();
|
let reg = cx.register.name();
|
||||||
let (view, doc) = cx.current();
|
let (view, doc) = cx.current();
|
||||||
_delete_selection(reg, doc, view.id);
|
delete_selection_impl(reg, doc, view.id);
|
||||||
enter_insert_mode(doc);
|
enter_insert_mode(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -912,7 +911,7 @@ mod cmd {
|
||||||
|
|
||||||
fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
||||||
// last view and we have unsaved changes
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
editor.close(editor.view().id, /* close_buffer */ false);
|
editor.close(editor.view().id, /* close_buffer */ false);
|
||||||
|
@ -934,7 +933,7 @@ mod cmd {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _write<P: AsRef<Path>>(
|
fn write_impl<P: AsRef<Path>>(
|
||||||
view: &View,
|
view: &View,
|
||||||
doc: &mut Document,
|
doc: &mut Document,
|
||||||
path: Option<P>,
|
path: Option<P>,
|
||||||
|
@ -962,7 +961,7 @@ mod cmd {
|
||||||
|
|
||||||
fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
||||||
let (view, doc) = editor.current();
|
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());
|
editor.set_error(e.to_string());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1039,7 +1038,7 @@ mod cmd {
|
||||||
|
|
||||||
fn write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
fn write_quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
||||||
let (view, doc) = editor.current();
|
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());
|
editor.set_error(e.to_string());
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -1053,7 +1052,7 @@ mod cmd {
|
||||||
|
|
||||||
/// Returns `true` if there are modified buffers remaining and sets editor error,
|
/// Returns `true` if there are modified buffers remaining and sets editor error,
|
||||||
/// otherwise returns `false`
|
/// otherwise returns `false`
|
||||||
fn _buffers_remaining(editor: &mut Editor) -> bool {
|
fn buffers_remaining_impl(editor: &mut Editor) -> bool {
|
||||||
let modified: Vec<_> = editor
|
let modified: Vec<_> = editor
|
||||||
.documents()
|
.documents()
|
||||||
.filter(|doc| doc.is_modified())
|
.filter(|doc| doc.is_modified())
|
||||||
|
@ -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();
|
let mut errors = String::new();
|
||||||
|
|
||||||
// save all documents
|
// save all documents
|
||||||
|
@ -1090,7 +1095,7 @@ mod cmd {
|
||||||
editor.set_error(errors);
|
editor.set_error(errors);
|
||||||
|
|
||||||
if quit {
|
if quit {
|
||||||
if !force && _buffers_remaining(editor) {
|
if !force && buffers_remaining_impl(editor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,19 +1108,19 @@ mod cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
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) {
|
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) {
|
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) {
|
fn quit_all_impl(editor: &mut Editor, args: &[&str], event: PromptEvent, force: bool) {
|
||||||
if !force && _buffers_remaining(editor) {
|
if !force && buffers_remaining_impl(editor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,11 +1132,11 @@ mod cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quit_all(editor: &mut Editor, args: &[&str], event: PromptEvent) {
|
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) {
|
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] = &[
|
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) {
|
pub fn goto_mode(cx: &mut Context) {
|
||||||
if let Some(count) = cx._count {
|
if let Some(count) = cx.count {
|
||||||
push_jump(cx.editor);
|
push_jump(cx.editor);
|
||||||
|
|
||||||
let (view, doc) = cx.current();
|
let (view, doc) = cx.current();
|
||||||
|
@ -1646,7 +1651,7 @@ pub fn exit_select_mode(cx: &mut Context) {
|
||||||
cx.doc().mode = Mode::Normal;
|
cx.doc().mode = Mode::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _goto(
|
fn goto_impl(
|
||||||
editor: &mut Editor,
|
editor: &mut Editor,
|
||||||
compositor: &mut Compositor,
|
compositor: &mut Compositor,
|
||||||
locations: Vec<lsp::Location>,
|
locations: Vec<lsp::Location>,
|
||||||
|
@ -1734,7 +1739,7 @@ pub fn goto_definition(cx: &mut Context) {
|
||||||
None => Vec::new(),
|
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(),
|
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(),
|
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,
|
move |editor: &mut Editor,
|
||||||
compositor: &mut Compositor,
|
compositor: &mut Compositor,
|
||||||
items: Option<Vec<lsp::Location>>| {
|
items: Option<Vec<lsp::Location>>| {
|
||||||
_goto(
|
goto_impl(
|
||||||
editor,
|
editor,
|
||||||
compositor,
|
compositor,
|
||||||
items.unwrap_or_default(),
|
items.unwrap_or_default(),
|
||||||
|
@ -2236,7 +2241,7 @@ enum Paste {
|
||||||
After,
|
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) {
|
if let Some(values) = register::get(reg) {
|
||||||
let repeat = std::iter::repeat(
|
let repeat = std::iter::repeat(
|
||||||
values
|
values
|
||||||
|
@ -2305,7 +2310,7 @@ pub fn paste_after(cx: &mut Context) {
|
||||||
let reg = cx.register.name();
|
let reg = cx.register.name();
|
||||||
let (view, doc) = cx.current();
|
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.apply(&transaction, view.id);
|
||||||
doc.append_changes_to_history(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 reg = cx.register.name();
|
||||||
let (view, doc) = cx.current();
|
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.apply(&transaction, view.id);
|
||||||
doc.append_changes_to_history(view.id);
|
doc.append_changes_to_history(view.id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -564,7 +564,7 @@ impl EditorView {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// set the count
|
// set the count
|
||||||
cxt._count = cxt.editor.count.take();
|
cxt.count = cxt.editor.count.take();
|
||||||
// TODO: edge case: 0j -> reset to 1
|
// TODO: edge case: 0j -> reset to 1
|
||||||
// if this fails, count was Some(0)
|
// if this fails, count was Some(0)
|
||||||
// debug_assert!(cxt.count != 0);
|
// debug_assert!(cxt.count != 0);
|
||||||
|
@ -612,7 +612,7 @@ impl Component for EditorView {
|
||||||
let mut cxt = commands::Context {
|
let mut cxt = commands::Context {
|
||||||
register: helix_view::RegisterSelection::default(),
|
register: helix_view::RegisterSelection::default(),
|
||||||
editor: &mut cx.editor,
|
editor: &mut cx.editor,
|
||||||
_count: None,
|
count: None,
|
||||||
callback: None,
|
callback: None,
|
||||||
on_next_key_callback: None,
|
on_next_key_callback: None,
|
||||||
callbacks: cx.callbacks,
|
callbacks: cx.callbacks,
|
||||||
|
|
Loading…
Reference in New Issue