martanne / dvtm

dvtm brings the concept of tiling window management, popularized by X11-window managers like dwm to the console. As a console window manager it tries to make it easy to work with multiple console based programs.
MIT License
857 stars 106 forks source link

Implementing a dvtm-editor script? #45

Closed ghost closed 7 years ago

ghost commented 7 years ago

What about having both:

. config.h environment variable keybinding
text-only editor static Editor editors[] DVTM_EDITOR Mod + e
color pager static Editor pagers[] DVTM_PAGER Mod + E

I may be able to try it after my exams if you are short on time.

ghost commented 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.

martanne commented 7 years ago

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.

ghost commented 7 years ago

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:

Any editor can edit and save a file, while not can read and write to and from stdin.

ghost commented 7 years ago

In the end, the script could check availability (with command -v):

  1. DVTM_EDITOR,
  2. VISUAL,
  3. EDITOR,
  4. ALTERNATE_EDITOR
  5. PAGER
  6. vis (because it handles input the right way and because we can),
  7. vim (because it is popular ?),
  8. vi
  9. less (fallingback to pagers)
  10. 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.

martanne commented 7 years ago

I merged a dvtm-editor and dvtm-pager utility which more or less does what you described. Hope this covers your use cases.

ghost commented 7 years ago

This works very well. A bunch of thank-you for @martanne and the other author.