Title: `readline.set_completer_delims` has no effect with libedit · Issue #112105 · python/cpython · GitHub
Open Graph Title: `readline.set_completer_delims` has no effect with libedit · Issue #112105 · python/cpython
X Title: `readline.set_completer_delims` has no effect with libedit · Issue #112105 · python/cpython
Description: Bug report Bug description: readline.set_completer_delims works fine with GNU readline, but not with libedit. A quick example: import readline readline.set_completer_delims("\n") if "libedit" in getattr(readline, "__doc__", ""): readline...
Open Graph Description: Bug report Bug description: readline.set_completer_delims works fine with GNU readline, but not with libedit. A quick example: import readline readline.set_completer_delims("\n") if "libedit" in ge...
X Description: Bug report Bug description: readline.set_completer_delims works fine with GNU readline, but not with libedit. A quick example: import readline readline.set_completer_delims("\n") if "...
Opengraph URL: https://github.com/python/cpython/issues/112105
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`readline.set_completer_delims` has no effect with libedit","articleBody":"# Bug report\n\n### Bug description:\n\n`readline.set_completer_delims` works fine with GNU readline, but not with libedit.\n\nA quick example:\n\n```python\nimport readline\n\nreadline.set_completer_delims(\"\\n\")\nif \"libedit\" in getattr(readline, \"__doc__\", \"\"):\n readline.parse_and_bind(\"bind ^I rl_complete\")\nelse:\n readline.parse_and_bind(\"tab: complete\")\n\ndef completer(text, state):\n if text == \"$\" and state == 0:\n return \"$complete\"\n return None\n\nreadline.set_completer(completer)\n\ninput()\n# Type $ then \u003ctab\u003e\n```\n\nWith GNU readline, it completes correctly, but with libedit, it can't - libedit still considers `$` as a delimiter. You can confirm that by printing the text in `completer` function.\n\nThe issue is in `readline.c`:\n\nhttps://github.com/python/cpython/blob/d4f83e1e3a19e2f881115f20d58ae6a019ddb48f/Modules/readline.c#L576-L581\n\n`readline.c` writes to `rl_completer_word_break_characters`, which works fine [source](https://git.savannah.gnu.org/cgit/readline.git/tree/complete.c#n1079).\n\nHowever, libedit does not do the same thing, it uses `rl_basic_word_break_characters` [instead](https://opensource.apple.com/source/libedit/libedit-40/src/readline.c):\n\n```C\nif (rl_completion_word_break_hook != NULL)\n\tbreakchars = (*rl_completion_word_break_hook)();\nelse\n\tbreakchars = rl_basic_word_break_characters;\n```\n\nThus, writing to `rl_completer_word_break_characters` will not have any effect on libedit. The simplest way I can think of, is to write to both `rl_completer_word_break_characters` and `rl_basic_word_break_characters`. They both exist in GNU readline and libedit, for slightly different purposes.\n\n* GNU readline:\n * `rl_completer_word_break_characters` is the one that takes effect\n * `rl_basic_word_break_characters` just keeps a string as default value for `rl_completer_word_break_characters`\n* libedit\n * `rl_completer_word_break_characters` is not used at all\n * `rl_basic_word_break_characters` is used for break words\n\nFrom what I can observe, writing to both variables has no unexpected side effect, because `rl_basic_word_break_characters` is not used on CPython with GNU readline.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux, macOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-112106\n* gh-112487\n* gh-112488\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/gaogaotiantian","@type":"Person","name":"gaogaotiantian"},"datePublished":"2023-11-15T04:52:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/112105/cpython/issues/112105"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:990e1e32-e964-f377-5331-87d63bd2bbbe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8DE:3BD8F2:20A6458:2D5A71B:6A4F492A |
| html-safe-nonce | 3413126e38be9538f872b75dbbcd9a67ddc458ff1191fd248413588f74b8489a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOERFOjNCRDhGMjoyMEE2NDU4OjJENUE3MUI6NkE0RjQ5MkEiLCJ2aXNpdG9yX2lkIjoiNTM2MDE5Mzg5Mzg1MjcyNzU5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 653fc36be13d24cd6cb3833da1e7c0f4afe0372d445fc1c73bc37c90013bd45f |
| hovercard-subject-tag | issue:1994042674 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/112105/issue_layout |
| twitter:image | https://opengraph.githubassets.com/184d1be32ea4d5b07a51d249ac140e3c5810ad42257ef22aacb61d6f8a463e56/python/cpython/issues/112105 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/184d1be32ea4d5b07a51d249ac140e3c5810ad42257ef22aacb61d6f8a463e56/python/cpython/issues/112105 |
| og:image:alt | Bug report Bug description: readline.set_completer_delims works fine with GNU readline, but not with libedit. A quick example: import readline readline.set_completer_delims("\n") if "libedit" in ge... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gaogaotiantian |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width