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 prefix-numeric-value to rust #252

Merged
merged 1 commit into from Jul 19, 2017
Jump to file or symbol
Failed to load files and symbols.
+29 −24
Diff settings

Always

Just for now

Copy path View file
@@ -1017,6 +1017,7 @@ extern "C" {
pub static Qvectorp: Lisp_Object;
pub static Qsequencep: Lisp_Object;
pub static Qcharacterp: Lisp_Object;
pub static Qminus: Lisp_Object;
pub static Qinteger: Lisp_Object;
pub static Qsymbol: Lisp_Object;
Copy path View file
@@ -0,0 +1,23 @@
//! Call a Lisp function interactively.
use remacs_macros::lisp_fn;
use remacs_sys::Qminus;
use lisp::LispObject;
/// Return numeric meaning of raw prefix argument RAW.
/// A raw prefix argument is what you get from `(interactive "P")'.
/// Its numeric meaning is what you would get from `(interactive "p")'.
#[lisp_fn]
fn prefix_numeric_value(raw: LispObject) -> LispObject {
if raw.is_nil() {
LispObject::from_fixnum(1)
} else if raw.eq(LispObject::from_raw(unsafe { Qminus })) {
LispObject::from_fixnum(-1)
} else if raw.is_integer() {
raw
} else if let Some(number) = raw.as_cons().map_or(None, |v| v.car().as_fixnum()) {
LispObject::from_fixnum(number)
} else {
LispObject::from_fixnum(1)
}
}
Copy path View file
@@ -38,6 +38,7 @@ mod str2sig;
mod multibyte;
mod buffers;
mod windows;
mod interactive;
#[cfg(all(not(test), target_os = "macos"))]
use alloc_unexecmacosx::OsxUnexecAlloc;
@@ -130,6 +131,9 @@ pub use multibyte::str_to_multibyte;
pub use multibyte::str_as_unibyte;
pub use multibyte::str_to_unibyte;
// Used in window.c, macros.c
pub use interactive::Fprefix_numeric_value;
extern "C" {
fn defsubr(sname: *const Lisp_Subr);
}
@@ -234,6 +238,7 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*vectors::Svectorp);
defsubr(&*vectors::Slength);
defsubr(&*crypto::Sbuffer_hash);
defsubr(&*interactive::Sprefix_numeric_value);
defsubr(&*floatfns::Sisnan);
defsubr(&*floatfns::Sacos);
Copy path View file
@@ -848,29 +848,6 @@ invoke it. If KEYS is omitted or nil, the return value of
}
}
DEFUN ("prefix-numeric-value", Fprefix_numeric_value, Sprefix_numeric_value,
1, 1, 0,
doc: /* Return numeric meaning of raw prefix argument RAW.
A raw prefix argument is what you get from `(interactive "P")'.
Its numeric meaning is what you would get from `(interactive "p")'. */)
(Lisp_Object raw)
{
Lisp_Object val;
if (NILP (raw))
XSETFASTINT (val, 1);
else if (EQ (raw, Qminus))
XSETINT (val, -1);
else if (CONSP (raw) && INTEGERP (XCAR (raw)))
XSETINT (val, XINT (XCAR (raw)));
else if (INTEGERP (raw))
val = raw;
else
XSETFASTINT (val, 1);
return val;
}
void
syms_of_callint (void)
{
@@ -956,5 +933,4 @@ a way to turn themselves off when a mouse command switches windows. */);
defsubr (&Sinteractive);
defsubr (&Scall_interactively);
defsubr (&Sfuncall_interactively);
defsubr (&Sprefix_numeric_value);
}
ProTip! Use n and p to navigate between commits in a pull request.