prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Provide custom implementation of apply_completion

Open
#1,912 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Is there an idiomatic way of overriding the behaviour of apply_completion in Buffer?

I see that the default semantics, which is suitable for most applications, is:

self.delete_before_cursor(-completion.start_position)
self.insert_text(completion.text)

However, I have a kind of niche use-case which would be catered for better if there was an idiomatic way to reliably change this behaviour. For example, the most general interface I can imagine is effectively a function that rewrites the line and cursor position arbitrarily.

I apologise if there's a simple Python trick that I'm unaware of that would permit me to override this (I've tried various modifications to the example autocomplete-with-control-space.py to no avail) or if permitting this could have unintended interactions with other parts of the completer infrastructure that I haven't considered.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Buffer.apply_completion and the autocomplete-with-control-space.py example to understand how completion application is currently reached. Define what an idiomatic customization point should guarantee for arbitrary line and cursor rewrites, including its interaction with the completer infrastructure; the issue is done when that behavior is supported and documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.