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 some functions #281

Merged
merged 10 commits into from Aug 13, 2017
Copy path View file
@@ -10,16 +10,27 @@ use threads::ThreadState;
use remacs_macros::lisp_fn;
pub const BEG: ptrdiff_t = 1;
pub const BEG_BYTE: ptrdiff_t = 1;
pub type LispBufferRef = ExternalPtr<Lisp_Buffer>;
impl LispBufferRef {
#[inline]
pub fn zv(&self) -> ptrdiff_t {
self.zv
}
#[inline]
pub fn beg_addr(&self) -> *mut c_uchar {
unsafe { (*self.text).beg }
}
#[inline]
pub fn beg(&self) -> ptrdiff_t {
BEG
}
#[inline]
pub fn beg_byte(&self) -> ptrdiff_t {
BEG_BYTE
@@ -55,6 +66,11 @@ impl LispBufferRef {
unsafe { (*self.text).z_byte }
}
#[inline]
pub fn z(&self) -> ptrdiff_t {
unsafe { (*self.text).z }
}
// Check if buffer is live
#[inline]
pub fn is_live(self) -> bool {
Copy path View file
@@ -0,0 +1,43 @@
//! Lisp functions pertaining to editing.
use remacs_macros::lisp_fn;
use lisp::LispObject;
use remacs_sys::EmacsInt;
use threads::ThreadState;
use buffers::get_buffer;
/// Return value of point, as an integer.
/// Beginning of buffer is position (point-min).
#[lisp_fn]
pub fn point() -> LispObject {
let buffer_ref = ThreadState::current_buffer();
LispObject::from_natnum(buffer_ref.pt as EmacsInt)
}
/// Return the number of characters in the current buffer.
/// If BUFFER is not nil, return the number of characters in that buffer
/// instead.
///
/// This does not take narrowing into account; to count the number of
/// characters in the accessible portion of the current buffer, use
/// `(- (point-max) (point-min))', and to count the number of characters
/// in some other BUFFER, use
/// `(with-current-buffer BUFFER (- (point-max) (point-min)))'.
#[lisp_fn(min = "0")]
pub fn buffer_size(object: LispObject) -> LispObject {
let buffer_ref = if object.is_not_nil() {
get_buffer(object).as_buffer_or_error()
} else {
ThreadState::current_buffer()
};
LispObject::from_natnum((buffer_ref.z() - buffer_ref.beg()) as EmacsInt)
}
/// Return t if point is at the end of the buffer.
/// If the buffer is narrowed, this means the end of the narrowed part.
#[lisp_fn]
pub fn eobp() -> LispObject {
let buffer_ref = ThreadState::current_buffer();
LispObject::from_bool(buffer_ref.zv() == buffer_ref.pt)
}
Copy path View file
@@ -50,6 +50,7 @@ mod threads;
mod chartable;
mod category;
mod obarray;
mod editfns;
#[cfg(all(not(test), target_os = "macos"))]
use alloc_unexecmacosx::OsxUnexecAlloc;
@@ -79,6 +80,7 @@ pub use math::Fquo;
pub use math::Flss;
pub use math::Fleq;
pub use math::arithcompare;
pub use editfns::Feobp;
// Widely used in the C codebase.
pub use lists::Fsetcar;
@@ -128,6 +130,9 @@ pub use obarray::intern_1;
pub use obarray::Fintern;
pub use obarray::Fintern_soft;
// Used in fileio.c
pub use editfns::Fpoint;
// used in chartab.c
pub use chartable::Fset_char_table_parent;
@@ -301,5 +306,8 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*floatfns::Sfloor);
defsubr(&*floatfns::Sround);
defsubr(&*floatfns::Struncate);
defsubr(&*editfns::Spoint);
defsubr(&*editfns::Sbuffer_size);
defsubr(&*editfns::Seobp);
}
}
Copy path View file
@@ -363,16 +363,6 @@ DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
return val;
}
DEFUN ("point", Fpoint, Spoint, 0, 0, 0,
doc: /* Return value of point, as an integer.
Beginning of buffer is position (point-min). */)
(void)
{
Lisp_Object temp;
XSETFASTINT (temp, PT);
return temp;
}
DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
doc: /* Return value of point, as a marker object. */)
(void)
@@ -1055,28 +1045,6 @@ usage: (save-current-buffer &rest BODY) */)
return unbind_to (count, Fprogn (args));
}
DEFUN ("buffer-size", Fbuffer_size, Sbuffer_size, 0, 1, 0,
doc: /* Return the number of characters in the current buffer.
If BUFFER is not nil, return the number of characters in that buffer
instead.
This does not take narrowing into account; to count the number of
characters in the accessible portion of the current buffer, use
`(- (point-max) (point-min))', and to count the number of characters
in some other BUFFER, use
`(with-current-buffer BUFFER (- (point-max) (point-min)))'. */)
(Lisp_Object buffer)
{
if (NILP (buffer))
return make_number (Z - BEG);
else
{
CHECK_BUFFER (buffer);
return make_number (BUF_Z (XBUFFER (buffer))
- BUF_BEG (XBUFFER (buffer)));
}
}
DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 0, 0,
doc: /* Return the minimum permissible value of point in the current buffer.
This is 1, unless narrowing (a buffer restriction) is in effect. */)
@@ -1209,16 +1177,6 @@ If the buffer is narrowed, this means the beginning of the narrowed part. */)
return Qnil;
}
DEFUN ("eobp", Feobp, Seobp, 0, 0, 0,
doc: /* Return t if point is at the end of the buffer.
If the buffer is narrowed, this means the end of the narrowed part. */)
(void)
{
if (PT == ZV)
return Qt;
return Qnil;
}
DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0,
doc: /* Return t if point is at the beginning of a line. */)
(void)
@@ -5430,7 +5388,6 @@ functions if all the text being accessed has this property. */);
defsubr (&Spoint_marker);
defsubr (&Smark_marker);
defsubr (&Spoint);
defsubr (&Sregion_beginning);
defsubr (&Sregion_end);
@@ -5453,7 +5410,6 @@ functions if all the text being accessed has this property. */);
defsubr (&Ssave_excursion);
defsubr (&Ssave_current_buffer);
defsubr (&Sbuffer_size);
defsubr (&Spoint_max);
defsubr (&Spoint_min);
defsubr (&Spoint_min_marker);
@@ -5464,7 +5420,6 @@ functions if all the text being accessed has this property. */);
defsubr (&Sbyte_to_position);
defsubr (&Sbobp);
defsubr (&Seobp);
defsubr (&Sbolp);
defsubr (&Seolp);
defsubr (&Sfollowing_char);
ProTip! Use n and p to navigate between commits in a pull request.