andreyorst / powerline.kak

Kakoune modeline, but with passion
MIT License
50 stars 8 forks source link

Suggestions for behaviour of `powerline-toggle` command #12

Closed stevenyvr987 closed 5 years ago

stevenyvr987 commented 5 years ago
  1. I tried toggling all parts of the powerline off, but then I get an empty mode line. At this point, I expected to get kak's default mode line.
  2. Could powerline-toggle accept zero arguments to toggle all powerline segments?
  3. Could powerline-toggle implement tab completion to get hints of available powerline segments, in the same way that powerline-format accepts tab completion?
andreyorst commented 5 years ago

3. Could powerline-toggle implement tab completion to get hints of available powerline segments, in the same way that powerline-format accepts tab completion?

I thought I have this feature :O

2. Could powerline-toggle accept zero arguments to toggle all powerline segments?

What should happen if you toggle all segments? default modeline should appear?

  1. I tried toggling all parts of the powerline off, but then I get an empty mode line. At this point, I expected to get kak's default mode line.

powerline.kak overrides default modeline value without saving it, so rightnow it's not possible. It's not impossible to add, but I don't see why it should be there. No powerline is good for side-panel-like windows like tagbar.kak

stevenyvr987 commented 5 years ago
  1. Could powerline-toggle implement tab completion to get hints of available powerline segments, in the same way that powerline-format accepts tab completion?

I thought I have this feature :O

I just looked at the source and it looks like there's an error in the -shell-script-candidates definition: kak_quoted_quoted_opt_powerline_modules should be kak_quoted_opt_powerline_modules

  1. Could powerline-toggle accept zero arguments to toggle all powerline segments?

What should happen if you toggle all segments? default modeline should appear?

  1. I tried toggling all parts of the powerline off, but then I get an empty mode line. At this point, I expected to get kak's default mode line.

powerline.kak overrides default modeline value without saving it, so rightnow it's not possible. It's not impossible to add, but I don't see why it should be there. No powerline is good for side-panel-like windows like tagbar.kak

If I toggle all segments, it would be nice if the original modeline returns, but then considering your use case of not having any modeline for side panel windows, maybe a pair of new commands powerline-enable/powerline-disable is needed.

In any case, I think it would be nice to not lose the original modeline. Here's a few use cases.

andreyorst commented 5 years ago

I hear you. I'll work on toggling feature in few days :)

andreyorst commented 5 years ago

I've added functions to toggle powerline, but there's one problem. modelinefmt only works in window scope, so I can't toggle powerline in all windows. As a workaround I can replace hooks from modeline-rebuild to modeline-disable, but it's ugly.

Now you need to turn powerline on explicitly with hook global -once -always WinCreate .* powerline-enable

andreyorst commented 5 years ago

@stevenyvr987 I've changed scoping to buffer, so now it is possible to toggle powerline for all buffers on and off. Could you test this please and see if it works for you?

stevenyvr987 commented 5 years ago

I've just git pulled the toggling branch into my autoload directory. powerline-toggle seems to work as i expected. Thanks for making the changes.

I used the following configuration to get powerline installed, hook -once global BufCreate .* { powerline-enable }. I opened two different files, kak -s s a.txt b.txt. Moreover, I opened another kak client kak -c s.

  1. I saw Powerline enabled in each window.
  2. I then powerline-toggle'd in one of the windows, and was able to see the original stats line show up in all windows; toggling again showed Powerline in all windows.
  3. I was able to see the same behaviour when toggling Powerline.

I also tried using hook -once global WinCreate .* { powerline-enable } and saw the same behaviour.

I'm not sure which hook, BufCreate or WinCreate, is best. Currently, the README.md file doesn't suggest how to enable powerline if autoloading.

andreyorst commented 5 years ago

I'm not sure which hook, BufCreate or WinCreate, is best. Currently, the README.md file doesn't suggest how to enable powerline if autoloading.

I've not decided yet either. I think BufCreate is optimal, because currently powerline-enable and all powerline commands are using the buffer scope. I don't like the hook solution because it's too verbose and inexperienced users may get it wrong. I think I'll add powerline-start command that will require powerline module and declare a hook

andreyorst commented 5 years ago

Also, I've found another problem. Some modules declare hooks. When we disable powerline, we also should disable module hooks. And when we enable powerline back, those hooks should be enabled as well. This is trickier to maintain.

andreyorst commented 5 years ago

I've pushed huge amount of changes regarding how toggling work and how hooks are set up, please test

stevenyvr987 commented 5 years ago

I've just tested the latest version of the toggling branch.

To get powerline working in the new scheme (without using the plug module):

I repeated my earlier scenario of opening up two buffers and two clients, one client showing one buffer, the other client showing the other buffer; calling powerline-toggle twice in a row shows the powerline changing to the original status line and then changing back to powerline, across each window, as expected.

Here's a new test scenario.

andreyorst commented 5 years ago

Calling powerline-toggle-module for one of the modules (bufname) turned off the module for the window, but not the other; I think this is expected.

powerline-toggle-module tries to be efficient and does not rebuild all powerlines in all windows. Usually as you switch to another window or buffer the powerline updates. I'd like to keep that if possible.

If I call powerline-toggle so that no powerline is showing, and then call powerline-toggle-module bufname in one of the windows, powerline shows up in the window without bufname; the other window shows powerline toggled off. I'm not sure whether calling powerline-toggle-module should result in showing powerline when it's toggled off.

The same reason as above. We do not rebuild all powerlines to avoid longer times of unresponsiveness. I've thought about doing all of this asynchronously, but couldn't find reliable way yet. Still thinking about this though.

If I now call powerline-toggle, powerline shows up in the other window, but without bufname, which is not expected, since toggling a module is scoped to a window. At this point, it seems there is a mis-match in state variables. Complicated!

since toggling a module is scoped to a window

No. The toggling is not scoped, it's just the powerline is not yet updated.

I hear your thoughts, I'll look into those but after a vacation. I guess I'll not be able to do anything in next 12 days. We'll see.

As for errors:

  • First, I tried calling powerline-start and then calling commands to define a customized sequence of modules, and to select a preferred theme, but got errors saying these commands were not yet defined.
  • I had to define my own version of powerline-start, adding in commands to customize powerline.

That's a cornercase. If you calling powerline-start manually it will fail, because all it does is declares a hook that enables powerline when a buffer is ready, since powerline is buffer scoped commands cannot be evaluated before the buffer is opened. I've thought about something like this:

define-command powerline-start %{
    require-module powerline
    try %{
        powerline-enable
    } catch %{
        hook -once global BufCreate .* powerline-enable
    }
}

To make it more interactive, but unfortunately this throws lot's of errors, because while powerline-enable works it's internal parts are not able to without a buffer. Wrapping everything inside in try would solve this, but this will not work either, because a lot of stuff is tied to another hook ModuleLoaded powerline which is also buffer dependent and needs to succeed. So currently powerline-start only defines a hook:

define-command powerline-start %{
    hook -once global BufCreate .* %{ 
        require-module powerline
        powerline-enable
    }
}

If you really want to start powerline manually you should first require it's module, and after that enable it, but this can only happen after buffer was created. This how Kakoune scoping works, unfortunately I can't improve much here without sacrificing buffer scope which is impossible.

andreyorst commented 5 years ago

I have pushed and experimental commit that always rebuilds powerlines in all buffers. If you can test if with huge amount of buffers (about a hundred, I usually work with many buffers in background launching kak by find -type f -name '*.cc' | xargs kak) that would be nice. But I already see that opening 60 buffers makes kakoune hang on every rebuild of powerline

andreyorst commented 5 years ago

That's acutally another problem, because if we toggle powerline off it is fast, but toggling it on for hundred buffers will be a painful task. Maybe I should repaint it on demand somehow

andreyorst commented 5 years ago

I've managed to achieve good performance and tackle all points you've described here. Thanks for inspiration! Can you please test it again?

stevenyvr987 commented 5 years ago

I see that you've merged, so I'm now using the main branch.

When i open kak on all of kakoune's source files kak src/*.{cc,hh} (142 files, about 10MB of resident memory), and then toggle powerline off/on, I don't sense any performance issues; the effect is fast.

Here is a sequence of actions that leads to something "unexpected".

  1. In window 1, kak -s s /var/tmp/a.txt /var/tmp/b.txt
  2. In window 2, kak -c s
  3. In either window, :powerline-toggle -- powerline turns off in windows 1 and 2
  4. :powerline-toggle-module bufname -- powerline shows without bufname; is showing up expected?
  5. :powerline-toggle -- powerline continues to show, expected if powerline didn't show in step 4, but since it did, staying untoggled seems unexpected.

It seems in step 4, doing powerline-toggle-module overrode the toggle state.

andreyorst commented 5 years ago

I've pushed the fix. See if it works for you

stevenyvr987 commented 5 years ago

Tried again, and it works in an expected way: When I tried to toggle a powerline module, a message shows in status line saying powerline is disabled, which is understandable.