Skip to content

Update Reline core to stay in sync with the line_editor's completion_append_character #756

Open

Description

@sjanusz-r7

Description

When updating Reline.completion_append_character in Reline.completion_proc, the change does not get reflected until you enter a new Reline.readline or Reline.readmultiline context. It seems like the value of Reline.completion_append_character and Reline.line_editor.completion_append_character is out of sync.

Scenario: We are updating the value of Reline.completion_append_character = ' ' inside of the completion_proc, but it's not reflecting in the line_editor

Expected Behaviour

Being able to change Reline.completion_append_character in the completion proc and have it update the line_editor.

i.e. this code:

reline/lib/reline.rb

Lines 83 to 93 in 7534f7f

def completion_append_character=(val)
if val.nil?
@completion_append_character = nil
elsif val.size == 1
@completion_append_character = val.encode(encoding)
elsif val.size > 1
@completion_append_character = val[0].encode(encoding)
else
@completion_append_character = nil
end
end

To immediately update the line_editor's completion_append_character value

    def completion_append_character=(val)
      if val.nil?
        @completion_append_character = nil
      elsif val.size == 1
        @completion_append_character = val.encode(encoding)
      elsif val.size > 1
        @completion_append_character = val[0].encode(encoding)
      else
        @completion_append_character = nil
      end
      # Ensure the line_editor is updated too:
      line_editor.completion_append_character = @completion_append_character
    end

Current Behaviour

Changing Reline.completion_append_character in Reline.completion_append_character does not take effect until a new call to Reline.readline.

Terminal Emulator

MacOS

Reline Version

0.5.10

Activity

  1. tompng commented on Oct 4, 2024

    @tompng
    Member

    Some configurations are hard to make stay in sync.
    For example, this code updates completion_proc itself in completion_proc. It also updates basic_word_break_characters that changes completion target.

    def new_proc(a)
      ->k{
        Readline.completion_proc = new_proc(a.succ)
        Readline.basic_word_break_characters = [';', '.'].sample
        [a]
      }
    end
    Readline.completion_proc = new_proc('a')

    This configurations looks stayed in sync in GNU Readline but not in Reline.
    However, making completion_proc and basic_word_break_characters stay in sync will significantly impairs code maintainability.

    Only changing completion_append_character to be synchronized is not so hard, but I think it is not a good idea to guarantee it to be stay in sync.

    In my opinion, it feel like changing completion_append_character inside completion_proc is a hack that only works in the current version of GNU Readline.

  2. sjanusz-r7 commented on Oct 14, 2024

    @sjanusz-r7
    Author

    In my opinion, it feel like changing completion_append_character inside completion_proc is a hack that only works in the current version of GNU Readline.

    What would be a more idiomatic Reline solution? For our use case - the scenario is: Some of our completions require a different value for completion_append_character

    It looks like currently GNU Readline and RbReadline support this functionality, but it's not supported by Reline unfortunately without a patch to sync the Readline and line_editor values

    As a feature request - if there was a different API to tell Reline about individual append characters as part of the completion_proc result that would be great

  3. tompng commented on Oct 14, 2024

    @tompng
    Member

    I think this is a bug that should be fixed an incompatibility to readline only because GNU Readline documents that rl_completion_append_character can be changed from completion function.

    From GNU Readline's documentation https://tiswww.case.edu/php/chet/readline/readline.html#index-rl_005fcompletion_005fappend_005fcharacter

    When a single completion alternative matches at the end of the command line, this character is appended to the inserted completion text. The default is a space character (‘ ’). Setting this to the null character (‘\0’) prevents anything being appended automatically. This can be changed in application-specific completion functions to provide the “most sensible word separator character” according to an application-specific command line syntax specification. It is set to the default before any application-specific completion function is called, and may only be changed within such a function.

    rl_completion_append_character can only be set from completion function and always reset to default value before completion function is called.
    Note that the documented behavior is reported as a bug in Ruby's readline binding and carefully fixed. https://bugs.ruby-lang.org/issues/4635.

  4. reopened this on Oct 14, 2024
  5. added
    enhancementNew feature or request
    and removed
    bugSomething isn't working
    on Oct 23, 2024
  6. ddoherty03 commented on Feb 2, 2025

    @ddoherty03

    I'll second this. As an example, completing file names, I want the append character to be a SPACE if we are currently on a regular file, indicating a complete path, but I want it to be the empty string if we have only completed to a directory, indicating there is more completion to do.

  7. adfoster-r7 commented on May 15, 2026

    @adfoster-r7

    It would be great to have support for this; I wonder if anything has changed in Reline to help support this capability? 👀

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions