Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k committed Jun 17, 2021
1 parent b3b6601 commit 4d5b117
Show file tree
Hide file tree
Showing 34 changed files with 1,764 additions and 594 deletions.
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@
[submodule "helix-syntax/languages/tree-sitter-nix"]
path = helix-syntax/languages/tree-sitter-nix
url = https://github.com/cstrahan/tree-sitter-nix
shallow = true
[submodule "helix-syntax/languages/tree-sitter-latex"]
path = helix-syntax/languages/tree-sitter-latex
url = https://github.com/latex-lsp/tree-sitter-latex
shallow = true
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
- [Configuration](./configuration.md)
- [Themes](./themes.md)
- [Keymap](./keymap.md)
- [Key Remapping](./remapping.md)
- [Hooks](./hooks.md)
1 change: 0 additions & 1 deletion book/src/configuration.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Configuration

To override global configuration parameters create a `config.toml` file located in your config directory (i.e `~/.config/helix/config.toml`).

7 changes: 5 additions & 2 deletions book/src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ We provide pre-built binaries on the [GitHub Releases page](https://github.com/h

## OSX

TODO: brew tap
A Homebrew tap is available:

Please use a pre-built binary release for the time being.
```
brew tap helix-editor/helix
brew install helix
```

## Linux

Expand Down
48 changes: 48 additions & 0 deletions book/src/remapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Key Remapping

One-way key remapping is temporarily supported via a simple TOML configuration
file. (More powerful solutions such as rebinding via commands will be
available in the feature).

To remap keys, write a `config.toml` file in your `helix` configuration
directory (default `~/.config/helix` in Linux systems) with a structure like
this:

```toml
# At most one section each of 'keys.normal', 'keys.insert' and 'keys.select'
[keys.normal]
a = "move_char_left" # Maps the 'a' key to the move_char_left command
w = "move_line_up" # Maps the 'w' key move_line_up
C-S-esc = "select_line" # Maps Control-Shift-Escape to select_line

[keys.insert]
A-x = "normal_mode" # Maps Alt-X to enter normal mode
```

Control, Shift and Alt modifiers are encoded respectively with the prefixes
`C-`, `S-` and `A-`. Special keys are encoded as follows:

* Backspace => "backspace"
* Space => "space"
* Return/Enter => "ret"
* < => "lt"
* > => "gt"
* + => "plus"
* - => "minus"
* ; => "semicolon"
* % => "percent"
* Left => "left"
* Right => "right"
* Up => "up"
* Home => "home"
* End => "end"
* Page Up => "pageup"
* Page Down => "pagedown"
* Tab => "tab"
* Back Tab => "backtab"
* Delete => "del"
* Insert => "ins"
* Null => "null"
* Escape => "esc"

Commands can be found in the source code at `../../helix-term/src/commands.rs`
1 change: 1 addition & 0 deletions contrib/themes/bogster.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

"ui.background" = { bg = "#161c23" }
"ui.linenr" = { fg = "#415367" }
"ui.linenr.selected" = { fg = "#e5ded6" } # TODO
"ui.statusline" = { bg = "#232d38" }
"ui.popup" = { bg = "#232d38" }
"ui.window" = { bg = "#232d38" }
Expand Down
1 change: 1 addition & 0 deletions contrib/themes/ingrid.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

"ui.background" = { bg = "#FFFCFD" }
"ui.linenr" = { fg = "#bbbbbb" }
"ui.linenr.selected" = { fg = "#F3EAE9" } # TODO
"ui.statusline" = { bg = "#F3EAE9" }
"ui.popup" = { bg = "#F3EAE9" }
"ui.window" = { bg = "#D8B8B3" }
Expand Down
1 change: 1 addition & 0 deletions contrib/themes/onedark.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ui.background" = { fg = "#ABB2BF", bg = "#282C34" }
"ui.help" = { bg = "#3E4452" }
"ui.linenr" = { fg = "#4B5263", modifiers = ['dim'] }
"ui.linenr.selected" = { fg = "#ABB2BF" }
"ui.popup" = { bg = "#3E4452" }
"ui.statusline" = { fg = "#ABB2BF", bg = "#2C323C" }
"ui.selection" = { bg = "#3E4452" }
Expand Down
77 changes: 60 additions & 17 deletions helix-core/src/register.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,63 @@
use crate::Tendril;
use once_cell::sync::Lazy;
use std::{collections::HashMap, sync::RwLock};

// TODO: could be an instance on Editor
static REGISTRY: Lazy<RwLock<HashMap<char, Vec<String>>>> =
Lazy::new(|| RwLock::new(HashMap::new()));

/// Read register values.
pub fn get(register_name: char) -> Option<Vec<String>> {
let registry = REGISTRY.read().unwrap();
registry.get(&register_name).cloned() // TODO: no cloning
use std::collections::HashMap;

#[derive(Debug)]
pub struct Register {
name: char,
values: Vec<String>,
}

impl Register {
pub fn new(name: char) -> Self {
Self {
name,
values: Vec::new(),
}
}

pub fn new_with_values(name: char, values: Vec<String>) -> Self {
Self { name, values }
}

pub fn name(&self) -> char {
self.name
}

pub fn read(&self) -> &Vec<String> {
&self.values
}

pub fn write(&mut self, values: Vec<String>) {
self.values = values;
}
}

/// Read register values.
// restoring: bool
pub fn set(register_name: char, values: Vec<String>) {
let mut registry = REGISTRY.write().unwrap();
registry.insert(register_name, values);
/// Currently just wraps a `HashMap` of `Register`s
#[derive(Debug, Default)]
pub struct Registers {
inner: HashMap<char, Register>,
}

impl Registers {
pub fn get(&self, name: char) -> Option<&Register> {
self.inner.get(&name)
}

pub fn get_mut(&mut self, name: char) -> Option<&mut Register> {
self.inner.get_mut(&name)
}

pub fn get_or_insert(&mut self, name: char) -> &mut Register {
self.inner
.entry(name)
.or_insert_with(|| Register::new(name))
}

pub fn write(&mut self, name: char, values: Vec<String>) {
self.inner
.insert(name, Register::new_with_values(name, values));
}

pub fn read(&self, name: char) -> Option<&Vec<String>> {
self.get(name).map(|reg| reg.read())
}
}
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-latex
Submodule tree-sitter-latex added at 7f7206
1 change: 1 addition & 0 deletions helix-syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ mk_langs!(
(Java, tree_sitter_java),
(Json, tree_sitter_json),
(Julia, tree_sitter_julia),
(Latex, tree_sitter_latex),
(Nix, tree_sitter_nix),
(Php, tree_sitter_php),
(Python, tree_sitter_python),
Expand Down
11 changes: 4 additions & 7 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use helix_core::syntax;
use helix_lsp::lsp;
use helix_view::{document::Mode, theme, Document, Editor, Theme, View};

use crate::{args::Args, compositor::Compositor, ui};
use crate::{args::Args, compositor::Compositor, config::Config, keymap::Keymaps, ui};

use log::{error, info};

Expand Down Expand Up @@ -37,10 +37,6 @@ pub type LspCallback =
pub type LspCallbacks = FuturesUnordered<LspCallback>;
pub type LspCallbackWrapper = Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Configuration {
pub theme: Option<String>,
}

pub struct Application {
compositor: Compositor,
Expand All @@ -52,7 +48,7 @@ pub struct Application {
}

impl Application {
pub fn new(mut args: Args) -> Result<Self, Error> {
pub fn new(mut args: Args, config: Config) -> Result<Self, Error> {
use helix_view::editor::Action;
let mut compositor = Compositor::new()?;
let size = compositor.size();
Expand Down Expand Up @@ -95,7 +91,8 @@ impl Application {

let mut editor = Editor::new(size, theme_loader.clone(), syn_loader.clone());

compositor.push(Box::new(ui::EditorView::new()));
let mut editor_view = Box::new(ui::EditorView::new(config.keymaps));
compositor.push(editor_view);

if !args.files.is_empty() {
let first = &args.files[0]; // we know it's not empty
Expand Down
Loading

0 comments on commit 4d5b117

Please sign in to comment.