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 kill-buffer #1507

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
348 changes: 333 additions & 15 deletions rust_src/src/buffers.rs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions rust_src/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ pub struct LispMarkerIter {
current: Option<LispMarkerRef>,
}

impl LispMarkerIter {
pub fn from_buffer(buffer: LispBufferRef) -> Self {
Self {
current: buffer.markers(),
}
}
}

impl Iterator for LispMarkerIter {
type Item = LispMarkerRef;

Expand Down
5 changes: 5 additions & 0 deletions rust_src/src/minibuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ use crate::{
symbols::symbol_value,
textprop::get_char_property,
threads::{c_specpdl_index, ThreadState},
windows::LispWindowRef,
};

pub fn minibuffer_window() -> LispWindowRef {
agraven marked this conversation as resolved.
Show resolved Hide resolved
unsafe { minibuf_window }.into()
}

/// Return t if BUFFER is a minibuffer.
/// No argument or nil as argument means use current buffer as BUFFER.
/// BUFFER can be a buffer or a buffer name.
Expand Down
1 change: 1 addition & 0 deletions rust_src/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub fn string_width(string: LispStringRef) -> usize {
macro_rules! new_unibyte_string {
($str:expr) => {{
let strg = ::std::ffi::CString::new($str).unwrap();
#[allow(unused_unsafe)]
unsafe {
crate::remacs_sys::make_unibyte_string(strg.as_ptr(), strg.as_bytes().len() as isize)
}
Expand Down
1 change: 1 addition & 0 deletions rust_src/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@
#endif
#include "window.h"
#include "xgselect.h"
#include "xwidget.h"
agraven marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 4 additions & 5 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ int last_per_buffer_idx;
static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
bool after, Lisp_Object arg1,
Lisp_Object arg2, Lisp_Object arg3);
static void swap_out_buffer_local_variables (struct buffer *b);

extern void drop_overlay (struct buffer *, struct Lisp_Overlay *);
void unchain_both (struct buffer *, Lisp_Object);
Expand All @@ -128,7 +127,6 @@ Lisp_Object buffer_fundamental_string(void)
return QSFundamental;
}

static void free_buffer_text (struct buffer *b);
extern struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *);
static Lisp_Object buffer_lisp_local_variables (struct buffer *, bool);

Expand Down Expand Up @@ -947,6 +945,7 @@ compact_buffer (struct buffer *buffer)
}
}

#if PORTED_TO_RUST
DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ",
doc: /* Kill the buffer specified by BUFFER-OR-NAME.
The argument may be a buffer or the name of an existing buffer.
Expand Down Expand Up @@ -1223,6 +1222,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)

return Qt;
}
#endif

/* Move association for BUFFER to the front of buffer (a)lists. Since
we do this each time BUFFER is selected visibly, the more recently
Expand Down Expand Up @@ -1983,7 +1983,7 @@ the normal hook `change-major-mode-hook'. */)
/* Make sure no local variables remain set up with buffer B
for their current values. */

static void
void
swap_out_buffer_local_variables (struct buffer *b)
{
Lisp_Object oalist, alist, buffer;
Expand Down Expand Up @@ -4053,7 +4053,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)

/* Free buffer B's text buffer. */

static void
void
free_buffer_text (struct buffer *b)
{
block_input ();
Expand Down Expand Up @@ -5260,7 +5260,6 @@ Functions running this hook are, `get-buffer-create',
defsubr (&Sbuffer_local_variables);
defsubr (&Sset_buffer_modified_p);
defsubr (&Sother_buffer);
defsubr (&Skill_buffer);
defsubr (&Sbury_buffer_internal);
defsubr (&Sset_buffer_major_mode);
defsubr (&Sbuffer_swap_text);
Expand Down
3 changes: 3 additions & 0 deletions src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,9 @@ struct infile
/* Defined in buffer.c. */
extern struct infile* infile;

extern void free_buffer_text (struct buffer *b);
extern void swap_out_buffer_local_variables (struct buffer *b);

/* Defined in lread.c. */
extern void readevalloop (Lisp_Object, struct infile *, Lisp_Object, bool,
Lisp_Object, Lisp_Object,
Expand Down
46 changes: 46 additions & 0 deletions test/rust_src/src/buffers-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,52 @@
(should-not (string= random-name buf-name))
(should (< 0 random-number 999999)))))

(ert-deftest test-kill-buffer-by-buf ()
(let ((buf (get-buffer-create "kill-me")))
(kill-buffer buf)
(should (eq (get-buffer "kill-me") nil))))

(ert-deftest test-kill-buffer-by-name ()
(get-buffer-create "kill-me")
(kill-buffer "kill-me")
(should (eq (get-buffer "kill-me") nil)))

(ert-deftest test-kill-buffer-default ()
(let ((buf (get-buffer-create "kill-me")))
(with-current-buffer buf (kill-buffer))
(should (eq (get-buffer "kill-me") nil))))

(ert-deftest test-kill-buffer-query-fn ()
(let ((buf (get-buffer-create "kill-me"))
(kill-fns kill-buffer-query-functions))
(setq kill-buffer-query-functions
(list (lambda ()
(should (eq (current-buffer) buf))
nil)))
(kill-buffer buf)
(should (eq (get-buffer "kill-me") buf))
(setq kill-buffer-query-functions kill-fns)
(kill-buffer buf)
(should (eq (get-buffer "kill-me") nil))))

(ert-deftest test-kill-buffer-hook-fns ()
(let* ((buf (get-buffer-create "kill-me"))
(kill-hook-called nil)
(kill-hook-fn (lambda ()
(should (eq (current-buffer) buf))
(setq kill-hook-called t)))
(update-hook-called nil)
(update-hook-fn (lambda ()
(setq update-hook-called t))))
(add-hook `kill-buffer-hook kill-hook-fn)
(add-hook `buffer-list-update-hook update-hook-fn)
(kill-buffer buf)
(should (eq (get-buffer "kill-me") nil))
(should (eq kill-hook-called t))
(should (eq update-hook-called t))
(remove-hook `kill-buffer-hook kill-hook-fn)
(remove-hook `buffer-list-update-hook update-hook-fn)))

(provide 'buffers-tests)

;;; buffers-tests.el ends here