szermatt / emacs-bash-completion

Add programmable bash completion to Emacs shell-mode
GNU General Public License v2.0
281 stars 33 forks source link

improve path completion to show only the last path segment #56

Closed taquangtrung closed 2 years ago

taquangtrung commented 2 years ago

Hi,

This is a simple PR to refine the output of path completion by removing the prefix.

For example, here is the screenshot of the current path completion feature: the prefix ~/workspace/rust is duplicated in all completion candidates:

bash-completion-1

And here is the output after applying my PR,

bash-completion-2

Can you review the PR and consider merging it?

Thanks!

szermatt commented 2 years ago

Hi! Thank you for the PR request!

I'm afraid, however, that making such a change would interfere with the proper running of completion. Completion functions in completion-at-point-functions are supposed to return the results with prefix

From https://www.gnu.org/software/emacs/manual/html_node/elisp/Completion-in-Buffers.html:

Additionally, the collection should generally not be pre-filtered based on the current text between start and end, because that is the responsibility of the caller of completion-at-point-functions to do that according to the completion styles it decides to use.

This is because completion is split into two layers: the layer that provides the UI and displays the completion candidate (completion-in-region) and the layer that provides the completion candidate (completion-at-point-function). bash-completion should be fed to completion-at-point-function to provide the completion candidates.

The change you want to make fits into completion-in-region. See the link above for details.

I'm not sure which implementation of completion-in-region you're using. I'd suggest having a look at the value of completion-in-region-function in your Emacs, then customize, replace or even rewrite it.

Luckily, there are pretty nice alternative implementations of completion-in-region-function that you can try :) If you look around, I'm sure you'll find one that works well for you. I'm old-fashioned and use the default Emacs one, without popups. Here's an example: https://github.com/minad/corfu

taquangtrung commented 2 years ago

@szermatt: I see, I got your point on completion-at-point. Thanks for the suggestion to use completion-in-region!