helix/helix-core/src/lib.rs

94 lines
2.4 KiB
Rust
Raw Normal View History

2020-06-02 09:57:01 +08:00
#![allow(unused)]
pub mod auto_pairs;
pub mod comment;
pub mod diagnostic;
pub mod graphemes;
mod history;
2020-10-14 11:01:41 +08:00
pub mod indent;
pub mod macros;
pub mod match_brackets;
2021-03-18 12:39:34 +08:00
pub mod movement;
2021-02-22 14:50:41 +08:00
pub mod object;
2020-09-17 13:57:49 +08:00
mod position;
2020-10-06 15:00:23 +08:00
pub mod register;
pub mod search;
pub mod selection;
2021-05-30 16:52:46 +08:00
mod state;
2020-09-12 18:36:49 +08:00
pub mod syntax;
mod transaction;
2020-05-20 17:14:51 +08:00
pub(crate) fn find_first_non_whitespace_char2(line: RopeSlice) -> Option<usize> {
// find first non-whitespace char
2021-02-18 17:45:41 +08:00
for (start, ch) in line.chars().enumerate() {
// TODO: could use memchr with chunks?
if ch != ' ' && ch != '\t' && ch != '\n' {
return Some(start);
}
}
None
}
pub(crate) fn find_first_non_whitespace_char(text: RopeSlice, line_num: usize) -> Option<usize> {
let line = text.line(line_num);
let mut start = text.line_to_char(line_num);
// find first non-whitespace char
for ch in line.chars() {
// TODO: could use memchr with chunks?
if ch != ' ' && ch != '\t' && ch != '\n' {
return Some(start);
}
start += 1;
}
None
}
pub fn runtime_dir() -> std::path::PathBuf {
// runtime env var || dir where binary is located
std::env::var("HELIX_RUNTIME")
.map(|path| path.into())
.unwrap_or_else(|_| {
std::env::current_exe()
.ok()
.and_then(|path| path.parent().map(|path| path.to_path_buf()))
.unwrap()
})
}
pub fn config_dir() -> std::path::PathBuf {
// TODO: allow env var override
let strategy = choose_base_strategy().expect("Unable to find the config directory!");
let mut path = strategy.config_dir();
path.push("helix");
path
}
2021-06-03 00:19:56 +08:00
pub fn cache_dir() -> std::path::PathBuf {
// TODO: allow env var override
let strategy = choose_base_strategy().expect("Unable to find the config directory!");
let mut path = strategy.cache_dir();
path.push("helix");
path
}
use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
pub use ropey::{Rope, RopeSlice};
2020-09-29 00:00:35 +08:00
2020-05-28 13:45:44 +08:00
pub use tendril::StrTendril as Tendril;
#[doc(inline)]
pub use {regex, tree_sitter};
2021-03-18 12:39:34 +08:00
pub use position::{coords_at_pos, pos_at_coords, Position};
2021-03-22 11:40:07 +08:00
pub use selection::{Range, Selection};
2021-04-01 10:01:11 +08:00
pub use smallvec::SmallVec;
2020-09-17 13:57:49 +08:00
pub use syntax::Syntax;
pub use diagnostic::Diagnostic;
pub use history::History;
pub use state::State;
pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};