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 1 commit into from Aug 1, 2017
Jump to file or symbol
Failed to load files and symbols.
+29 −15
Diff settings


Just for now

Copy path View file
@@ -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;
@@ -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;
Copy path View file
@@ -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() {
} else {
Copy path View file
@@ -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;
@@ -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,
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;
@@ -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 },
unsafe { Fbuffer_file_name(object.to_raw()) },
let val = LispObject::from_raw(unsafe {
Ffind_operation_coding_system(4, args.as_mut_ptr())
Copy path View file
@@ -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;
@@ -153,6 +156,7 @@ pub extern "C" fn rust_init_syms() {
Copy path View file
@@ -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.
@@ -435,6 +435,12 @@ impl LispObject {
self.as_vectorlike().map_or(None, |v| v.as_buffer())
pub fn as_buffer_or_error(self) -> LispBufferRef {
|| wrong_type!(Qbufferp, self),
pub fn is_char_table(self) -> bool {
self.as_vectorlike().map_or(false, |v| {
Copy path View file
@@ -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.
@@ -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);
ProTip! Use n and p to navigate between commits in a pull request.