Created
October 24, 2017 18:23
-
-
Save jaccarmac/18ffd145abc0a475c8a7b84390e9daf9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/rust_src/remacs-sys/lib.rs b/rust_src/remacs-sys/lib.rs | |
index 028044b82a..88baff0342 100755 | |
--- a/rust_src/remacs-sys/lib.rs | |
+++ b/rust_src/remacs-sys/lib.rs | |
@@ -1162,6 +1162,13 @@ extern "C" { | |
pub fn hash_remove_from_table(h: *mut Lisp_Hash_Table, key: Lisp_Object); | |
pub fn set_point_both(charpos: ptrdiff_t, bytepos: ptrdiff_t); | |
pub fn buf_charpos_to_bytepos(buffer: *const Lisp_Buffer, charpos: ptrdiff_t) -> ptrdiff_t; | |
+ | |
+ pub fn Finsert_char( | |
+ character: Lisp_Object, | |
+ count: Lisp_Object, | |
+ inherit: Lisp_Object, | |
+ ) -> Lisp_Object; | |
+ | |
pub fn wait_reading_process_output( | |
time_limit: intmax_t, | |
nsecs: c_int, | |
@@ -1177,6 +1184,7 @@ extern "C" { | |
pub fn timespec_sub(a: timespec, b: timespec) -> timespec; | |
pub fn timespec_add(a: timespec, b: timespec) -> timespec; | |
+ // textprop | |
pub fn Fadd_text_properties( | |
start: Lisp_Object, | |
end: Lisp_Object, | |
diff --git a/rust_src/src/editfns.rs b/rust_src/src/editfns.rs | |
index a81ecf507b..5511808a0f 100644 | |
--- a/rust_src/src/editfns.rs | |
+++ b/rust_src/src/editfns.rs | |
@@ -3,12 +3,14 @@ | |
use remacs_macros::lisp_fn; | |
use lisp::LispObject; | |
use util::clip_to_bounds; | |
-use remacs_sys::{buf_charpos_to_bytepos, globals, set_point_both, Fcons, Fcopy_sequence, | |
- Fadd_text_properties, EmacsInt, Qinteger_or_marker_p, Qmark_inactive, Qnil}; | |
+use remacs_sys::{buf_charpos_to_bytepos, globals, set_point_both, EmacsInt, Qinteger_or_marker_p, | |
+ Qmark_inactive, Finsert_char, Qnil, Fcons, Fadd_text_properties, Fcopy_sequence}; | |
use threads::ThreadState; | |
use buffers::get_buffer; | |
use marker::{marker_position, set_point_from_marker}; | |
-use libc::ptrdiff_t; | |
+use multibyte::raw_byte_codepoint; | |
+use libc::{c_uchar, ptrdiff_t}; | |
+ | |
/// Return value of point, as an integer. | |
/// Beginning of buffer is position (point-min). | |
@@ -154,6 +156,40 @@ pub fn goto_char(position: LispObject) -> LispObject { | |
position | |
} | |
+/// TODO: Write better docstring | |
+/// Insert COUNT (second arg) copies of BYTE (first arg). | |
+/// Both arguments are required. | |
+/// BYTE is a number of the range 0..255. | |
+/// | |
+/// If BYTE is 128..255 and the current buffer is multibyte, the | |
+/// corresponding eight-bit character is inserted. | |
+/// | |
+/// Point, and before-insertion markers, are relocated as in the function `insert'. | |
+/// The optional third arg INHERIT, if non-nil, says to inherit text properties | |
+/// from adjoining text, if those properties are sticky. | |
+#[lisp_fn(min = "2")] | |
+pub fn insert_byte(mut byte: LispObject, count: LispObject, inherit: LispObject) -> LispObject { | |
+ let b = byte.as_fixnum_or_error(); | |
+ if b < 0 || b > 255 { | |
+ args_out_of_range!( | |
+ byte, | |
+ LispObject::from_fixnum(0), | |
+ LispObject::from_fixnum(255) | |
+ ) | |
+ } | |
+ let buf = ThreadState::current_buffer(); | |
+ if b >= 128 && LispObject::from_raw(buf.enable_multibyte_characters).is_not_nil() { | |
+ byte = LispObject::from_natnum(raw_byte_codepoint(b as c_uchar) as EmacsInt); | |
+ } | |
+ unsafe { | |
+ LispObject::from_raw(Finsert_char( | |
+ byte.to_raw(), | |
+ count.to_raw(), | |
+ inherit.to_raw(), | |
+ )) | |
+ } | |
+} | |
+ | |
/// Return character in current buffer at position POS. | |
/// POS is an integer or a marker and defaults to point. | |
/// If POS is out of range, the value is nil. | |
diff --git a/rust_src/src/lib.rs b/rust_src/src/lib.rs | |
index e331702ff0..b4231578a0 100755 | |
--- a/rust_src/src/lib.rs | |
+++ b/rust_src/src/lib.rs | |
@@ -423,6 +423,7 @@ pub extern "C" fn rust_init_syms() { | |
defsubr(&*editfns::Spoint_min); | |
defsubr(&*editfns::Spoint_max); | |
defsubr(&*editfns::Sgoto_char); | |
+ defsubr(&*editfns::Sinsert_byte); | |
defsubr(&*editfns::Schar_after); | |
defsubr(&*editfns::Spropertize); | |
defsubr(&*fns::Sfeaturep); | |
diff --git a/src/editfns.c b/src/editfns.c | |
index c1174a98fa..c7cdd60b81 100644 | |
--- a/src/editfns.c | |
+++ b/src/editfns.c | |
@@ -2509,28 +2509,6 @@ called interactively, INHERIT is t. */) | |
return Qnil; | |
} | |
-DEFUN ("insert-byte", Finsert_byte, Sinsert_byte, 2, 3, 0, | |
- doc: /* Insert COUNT (second arg) copies of BYTE (first arg). | |
-Both arguments are required. | |
-BYTE is a number of the range 0..255. | |
- | |
-If BYTE is 128..255 and the current buffer is multibyte, the | |
-corresponding eight-bit character is inserted. | |
- | |
-Point, and before-insertion markers, are relocated as in the function `insert'. | |
-The optional third arg INHERIT, if non-nil, says to inherit text properties | |
-from adjoining text, if those properties are sticky. */) | |
- (Lisp_Object byte, Lisp_Object count, Lisp_Object inherit) | |
-{ | |
- CHECK_NUMBER (byte); | |
- if (XINT (byte) < 0 || XINT (byte) > 255) | |
- args_out_of_range_3 (byte, make_number (0), make_number (255)); | |
- if (XINT (byte) >= 128 | |
- && ! NILP (BVAR (current_buffer, enable_multibyte_characters))) | |
- XSETFASTINT (byte, BYTE8_TO_CHAR (XINT (byte))); | |
- return Finsert_char (byte, count, inherit); | |
-} | |
- | |
/* Making strings from buffer contents. */ | |
@@ -5243,7 +5221,6 @@ functions if all the text being accessed has this property. */); | |
defsubr (&Sinsert_and_inherit); | |
defsubr (&Sinsert_and_inherit_before_markers); | |
defsubr (&Sinsert_char); | |
- defsubr (&Sinsert_byte); | |
defsubr (&Suser_login_name); | |
defsubr (&Suser_real_login_name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment