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 bolp and eolp to rust #293

Merged
merged 11 commits into from Sep 2, 2017
Copy path View file
@@ -43,6 +43,11 @@ impl LispBufferRef {
unsafe { (*self.text).gpt_byte }
}
#[inline]
pub fn gap_size(&self) -> ptrdiff_t {
unsafe { (*self.text).gap_size }
}
#[inline]
pub fn gap_end_addr(&self) -> *mut c_uchar {
unsafe {
@@ -93,6 +98,17 @@ impl LispBufferRef {
pub fn is_live(self) -> bool {
LispObject::from_raw(self.name).is_not_nil()
}
#[inline]
pub fn fetch_byte(&self, n: ptrdiff_t) -> u8 {
let offset = if n >= self.gpt_byte() {
self.gap_size()
} else {
0
};
unsafe { *(self.beg_addr().offset(offset + n - self.beg_byte())) as u8 }
}
}
impl LispObject {
Copy path View file
@@ -49,3 +49,22 @@ pub fn bobp() -> LispObject {
let buffer_ref = ThreadState::current_buffer();
LispObject::from_bool(buffer_ref.pt == buffer_ref.begv)
}
/// Return t if point is at the beginning of a line.
#[lisp_fn]
pub fn bolp() -> LispObject {
let buffer_ref = ThreadState::current_buffer();
LispObject::from_bool(
buffer_ref.pt == buffer_ref.begv || buffer_ref.fetch_byte(buffer_ref.pt_byte - 1) == b'\n',
)
}
/// Return t if point is at the end of a line.
///`End of a line' includes point being at the end of the buffer.
#[lisp_fn]
pub fn eolp() -> LispObject {
let buffer_ref = ThreadState::current_buffer();
LispObject::from_bool(
buffer_ref.pt == buffer_ref.zv() || buffer_ref.fetch_byte(buffer_ref.pt_byte) == b'\n',

This comment has been minimized.

@kidd

kidd Aug 20, 2017

Collaborator

cargo fmt told me about that final comma, but.... does it make sense? I find it a bit strange, no?

This comment has been minimized.

@Wilfred

Wilfred Aug 29, 2017

Owner

Agreed, it's a little odd. Perhaps it's a rustfmt bug.

I like that rustfmt is a tool that you just run and it fixes formatting without human input. We could file a bug upstream, but I'd leave the comma for now if rustfmt wants it.

This comment has been minimized.

@birkenfeld

birkenfeld Aug 30, 2017

Collaborator

I don't think it's a big, it's just consistent in always having a final comma on multi-line lists of expressions. The argument for having the trailing comma in the first place, less churn when an element is added, applies to single arguments as well.

)
}
Copy path View file
@@ -170,6 +170,8 @@ pub use multibyte::str_to_unibyte;
// Used in window.c, macros.c
pub use interactive::Fprefix_numeric_value;
pub use editfns::Fbolp;
pub use editfns::Feolp;
extern "C" {
fn defsubr(sname: *const Lisp_Subr);
@@ -329,5 +331,7 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*editfns::Sbuffer_size);
defsubr(&*editfns::Seobp);
defsubr(&*editfns::Sbobp);
defsubr(&*editfns::Sbolp);
defsubr(&*editfns::Seolp);
}
}
Copy path View file
@@ -1167,25 +1167,6 @@ At the beginning of the buffer or accessible region, return 0. */)
return temp;
}
DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0,
doc: /* Return t if point is at the beginning of a line. */)
(void)
{
if (PT == BEGV || FETCH_BYTE (PT_BYTE - 1) == '\n')
return Qt;
return Qnil;
}
DEFUN ("eolp", Feolp, Seolp, 0, 0, 0,
doc: /* Return t if point is at the end of a line.
`End of a line' includes point being at the end of the buffer. */)
(void)
{
if (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')
return Qt;
return Qnil;
}
DEFUN ("char-after", Fchar_after, Schar_after, 0, 1, 0,
doc: /* Return character in current buffer at position POS.
POS is an integer or a marker and defaults to point.
@@ -5409,8 +5390,6 @@ functions if all the text being accessed has this property. */);
defsubr (&Sposition_bytes);
defsubr (&Sbyte_to_position);
defsubr (&Sbolp);
defsubr (&Seolp);
defsubr (&Sfollowing_char);
defsubr (&Sprevious_char);
defsubr (&Schar_after);
ProTip! Use n and p to navigate between commits in a pull request.