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 edit fns #297

Merged
merged 7 commits into from Sep 15, 2017
Copy path View file
@@ -1313,6 +1313,7 @@ extern "C" {
pub static Qwindow_live_p: Lisp_Object;
pub static Qoverlayp: Lisp_Object;
pub static Qminus: Lisp_Object;
pub static Qmark_inactive: Lisp_Object;
pub static Qinteger: Lisp_Object;
pub static Qsymbol: Lisp_Object;
Copy path View file
@@ -96,6 +96,16 @@ impl LispBufferRef {
unsafe { (*self.text).chars_modiff }
}
#[inline]
pub fn mark_active(&self) -> LispObject {
LispObject::from_raw(self.mark_active)
}
#[inline]
pub fn mark(&self) -> LispObject {
LispObject::from_raw(self.mark)
}
#[inline]
pub fn name(&self) -> LispObject {
LispObject::from_raw(self.name)
Copy path View file
@@ -2,10 +2,11 @@
use remacs_macros::lisp_fn;
use lisp::LispObject;
use remacs_sys::EmacsInt;
use util::clip_to_bounds;
use remacs_sys::{EmacsInt, globals, Qmark_inactive};
use threads::ThreadState;
use buffers::get_buffer;
use marker::marker_position;
/// Return value of point, as an integer.
/// Beginning of buffer is position (point-min).
@@ -69,6 +70,53 @@ pub fn eolp() -> LispObject {
)
}
// Return the start or end position of the region.
// BEGINNINGP means return the start.
// If there is no region active, signal an error.
fn region_limit(beginningp: bool) -> LispObject {
let current_buf = ThreadState::current_buffer();
if LispObject::from_raw(unsafe { globals.f_Vtransient_mark_mode }).is_not_nil() &&
LispObject::from_raw(unsafe { globals.f_Vmark_even_if_inactive }).is_nil() &&
current_buf.mark_active().is_nil()
{
xsignal!(Qmark_inactive);
}
let m = marker_position(current_buf.mark());
if m.is_nil() {
error!("The mark is not set now, so there is no region");
}
let num = m.as_fixnum_or_error();
// Clip to the current narrowing (bug#11770)
if ((current_buf.pt as EmacsInt) < num) == beginningp {
LispObject::from_fixnum(current_buf.pt as EmacsInt)
} else {
LispObject::from_fixnum(clip_to_bounds(current_buf.begv, num, current_buf.zv) as
EmacsInt)
}
}
/// Return the integer value of point or mark, whichever is smaller.
#[lisp_fn]
fn region_beginning() -> LispObject {
region_limit(true)
}
/// Return the integer value of point or mark, whichever is larger.
#[lisp_fn]
fn region_end() -> LispObject {
region_limit(false)
}
/// Return this buffer's mark, as a marker object.
/// Watch out! Moving this marker changes the mark position.
/// If you set the marker not to point anywhere, the buffer will have no mark.
#[lisp_fn]
fn mark_marker() -> LispObject {
ThreadState::current_buffer().mark()
}
/// Return the minimum permissible value of point in the current
/// buffer. This is 1, unless narrowing (a buffer restriction) is in
/// effect.
Copy path View file
@@ -55,6 +55,7 @@ mod chartable;
mod category;
mod obarray;
mod editfns;
mod util;
mod minibuf;
mod fns;
@@ -70,6 +71,8 @@ use remacs_sys::Lisp_Subr;
pub use base64::base64_encode_1;
pub use base64::base64_decode_1;
pub use util::clip_to_bounds;
// Used in buffer.c
pub use buffers::Fbuffer_live_p;
pub use buffers::Fbuffer_modified_p;
@@ -353,6 +356,9 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*editfns::Sbobp);
defsubr(&*editfns::Sbolp);
defsubr(&*editfns::Seolp);
defsubr(&*editfns::Sregion_beginning);
defsubr(&*editfns::Sregion_end);
defsubr(&*editfns::Smark_marker);
defsubr(&*editfns::Spoint_min);
defsubr(&*editfns::Spoint_max);
defsubr(&*minibuf::Sminibufferp);
Copy path View file
@@ -0,0 +1,15 @@
//! Miscellaneous utility functions
use remacs_sys::EmacsInt;
#[no_mangle]
pub extern "C" fn clip_to_bounds(lower: isize, num: EmacsInt, upper: isize) -> isize {
let num = num as isize;
if num < lower {
lower
} else if num <= upper {
num
} else {
upper
}
}
Copy path View file
@@ -386,54 +386,6 @@ The return value is POSITION. */)
return position;
}
/* Return the start or end position of the region.
BEGINNINGP means return the start.
If there is no region active, signal an error. */
static Lisp_Object
region_limit (bool beginningp)
{
Lisp_Object m;
if (!NILP (Vtransient_mark_mode)
&& NILP (Vmark_even_if_inactive)
&& NILP (BVAR (current_buffer, mark_active)))
xsignal0 (Qmark_inactive);
m = Fmarker_position (BVAR (current_buffer, mark));
if (NILP (m))
error ("The mark is not set now, so there is no region");
/* Clip to the current narrowing (bug#11770). */
return make_number ((PT < XFASTINT (m)) == beginningp
? PT
: clip_to_bounds (BEGV, XFASTINT (m), ZV));
}
DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0,
doc: /* Return the integer value of point or mark, whichever is smaller. */)
(void)
{
return region_limit (1);
}
DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0,
doc: /* Return the integer value of point or mark, whichever is larger. */)
(void)
{
return region_limit (0);
}
DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0,
doc: /* Return this buffer's mark, as a marker object.
Watch out! Moving this marker changes the mark position.
If you set the marker not to point anywhere, the buffer will have no mark. */)
(void)
{
return BVAR (current_buffer, mark);
}
/* Find all the overlays in the current buffer that touch position POS.
Return the number found, and store them in a vector in VEC
@@ -5337,9 +5289,6 @@ functions if all the text being accessed has this property. */);
defsubr (&Sget_pos_property);
defsubr (&Spoint_marker);
defsubr (&Smark_marker);
defsubr (&Sregion_beginning);
defsubr (&Sregion_end);
/* Symbol for the text property used to mark fields. */
DEFSYM (Qfield, "field");
Copy path View file
@@ -1007,11 +1007,8 @@ INLINE bool
#define FIXNUM_OVERFLOW_P(i) \
(! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
INLINE ptrdiff_t
clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
{
return num < lower ? lower : num <= upper ? num : upper;
}

This comment has been minimized.

@Wilfred

Wilfred Aug 31, 2017

Owner

Please leave a function declaration here. This has added a new warning when compiling the C:

  CC       xdisp.o

xdisp.c: In function ‘init_iterator’:

xdisp.c:2821:9: warning: implicit declaration of function ‘clip_to_bounds’ [-Wimplicit-function-declaration]

         (-1, XINT (BVAR (current_buffer, selective_display)),

This comment has been minimized.

@shanavas786

shanavas786 Sep 5, 2017

Collaborator

thanks, updated

ptrdiff_t clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper);
/* Construct a Lisp_Object from a value or address. */
ProTip! Use n and p to navigate between commits in a pull request.