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
Port char-width #1151
Comments
I'd like to port this function. Presumably, I'll also need to port the function |
You can start by calling them both from C. https://github.com/emacs-mirror/emacs/blob/78ec68e18f07a90a9ad400683b973ff51baa80e1/src/indent.c#L60 All C functions can be imported from remacs_sys. |
Would anyone mind if I have a go at this? |
A simple port to Rust would call the C functions. Which is why this is labelled as a good first issue. A more interesting port would look at the C functions called and bring them along too. |
I'm looking at the C function Trying to delve into the C for a better understanding, but in the meantime I'll go for the simple port option and open a WIP PR. |
Defined around line 1818 of lisp.h. In general XFOO means "hard cast to FOO, do no checks". This is an exception. |
BTW, check out https://github.com/Wilfred/deadgrep I have it bound to C-c g. |
So my |
I guess by using |
I see from the most recent commit that If that's the case, is it an idiom that we could DRY somehow, either with a function or a macro? |
I think we shouldn't use into too much. You can return width as |
Probably it's ok if you use into when the return type is EmacsInt. But I don't like it when you can't see the resulting type. |
|
As for finding the |
We consider the |
These are all really good questions @NQNStudios. Thanks for taking the time. |
Is this fine? use crate::{
// ...
remacs_sys::{buffer_display_table, char_width, CHECK_CHARACTER},
};
/// Return width of CHAR when displayed in the current buffer.
/// The width is measured by how many columns it occupies on the screen.
/// Tab is taken to occupy `tab-width' columns.
#[lisp_fn(c_name = "char_width", name = "char-width")]
pub fn char_width_lisp(ch: LispObject) -> EmacsInt {
CHECK_CHARACTER(ch);
let c: usize = ch.into().unwrap();
let width = char_width(c, buffer_display_table());
width.into().unwrap()
} EDIT: this is NOT fine. |
@A6GibKm why is this not fine? would you like to elaborate? |
It compiles, but the results I got from the function are not accurate. |
@A6GibKm please post a PR, then we can comment on the code as you make progress. |
The text was updated successfully, but these errors were encountered: