-
Notifications
You must be signed in to change notification settings - Fork 309
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 run-window-configuration-change-hook (#1441) #1545
Port run-window-configuration-change-hook (#1441) #1545
Conversation
correct
also, correct. |
rust_src/src/windows.rs
Outdated
/// Run `window-configuration-change-hook' for FRAME. | ||
/// If FRAME is omitted or nil, it defaults to the selected frame. | ||
#[lisp_fn(min = "0")] | ||
pub fn run_window_configuration_change_hook(frame: Option<LispObject>) -> LispObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn run_window_configuration_change_hook(frame: Option<LispObject>) -> LispObject { | |
pub fn run_window_configuration_change_hook(frame: LispFrameLiveOrSelected) { |
Wherever you see decode_live_frame
you can use LispFrameLiveOrSelected
instead. Then in the function:
let frame_ref: LispFrameRef = frame.into();
Now you have a Rust LispFrameRef
to use.
rust_src/src/windows.rs
Outdated
/// If FRAME is omitted or nil, it defaults to the selected frame. | ||
#[lisp_fn(min = "0")] | ||
pub fn run_window_configuration_change_hook(frame: Option<LispObject>) -> LispObject { | ||
let f = frame.map_or(Qnil, |obj| obj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed, see above.
rust_src/src/windows.rs
Outdated
#[lisp_fn(min = "0")] | ||
pub fn run_window_configuration_change_hook(frame: Option<LispObject>) -> LispObject { | ||
let f = frame.map_or(Qnil, |obj| obj); | ||
unsafe { run_window_conf_change_hook(decode_live_frame(f)) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe { run_window_conf_change_hook(decode_live_frame(f)) }; | |
unsafe { run_window_conf_change_hook(frame.into()) }; |
rust_src/src/windows.rs
Outdated
pub fn run_window_configuration_change_hook(frame: Option<LispObject>) -> LispObject { | ||
let f = frame.map_or(Qnil, |obj| obj); | ||
unsafe { run_window_conf_change_hook(decode_live_frame(f)) }; | ||
Qnil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the naked Qnil return. The lisp_fn
wrapper handles this in the cases where the function should always return Qnil.
Qnil | ||
} | ||
|
||
#[rustfmt::skip] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the skip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt causes an error when I try make.
$ make
:
make[1]: Entering directory '/path/to/remacs/src'
GEN globals.h
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
/bin/sh: line 1: 1785984 Aborted (core dumped) ../lib-src/make-docfile -d . -g dispnew.o frame.o scroll.o xdisp.o menu.o xmenu.o window.o charset.o coding.o category.o ccl.o character.o chartab.o bidi.o cm.o term.o terminal.o xfaces.o xterm.o xfns.o xselect.o xrdb.o xsmfns.o xsettings.o gtkutil.o emacsgtkfixed.o dbusbind.o emacs.o keyboard.o macros.o keymap.o sysdep.o buffer.o filelock.o insdel.o minibuf.o fileio.o dired.o casefiddle.o indent.o search.o regex.o undo.o alloc.o data.o doc.o editfns.o callint.o eval.o fns.o font.o print.o lread.o syntax.o unexelf.o bytecode.o process.o gnutls.o callproc.o region-cache.o sound.o atimer.o doprnt.o intervals.o textprop.o composite.o xml.o lcms.o inotify.o profiler.o thread.o systhread.o sheap.o xfont.o ftfont.o xftfont.o ftxfont.o fontset.o fringe.o image.o xgselect.o json.o ../rust_src/src/*.rs > globals.tmp
make[1]: *** No rule to make target 'gl-stamp', needed by 'globals.h'. Stop.
make[1]: Leaving directory '/path/to/remacs/src'
make: *** [Makefile:429: src] Error 2
And I followed these codes.
https://github.com/remacs/remacs/blob/master/rust_src/src/process.rs#L558-L559
rustfmt seems to break macro expansion.
Do you have any idea?
This code is formatted to following
def_lisp_sym!(
Qwindow_configuration_change_hook,
"window-configuration-change-hook"
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you show the backtrace you get when you reproduce the error with RUST_BACKTRACE=1
set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the backtrace.
$ RUST_BACKTRACE=1 make
make -C lib all
make[1]: Entering directory '/path/to/remacs/lib'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/path/to/remacs/lib'
make -C lib-src all
make[1]: Entering directory '/path/to/remacs/lib-src'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/path/to/remacs/lib-src'
make -C src VCSWITNESS='$(srcdir)/../.git/logs/HEAD' all
make[1]: Entering directory '/path/to/remacs/src'
GEN globals.h
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:47
3: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:36
4: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:200
5: std::panicking::default_hook
at src/libstd/panicking.rs:214
6: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:477
7: std::panicking::continue_panic_fmt
at src/libstd/panicking.rs:384
8: rust_begin_unwind
at src/libstd/panicking.rs:311
9: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
10: core::panicking::panic
at src/libcore/panicking.rs:49
11: core::option::Option<T>::unwrap
at /rustc/bc2e84ca0939b73fcf1768209044432f6a15c2e5/src/libcore/macros.rs:12
12: scan_rust_file
at remacs-lib/docfile.rs:168
/bin/sh: line 1: 2857917 Aborted (core dumped) ../lib-src/make-docfile -d . -g dispnew.o frame.o scroll.o xdisp.o menu.o xmenu.o window.o charset.o coding.o category.o ccl.o character.o chartab.o bidi.o cm.o term.o terminal.o xfaces.o xterm.o xfns.o xselect.o xrdb.o xsmfns.o xsettings.o gtkutil.o emacsgtkfixed.o dbusbind.o emacs.o keyboard.o macros.o keymap.o sysdep.o buffer.o filelock.o insdel.o minibuf.o fileio.o dired.o casefiddle.o indent.o search.o regex.o undo.o alloc.o data.o doc.o editfns.o callint.o eval.o fns.o font.o print.o lread.o syntax.o unexelf.o bytecode.o process.o gnutls.o callproc.o region-cache.o sound.o atimer.o doprnt.o intervals.o textprop.o composite.o xml.o lcms.o inotify.o profiler.o thread.o systhread.o sheap.o xfont.o ftfont.o xftfont.o ftxfont.o fontset.o fringe.o image.o xgselect.o json.o ../rust_src/src/*.rs > globals.tmp
make[1]: *** No rule to make target 'gl-stamp', needed by 'globals.h'. Stop.
make[1]: Leaving directory '/path/to/remacs/src'
make: *** [Makefile:429: src] Error 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. When we parse the def_lisp_sym!
macro in docfile.rs, we can only correctly parse it if it's all on one line. Same with defvar_lisp!
and the others. For now I suggest leaving the #[rustfmt::skip]
and we'll deal with docfile.rs separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@db48x Thank you!
You meant, this regexp doesn't support line breaks?
https://github.com/remacs/remacs/blob/master/rust_src/remacs-lib/docfile.rs#L166
-def_lisp_sym!\((.+?),\s+"(.+?)"\);
+def_lisp_sym!\(\s*(.+?),\s*"(.+?)"\s*\);
I found that defvar_lisp!
has the same issue.
@@ -1128,6 +1128,7 @@ extern Lisp_Object select_window (Lisp_Object window, Lisp_Object norecord, | |||
extern struct window *set_window_fringes (struct window *w, Lisp_Object left_width, | |||
Lisp_Object right_width, Lisp_Object outside_margins); | |||
extern void apply_window_adjustment (struct window *); | |||
extern void run_window_configuration_change_hook (struct frame *); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -201,3 +201,14 @@ | |||
;; frames inside tests (see https://github.com/remacs/remacs/issues/1429). | |||
(ert-deftest window-pixel-height-before-size-change () | |||
(window-pixel-height-before-size-change)) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Tests 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first draft. The changes are minor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, thanks for the PR
Hello,
I hope it closes issue #1441
I have 2 questions.
DEFVAR_LISP ("window-configuration-change-hook", ...)
usingdefvar_lisp!
?static
from C source codes. Is it a correct idea?run_window_configuration_change_hook
C function from Rust source code