{"action":"created","issue":{"url":"https://api.github.com/repos/manastech/crystal/issues/1025","labels_url":"https://api.github.com/repos/manastech/crystal/issues/1025/labels{/name}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/1025/comments","events_url":"https://api.github.com/repos/manastech/crystal/issues/1025/events","html_url":"https://github.com/manastech/crystal/pull/1025","id":96529611,"number":1025,"title":"Yield start and finish indices in Readline.autocomplete","user":{"login":"jbbarth","id":29363,"avatar_url":"https://avatars.githubusercontent.com/u/29363?v=3","gravatar_id":"","url":"https://api.github.com/users/jbbarth","html_url":"https://github.com/jbbarth","followers_url":"https://api.github.com/users/jbbarth/followers","following_url":"https://api.github.com/users/jbbarth/following{/other_user}","gists_url":"https://api.github.com/users/jbbarth/gists{/gist_id}","starred_url":"https://api.github.com/users/jbbarth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbbarth/subscriptions","organizations_url":"https://api.github.com/users/jbbarth/orgs","repos_url":"https://api.github.com/users/jbbarth/repos","events_url":"https://api.github.com/users/jbbarth/events{/privacy}","received_events_url":"https://api.github.com/users/jbbarth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-22T10:21:05Z","updated_at":"2015-07-22T13:00:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/manastech/crystal/pulls/1025","html_url":"https://github.com/manastech/crystal/pull/1025","diff_url":"https://github.com/manastech/crystal/pull/1025.diff","patch_url":"https://github.com/manastech/crystal/pull/1025.patch"},"body":"As of today, `Readline.autocomplete` only yields the text sent by\r\nreadline for autocompletion, which only contains the last token inside\r\nthe current buffer. For example:\r\n\r\n  > abc[TAB]\r\n  => will yield \"abc\"\r\n\r\n  > abc [TAB]\r\n  => will yield \"\"\r\n\r\n  > abc def[TAB]\r\n  => will yield \"def\"\r\n\r\nYielding the positional indices of the yielded string inside the current\r\nline buffer is necessary so the library is usable for performing some\r\nuseful autocompletion.\r\n\r\nNote that we could use `Readline.line_buffer` directly to guess the\r\nposition from where the autocompletion request originated, but 1/ it\r\nwouldn't be 100% deterministic, and 2/ this buffer is not updated in\r\nreal-time, so it frequently contains the previous line read by readline\r\ninstead of the current line.\r\n\r\n---\r\n\r\nFwiw, if someone needs this now, you can always patch readline from the outside, [here's what I did](https://github.com/jbbarth/caoutchouc/blob/master/src/patches/readline/autocomplete_yield_start_finish.cr)"},"comment":{"url":"https://api.github.com/repos/manastech/crystal/issues/comments/123711818","html_url":"https://github.com/manastech/crystal/pull/1025#issuecomment-123711818","issue_url":"https://api.github.com/repos/manastech/crystal/issues/1025","id":123711818,"user":{"login":"jbbarth","id":29363,"avatar_url":"https://avatars.githubusercontent.com/u/29363?v=3","gravatar_id":"","url":"https://api.github.com/users/jbbarth","html_url":"https://github.com/jbbarth","followers_url":"https://api.github.com/users/jbbarth/followers","following_url":"https://api.github.com/users/jbbarth/following{/other_user}","gists_url":"https://api.github.com/users/jbbarth/gists{/gist_id}","starred_url":"https://api.github.com/users/jbbarth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbbarth/subscriptions","organizations_url":"https://api.github.com/users/jbbarth/orgs","repos_url":"https://api.github.com/users/jbbarth/repos","events_url":"https://api.github.com/users/jbbarth/events{/privacy}","received_events_url":"https://api.github.com/users/jbbarth/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T13:00:11Z","updated_at":"2015-07-22T13:00:11Z","body":"Actually I have only evidence of line_buffer not updated realtime, and I can only tell for OSX, but I can make more extensive tests if you want.\r\n\r\nHere we go for the code sample: https://gist.github.com/jbbarth/6793347b404b3559e189 ; I use the autocompletion to show that when autocompleting on first character, I still get the previous line buffer, instructions are in \"output.txt\"\r\n\r\nThanks!"}}