Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Emacs respect string delimiter default #6

Conversation

gagbo
Copy link
Contributor

@gagbo gagbo commented Mar 18, 2024

Ref to original PR: eraserhd/parinfer-rust#142

@justinbarclay
Copy link
Owner

justinbarclay commented Mar 19, 2024

Can you run cargo check --features emacs? I've tried to build this branch, but I am getting a lot of errors.

I fixed up set_option to not error, but I kind of fumbled my way through a few parts just to get the errors to shut up for now.

fn set_option<'a>(
  options: &mut Options,
  option_name: Value<'a>,
  new_value: Value<'a>,
) -> Result<()> {
  let env = option_name.env;
  if option_name.eq(env.intern("partial-result")?) {
    options.partial_result = new_value.is_not_nil();
    return Ok(());
  }
  if option_name.eq(env.intern("force-balance")?) {
    options.force_balance = new_value.is_not_nil();
    return Ok(());
  }
  if option_name.eq(env.intern("return-parens")?) {
    options.return_parens = new_value.is_not_nil();
    return Ok(());
  }
  if option_name.eq(env.intern("comment-char")?) {
    let comment_char: String = new_value.into_rust()?;
    // Not sure if this is good behavior or not, to ignore the empty
    // string and use the default but right now it is just one less
    // error to deal with
    options.comment_char = comment_char.chars().next().unwrap_or_default();
    return Ok(());
  }
  if option_name.eq(env.intern("string-delimiters")?) {
    options.string_delimiters = new_value.into_rust::<Vector>()?
        .into_iter()
        .map(|x| x.into_rust())
        .collect::<Result<Vec<String>>>()?;
    return Ok(());
  }
  if option_name.eq(env.intern("lisp-vline-symbols")?) {
    options.lisp_vline_symbols = new_value.is_not_nil();
    return Ok(());
  }
  if option_name.eq(env.intern("lisp-block-comments")?) {
    options.lisp_block_comments = new_value.is_not_nil();
    return Ok(());
  }
  if option_name.eq(env.intern("guile-block-comments")?) {
    options.guile_block_comments = new_value.is_not_nil();
    return Ok(());
  }
  if option_name.eq(env.intern("scheme-sexp-comments")?) {
    options.scheme_sexp_comments = new_value.is_not_nil();
    return Ok(());
  }
  if option_name.eq(env.intern("julia-long-strings")?) {
    options.janet_long_strings = new_value.is_not_nil();
    return Ok(());
  }
  // I can't get this to work, it looks like you might need to upgrade the emacs crate 17+
  env.signal(unknown_option_error, option_name)
}

@justinbarclay
Copy link
Owner

On master I just added emacs to the default features in cargo so that cargo and rust-analyzer will pick them up.

@gagbo
Copy link
Contributor Author

gagbo commented Mar 20, 2024

Sure I'll try again, sorry about that, I wonder how so much stuff got outdated, I suppose there’s a new version of the emacs crate

gagbo added 4 commits March 20, 2024 21:17
Using the configuration `tab_spaces = 2` to minimize the impact on
formatting src/emacs_wrapper.rs
This is redone by using `saturating_add_signed` instead of having an
extra helper function. The function is stable since Rust 1.66
Upgrade to emacs crate 0.19

Fix all conversions to/from Lisp except the Vec<String> <-> Vector equivalence

Apparently one reference to env keeps escaping
@gagbo gagbo force-pushed the emacs_respect_string_delimiter_default branch from adb89df to 180acb8 Compare March 21, 2024 11:32
@gagbo
Copy link
Contributor Author

gagbo commented Mar 24, 2024

Should be fine now, ubolonton helped me with my last compilation issue

@justinbarclay justinbarclay merged commit a761135 into justinbarclay:master Mar 27, 2024
@justinbarclay
Copy link
Owner

Thanks for opening this PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants