Skip to content
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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions rust_src/remacs-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions rust_src/src/interactive.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
5 changes: 5 additions & 0 deletions rust_src/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions src/callint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}