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

Define buffer-file-name in Rust #279

Merged
merged 1 commit into from
Aug 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust_src/remacs-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ extern "C" {
pub static Qsequencep: Lisp_Object;
pub static Qcharacterp: Lisp_Object;
pub static Qchar_table_p: Lisp_Object;
pub static Qbufferp: Lisp_Object;
pub static Qminus: Lisp_Object;

pub static Qinteger: Lisp_Object;
Expand Down Expand Up @@ -1347,7 +1348,6 @@ extern "C" {
pub fn Fcurrent_buffer() -> Lisp_Object;
pub fn Fsignal(error_symbol: Lisp_Object, data: Lisp_Object) -> !;
pub fn Fcopy_sequence(seq: Lisp_Object) -> Lisp_Object;
pub fn Fbuffer_file_name(buffer: Lisp_Object) -> Lisp_Object;
pub fn Ffind_operation_coding_system(nargs: ptrdiff_t, args: *mut Lisp_Object) -> Lisp_Object;
pub fn Flocal_variable_p(variable: Lisp_Object, buffer: Lisp_Object) -> Lisp_Object;
pub fn Ffuncall(nargs: ptrdiff_t, args: *mut Lisp_Object) -> Lisp_Object;
Expand Down
13 changes: 13 additions & 0 deletions rust_src/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,16 @@ pub fn current_buffer() -> LispObject {
))
}
}

/// Return name of file BUFFER is visiting, or nil if none.
/// No argument or nil as argument means use the current buffer.
#[lisp_fn(min = "0")]
pub fn buffer_file_name(buffer: LispObject) -> LispObject {
let buf = if buffer.is_nil() {
ThreadState::current_buffer()
} else {
buffer.as_buffer_or_error()
};

LispObject::from_raw(buf.filename)
}
8 changes: 4 additions & 4 deletions rust_src/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std;
use std::slice;
use libc::ptrdiff_t;

use buffers::{LispBufferRef, get_buffer};
use buffers::{LispBufferRef, get_buffer, buffer_file_name};
use libc;
use lisp::{LispObject, LispNumber};
use multibyte::LispStringRef;
Expand All @@ -14,7 +14,7 @@ use remacs_sys::{preferred_coding_system, Fcoding_system_p, code_convert_string,
validate_subarray, string_char_to_byte};
use remacs_sys::{current_thread, record_unwind_current_buffer, set_buffer_internal,
make_buffer_string};
use remacs_sys::{globals, Fbuffer_file_name, Ffind_operation_coding_system, Flocal_variable_p};
use remacs_sys::{globals, Ffind_operation_coding_system, Flocal_variable_p};
use remacs_sys::{Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512, Qstringp, Qraw_text,
Qcoding_system_error, Qwrite_region, Qbuffer_file_coding_system};
use remacs_macros::lisp_fn;
Expand Down Expand Up @@ -112,13 +112,13 @@ fn get_coding_system_for_buffer(
return LispObject::from_raw(unsafe { Qraw_text });
}
}
if LispObject::from_raw(unsafe { Fbuffer_file_name(object.to_raw()) }).is_not_nil() {
if buffer_file_name(object).is_not_nil() {
/* Check file-coding-system-alist. */
let mut args = [
unsafe { Qwrite_region },
start.to_raw(),
end.to_raw(),
unsafe { Fbuffer_file_name(object.to_raw()) },
buffer_file_name(object).to_raw(),
];
let val = LispObject::from_raw(unsafe {
Ffind_operation_coding_system(4, args.as_mut_ptr())
Expand Down
4 changes: 4 additions & 0 deletions rust_src/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub use base64::base64_decode_1;
// Used in buffer.c
pub use buffers::Fbuffer_live_p;

// Used in nsfns.m
pub use buffers::Fbuffer_file_name;

// These need to be exported as bytecode.c depends upon them.
pub use math::Fplus;
pub use math::Fminus;
Expand Down Expand Up @@ -153,6 +156,7 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*buffers::Sbuffer_live_p);
defsubr(&*buffers::Sget_buffer);
defsubr(&*buffers::Scurrent_buffer);
defsubr(&*buffers::Sbuffer_file_name);
defsubr(&*windows::Swindowp);
defsubr(&*windows::Swindow_live_p);
defsubr(&*process::Sget_process);
Expand Down
8 changes: 7 additions & 1 deletion rust_src/src/lisp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use remacs_sys::{EmacsInt, EmacsUint, EmacsDouble, VALMASK, VALBITS, INTTYPEBITS
Lisp_Misc_Any, Lisp_Misc_Type, Lisp_Float, Lisp_Cons, Lisp_Object, lispsym,
make_float, circular_list, internal_equal, Fcons, CHECK_IMPURE, Qnil, Qt,
Qnumberp, Qfloatp, Qstringp, Qsymbolp, Qnumber_or_marker_p, Qwholenump, Qvectorp,
Qcharacterp, Qlistp, Qintegerp, Qhash_table_p, Qchar_table_p, Qconsp,
Qcharacterp, Qlistp, Qintegerp, Qhash_table_p, Qchar_table_p, Qconsp, Qbufferp,
SYMBOL_NAME, PseudovecType, EqualKind};

// TODO: tweak Makefile to rebuild C files if this changes.
Expand Down Expand Up @@ -435,6 +435,12 @@ impl LispObject {
self.as_vectorlike().map_or(None, |v| v.as_buffer())
}

pub fn as_buffer_or_error(self) -> LispBufferRef {
self.as_buffer().unwrap_or_else(
|| wrong_type!(Qbufferp, self),
)
}

pub fn is_char_table(self) -> bool {
self.as_vectorlike().map_or(false, |v| {
v.is_pseudovector(PseudovecType::PVEC_CHAR_TABLE)
Expand Down
9 changes: 0 additions & 9 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,14 +1066,6 @@ Return nil if BUFFER has been killed. */)
return BVAR (decode_buffer (buffer), name);
}

DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0,
doc: /* Return name of file BUFFER is visiting, or nil if none.
No argument or nil as argument means use the current buffer. */)
(register Lisp_Object buffer)
{
return BVAR (decode_buffer (buffer), filename);
}

DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, Sbuffer_base_buffer,
0, 1, 0,
doc: /* Return the base buffer of indirect buffer BUFFER.
Expand Down Expand Up @@ -6138,7 +6130,6 @@ Functions running this hook are, `get-buffer-create',
defsubr (&Smake_indirect_buffer);
defsubr (&Sgenerate_new_buffer_name);
defsubr (&Sbuffer_name);
defsubr (&Sbuffer_file_name);
defsubr (&Sbuffer_base_buffer);
defsubr (&Sbuffer_local_value);
defsubr (&Sbuffer_local_variables);
Expand Down