diff options
Diffstat (limited to 'src/ring.c')
-rw-r--r-- | src/ring.c | 66 |
1 files changed, 64 insertions, 2 deletions
@@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2024 Robin Haberkorn + * Copyright (C) 2012-2025 Robin Haberkorn * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -413,7 +413,7 @@ teco_state_edit_file_initial(teco_machine_main_t *ctx, GError **error) strlen(filename), cur == teco_ring_current); } - teco_interface_popup_show(); + teco_interface_popup_show(0); } else if (id > 0) { allow_filename = FALSE; if (!teco_current_doc_undo_edit(error) || @@ -480,6 +480,10 @@ teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE * area. * Naturally this only has any effect in interactive * mode. + * Note that you can also click on these entries \(em + * if mouse support is enabled \(em to immediately switch + * to any file in the buffer ring just like with any + * other popup. * * <file> may also be a glob pattern, in which case * all regular files matching the pattern are opened/edited. @@ -577,3 +581,61 @@ teco_state_save_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE * characters are enabled by default. */ TECO_DEFINE_STATE_EXPECTFILE(teco_state_save_file); + +/*$ EF close + * [bool]EF -- Remove buffer from ring + * -EF + * :EF + * + * Removes buffer from buffer ring, effectively + * closing it. + * If the buffer is dirty (modified), EF will yield + * an error. + * <bool> may be a specified to enforce closing dirty + * buffers. + * If it is a Failure condition boolean (negative), + * the buffer will be closed unconditionally. + * If <bool> is absent, the sign prefix (1 or -1) will + * be implied, so \(lq-EF\(rq will always close the buffer. + * + * When colon-modified, <bool> is ignored and \fBEF\fP + * will save the buffer before closing. + * The file is always written, unlike \(lq:EX\(rq which + * saves only dirty buffers. + * This can fail of course, e.g. when called on the unnamed + * buffer. + * + * It is noteworthy that EF will be executed immediately in + * interactive mode but can be rubbed out at a later time + * to reopen the file. + * Closed files are kept in memory until the command line + * is terminated. + */ +void +teco_state_ecommand_close(teco_machine_main_t *ctx, GError **error) +{ + if (teco_qreg_current) { + const teco_string_t *name = &teco_qreg_current->head.name; + g_autofree gchar *name_printable = teco_string_echo(name->data, name->len); + g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, + "Q-Register \"%s\" currently edited", name_printable); + return; + } + + if (teco_machine_main_eval_colon(ctx) > 0) { + if (!teco_buffer_save(teco_ring_current, NULL, error)) + return; + } else { + teco_int_t v; + if (!teco_expressions_pop_num_calc(&v, teco_num_sign, error)) + return; + if (teco_is_failure(v) && teco_ring_current->dirty) { + g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, + "Buffer \"%s\" is dirty", + teco_ring_current->filename ? : "(Unnamed)"); + return; + } + } + + teco_ring_close(error); +} |