~martanne/devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH vis] decouple windows and files

Details
Message ID
<172531775856.20527.11598101958719368213-0@git.sr.ht>
DKIM signature
missing
Download raw message
Patch: +23 -20
From: urosm <urosm@kompot.si>

This allows keeping files with unsaved modifications in the state
without having to have them displayed in a window.

vis_window_close no longer frees win->file, this is moved to vis_free.
After closing the last window cmd_quit and cmd_qall check for modified
files in vis->files and open a new window for the found modified file
if necessary.
---
 vis-cmds.c | 40 +++++++++++++++++++++-------------------
 vis.c      |  3 ++-
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/vis-cmds.c b/vis-cmds.c
index 4cfb3bd..f94c8b7 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -463,10 +463,6 @@ static bool cmd_edit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selec
	Win *oldwin = win;
	if (!oldwin)
		return false;
	if (cmd->flags != '!' && !vis_window_closable(oldwin)) {
		info_unsaved_changes(vis);
		return false;
	}
	if (!argv[1]) {
		if (oldwin->file->refcount > 1) {
			vis_info_show(vis, "Can not reload file being opened multiple times");
@@ -511,30 +507,36 @@ static bool has_windows(Vis *vis) {
	return false;
}

static bool cmd_quit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
	if (cmd->flags != '!' && !vis_window_closable(win)) {
		info_unsaved_changes(vis);
		return false;
static bool find_modified_file(Vis *vis) {
	for (File *file = vis->files; file; file = file->next) {
		if (!file->internal && text_modified(file->text)) {
			vis_window_new(vis, file->name);
			info_unsaved_changes(vis);
			return true;
		}
	}
	return false;
}

static bool cmd_quit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
	vis_window_close(win);
	if (!has_windows(vis))
		vis_exit(vis, argv[1] ? atoi(argv[1]) : EXIT_SUCCESS);
	if (has_windows(vis))
		return true;
	if (cmd->flags != '!' && find_modified_file(vis))
		return false;
	vis_exit(vis, argv[1] ? atoi(argv[1]) : EXIT_SUCCESS);
	return true;
}

static bool cmd_qall(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
	for (Win *next, *win = vis->windows; win; win = next) {
		next = win->next;
		if (!win->file->internal && (!text_modified(win->file->text) || cmd->flags == '!'))
	for (Win *win = vis->windows; win; win = win->next) {
		if (!win->file->internal)
			vis_window_close(win);
	}
	if (!has_windows(vis)) {
		vis_exit(vis, argv[1] ? atoi(argv[1]) : EXIT_SUCCESS);
		return true;
	} else {
		info_unsaved_changes(vis);
	if (cmd->flags != '!' && find_modified_file(vis))
		return false;
	}
	vis_exit(vis, argv[1] ? atoi(argv[1]) : EXIT_SUCCESS);
	return true;
}

static bool cmd_split(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
diff --git a/vis.c b/vis.c
index 7d3dd6a..9841516 100644
--- a/vis.c
+++ b/vis.c
@@ -547,7 +547,6 @@ void vis_window_close(Win *win) {
		return;
	Vis *vis = win->vis;
	vis_event_emit(vis, VIS_EVENT_WIN_CLOSE, win);
	file_free(vis, win->file);
	if (win->prev)
		win->prev->next = win->next;
	if (win->next)
@@ -626,6 +625,8 @@ void vis_free(Vis *vis) {
	file_free(vis, vis->command_file);
	file_free(vis, vis->search_file);
	file_free(vis, vis->error_file);
	while (vis->files)
		file_free(vis, vis->files);
	for (int i = 0; i < LENGTH(vis->registers); i++)
		register_release(&vis->registers[i]);
	ui_terminal_free(&vis->ui);
-- 
2.45.2

[vis/patches] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D3W64LYN31QJ.1U5SKS71NHPS1@fra02>
In-Reply-To
<172531775856.20527.11598101958719368213-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
vis/patches: FAILED in 1m12s

[decouple windows and files][0] from [~urosm][1]

[0]: https://lists.sr.ht/~martanne/devel/patches/54844
[1]: urosm@kompot.si

✗ #1317760 FAILED  vis/patches/openbsd.yml https://builds.sr.ht/~martanne/job/1317760
✓ #1317758 SUCCESS vis/patches/debian.yml  https://builds.sr.ht/~martanne/job/1317758
✓ #1317757 SUCCESS vis/patches/alpine.yml  https://builds.sr.ht/~martanne/job/1317757
✓ #1317759 SUCCESS vis/patches/freebsd.yml https://builds.sr.ht/~martanne/job/1317759
Details
Message ID
<3FLK1OE3UUMUE.2RZRXQJOEAN93@rnpnr.xyz>
In-Reply-To
<172531775856.20527.11598101958719368213-0@git.sr.ht> (view parent)
DKIM signature
permerror
Download raw message
~urosm <urosm@git.sr.ht> wrote:
> From: urosm <urosm@kompot.si>
> 
> This allows keeping files with unsaved modifications in the state
> without having to have them displayed in a window.
> 
> vis_window_close no longer frees win->file, this is moved to vis_free.
> After closing the last window cmd_quit and cmd_qall check for modified
> files in vis->files and open a new window for the found modified file
> if necessary.
> ---
>  vis-cmds.c | 40 +++++++++++++++++++++-------------------
>  vis.c      |  3 ++-
>  2 files changed, 23 insertions(+), 20 deletions(-)

Sorry I didn't mean to overlook this one. A better motivation for
this is that this helps us move towards the Client-Server idea. It
should also help with improving support for multiple views of the
the same file.

I think all the changes look good to me but they introduce a bug.
After applying this modify a file and try to close it without
writing. The cursor will jump to position 0,0. I think the order
in which parts of the window are being destroyed was changed so
now the selection gets lost.

That will need to be fixed before I can apply this.

- Randy

-- 
https://rnpnr.xyz/
GPG Fingerprint: B8F0 CF4C B6E9 415C 1B27 A8C4 C8D2 F782 86DF 2DC5
Reply to thread Export thread (mbox)