Skip to content

Can only bind key sequences to functions listed in bind --function-names - Cygwin, fish 2.2.0 #2284

Closed

Description

@macdanny

I recently opened (and closed) #2260 because the up-arrow key would only print a square with an x through it. I initially thought it was because of terminfo stuff, but eventually determined it was the 'up-or-search' function. I was able to bind up-arrow to history-search-backward, which was good enough at the time.

I have since installed fish on a FreeBSD box I have and it behaves much better than it does on Cygwin. So I now know up-or-search should not behave that way.

I've noticed some other peculiarities now. \cc also prints a box with an x through it. \cl does too. And I think I can see what the common thread is in all of this. Any binding that invokes the commandline function fails -- this includes up-or-search which is the first problem function I noticed.

I can run commandline on the command line and it does what it should. It's just broken when invoked from a function called by a key binding. It does work when invoked directly by a function (e.g. I can run up-or-search on the command line and while not particularly useful it does what it should and doesn't print a box with an x through it).

Activity

  1. macdanny commented on Aug 12, 2015

    @macdanny
    Author

    Actually it fails on any function not listed in the output of "bind --function-names"

  2. ridiculousfish commented on Aug 12, 2015

    @ridiculousfish
    Member

    I don't think commandline does much when run directly. Here's a simple test:

    bind q commandline -pt'
    foobarq
    

    When you type that q at the end, it should cause foobar to be printed again. Does that work?

  3. macdanny commented on Aug 15, 2015

    @macdanny
    Author

    I agree that it doesn't do much when run directly, my only point was that it does complete succesfully and it does do something other than printing � (on my terminal that is a box with an x through it).

    I realized after I opened this issue that it goes far beyond commandline. Even very simple functions or commands don't work when invoked from a key binding. For example, the following binding also causes the square to be printed when I hit ctrl-d:

    bind \cd exit

    From my testing it looks like the only bindings that DON'T cause the square to be printed are bindings that invoke functions that are listed by bind --function-names. Everything else prints a square.

    There's still enough functionality in those functions to make fish reasonably useful. I can bind up and down to history-search-backward and history-search-forward, I can bind ctrl-c to kill-whole-line, etc. But there is a lot of functionality that is being left on the table.

    I did have to make a couple of changes to get it to work reasonably well on Cygwin:

    • I had to remove -rdynamic from LDFLAGS_FISH options
    • I changed the default notifier strategy to strategy_shmem_polling

    I tried using the pre-2.2.0 versions, both the one with a package in Cygwin and one I built from the 2.1.2 source myself. It's a non-starter because it crashes too often. This bind issue is a nuisance to be sure but it isn't a showstopper.

  4. changed the title [-]Can't use commandline function in any binding - Cygwin, fish 2.2.0[/-] [+]Can only bind key sequences to functions listed in bind --function-names - Cygwin, fish 2.2.0[/+] on Aug 15, 2015
  5. macdanny commented on Aug 15, 2015

    @macdanny
    Author

    By the way -- I don't know if it's bad form to put this in here but fish is great. I really like the approach you have taken to come up with one set of rules that apply everywhere. This is the first shell I've used that makes sense to me.

  6. ridiculousfish commented on Aug 15, 2015

    @ridiculousfish
    Member

    Thanks for the praise :)

    This is very surprising behavior. I think the place to start looking is in input_mapping_execute. It would be helpful to know the following (e.g. printf debugging). In this function, "functions" refers to readline functions (bind --function-names) and "commands" refers to fish script commands.

    1. Does input_mapping_execute ever run with allow_commands set to true?
    2. If so, does has_commands get set to true?
    3. If so, does principal_parser().eval() execute?

    My speculative guess is that we're being bitten by differences in the width of wchar_t on Windows *nix.

  7. macdanny commented on Aug 16, 2015

    @macdanny
    Author

    Thanks for your guidance. I added some fprintf statements to output the information you suggested. In every case, allow_commands is true, has_commands is false.

  8. macdanny commented on Aug 16, 2015

    @macdanny
    Author

    OK, I added a lot more debugging statements and I have determined that input_function_get_code is definitely returning -1, but input_mapping_execute is definitely interpreting that to mean it is a function. So I changed the code to this, on the assumption that the data type conversion is what was making it fail, and it now works!

        wchar_t test_against = -1;
        for (wcstring_list_t::const_iterator it = m.commands.begin(), end = m.commands.end(); it != end; it++)
        {
            fprintf(stderr, "testing command %S\n", it->c_str());
            if (input_function_get_code(*it) != test_against) {
                fprintf(stderr, "calling it a function\n");
                has_functions = true;
            } else {
                has_commands = true;
            }
        }
  9. ridiculousfish commented on Aug 16, 2015

    @ridiculousfish
    Member

    Nice! We should define a wchar_t constant for not-found.

  10. ridiculousfish commented on Aug 17, 2015

    @ridiculousfish
    Member

    Can you please try e2f16ec (on master or cherry-picked)?

  11. macdanny commented on Aug 17, 2015

    @macdanny
    Author

    It works :)

    Thank you, I really appreciate you looking into this.

    I see the issue with "-rdynamic" was also fixed at some point -- much obliged.

  12. ridiculousfish commented on Aug 17, 2015

    @ridiculousfish
    Member

    Coolio

  13. added this to the milestone on Oct 24, 2015
  14. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions