Closed ghost closed 7 years ago
As an example, we could add another argument to copymode
, which is the array of editors to look into:
static void
-copymode(const char *args[]) {
+copymode(const char *args[], Editor editor) {
Then in config.h:
static KeyBinding bindings[] = {
...
- { { MOD, 'e', }, { copymode, { NULL } } },
+ { { MOD, 'e', }, { copymode, { NULL, editors } } },
{ { MOD, '/', }, { copymode, { "/", NULL } } },
+ { { MOD, 'E', }, { copymode, { NULL, pagers } } },
...
}
...
static Editor editors[] = {
{ .name = "vis", .argv = { "vis", "+%d", "-", NULL }, .filter = true, .color = false },
{ .name = "sandy", .argv = { "sandy", "-d", "-", NULL }, .filter = true, .color = false },
{ .name = "dvtm-editor", .argv = { "dvtm-editor", "-", NULL }, .filter = true, .color = false },
{ .name = "vim", .argv = { "vim", "+%d", "-", NULL }, .filter = false, .color = false },
- { .name = "less", .argv = { "less", "-R", "+%d", NULL }, .filter = false, .color = true },
- { .name = "more", .argv = { "more", "+%d", NULL }, .filter = false, .color = false },
};
+
+static Editor pagers[] = {
+ { .name = "less", .argv = { "less", "-R", "+%d", NULL }, .filter = false, .color = true },
+ { .name = "more", .argv = { "more", "+%d", NULL }, .filter = false, .color = true },
+};
PS: This does not add support for two distinct environment variable.
Could you motivate your changes a bit? We have limited scroll back history anyway so your editor should generally also be a reasonable pager.
This issue reminded me that I should dig out and review a patch for a standalone dvtm-editor
utility which would invoke $EDITOR
and at least in theory work for any editor.
The idea is that less
is a color-capable pager, and scrolling and searching is very pleasant with it. But less
it can not output text, and can not paste text for dvtm.
Now I remember that dvtm
has a scroll keybinding in addition of the pager. This will fix my issue.
In addition, less
, if input comes from a file (i.e: not from stdin), pressing v
opens the editor.
We I could even make a dvtm-editor
script that does this:
$DVTM_EDITOR
(less which can now open an editor, or any editor):w
) and quit.Any editor can edit and save a file, while not can read and write to and from stdin
.
In the end, the script could check availability (with command -v
):
DVTM_EDITOR
,VISUAL
,EDITOR
,ALTERNATE_EDITOR
PAGER
vis
(because it handles input the right way and because we can),vim
(because it is popular ?),vi
less
(fallingback to pagers)more
(last resort).For all pager, we would not output anything, for all editors, we would output the remaining content of the text file, unless it has not been saved (comparison of mtime
or some other trick), we did just have a look and not copy.
This chunk could eventually make copymode()
simpler.
I merged a dvtm-editor
and dvtm-pager
utility which more or less does what you described. Hope this covers your use cases.
This works very well. A bunch of thank-you for @martanne and the other author.
What about having both:
static Editor editors[]
DVTM_EDITOR
static Editor pagers[]
DVTM_PAGER
I may be able to try it after my exams if you are short on time.