Implement `:help topics` and document "Words vs. WORDS"

`:help topics` will open a fuzzy picker of files in
`runtime/help/topics` for non-command-related help topics.
pull/997/head
Omnikar 3 years ago
parent c108d565a1
commit 835d5152e5
No known key found for this signature in database
GPG Key ID: 7DE6694CDA7885ED

@ -2747,6 +2747,53 @@ pub mod cmd {
todo!() todo!()
} }
if args[0] == "topics" {
let dir_path = helix_core::runtime_dir().join("help/topics");
let entries: Vec<PathBuf> = std::fs::read_dir(dir_path)
.map(|entries| {
entries
.filter_map(|entry| {
let entry = entry.ok()?;
let path = entry.path();
Some(path)
})
.collect()
})
.unwrap_or_default();
let callback = Box::pin(async move {
let call: job::Callback =
Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
let picker = FilePicker::new(
entries,
|path| {
path.file_stem()
.and_then(|s| s.to_str())
.map(From::from)
.unwrap_or_default()
},
|editor, path, action| {
if let Err(e) = editor.open(path.clone(), action).and_then(|id| {
editor
.document_mut(id)
.unwrap()
.set_path(None)
.map_err(Into::into)
}) {
editor.set_error(e.to_string());
}
},
|_editor, path| Some((path.clone(), None)),
);
compositor.push(Box::new(picker));
});
Ok(call)
});
cx.jobs.callback(callback);
return Ok(());
}
let help_dir; let help_dir;
let command = { let command = {

@ -262,7 +262,7 @@ pub mod completers {
pub fn help(input: &str) -> Vec<Completion> { pub fn help(input: &str) -> Vec<Completion> {
let static_cmds_path = helix_core::runtime_dir().join("help/static-commands"); let static_cmds_path = helix_core::runtime_dir().join("help/static-commands");
let typable_cmds_path = helix_core::runtime_dir().join("help/typable-commands"); let typable_cmds_path = helix_core::runtime_dir().join("help/typable-commands");
let commands: Vec<String> = std::fs::read_dir(static_cmds_path) let mut items: Vec<String> = std::fs::read_dir(static_cmds_path)
.map(|entries| { .map(|entries| {
entries entries
.filter_map(|entry| { .filter_map(|entry| {
@ -288,10 +288,11 @@ pub mod completers {
.collect() .collect()
}) })
.unwrap_or_default(); .unwrap_or_default();
items.push("topics".to_owned());
let matcher = Matcher::default(); let matcher = Matcher::default();
let mut matches: Vec<_> = commands let mut matches: Vec<_> = items
.into_iter() .into_iter()
.map(Cow::from) .map(Cow::from)
.filter_map(|name| matcher.fuzzy_match(&name, input).map(|score| (name, score))) .filter_map(|name| matcher.fuzzy_match(&name, input).map(|score| (name, score)))

@ -0,0 +1,19 @@
Words vs. WORDS
Words and WORDS are two very similar types of text objects. A word
is a string of "word" characters, which include letters, numbers,
and underscores. A WORD, on the other hand, is any string of
non-whitespace characters.
In the example below, the words are underlined by 'w', and the
WORDS are underlined by 'W'.
This "stuff" is not-so difficult!
---------------------------------
wwww wwwww ww www ww wwwwwwwww
WWWW WWWWWWW WW WWWWWW WWWWWWWWWW
As is visible in the example, the words do not include any of the
non-alphanumeric punctuation, while the WORDS do include the
quotes, hyphen, and exclamation point. Also notice that 'not-so'
contains two words, but only one WORD.
Loading…
Cancel
Save