Subject: bug#50470: 27.1; 'company-mode' 'eshell'

From: <[email-masked]>
Date: Fri, 10 Dec 2021 11:50:09 +0100

Dmitry Gutov <[email-masked]> writes:

> On 09.09.2021 04:57, Dmitry Gutov wrote:
>> Hi!
>> 
>> On 08.09.2021 09:23, Christophe via Bug reports for GNU Emacs, the Swiss 
>> army knife of text editors wrote:
>>> Hello,
>>> when company-mode is activate:
>>> (use-package company
>>>    :ensure t
>>>    :init
>>>    (global-company-mode t)
>>>    )
>>> there are some weird things:
>>> - when you type something, if you enter a single quote a blank space 
>>> is added.
>>> ex: $ ls Images/'
>> 
>> This is unfortunately an old problem. I though there was already a bug 
>> report for it, but couldn't find it. Hope someone will find time to dig 
>> in through the leaky abstraction of c-a-p-f -> pcomplete.
>
> Some new details, from 
> https://github.com/company-mode/company-mode/discussions/1276:
>
> When this happens (the user types a quote character and the tab 
> character is inserted),

In my package capf-autosuggest, I run completion-at-point-functions
somewhat like this:

    (let (;; `pcomplete-completions-at-point' may illegally use
          ;; `completion-in-region' itself instead of returning a collection.
          ;; Let's try to outsmart it.
          (completion-in-region-function
           (lambda (start end collection predicate)
             (throw 'illegal-comp-in-region
                    (list start end collection :predicate predicate))))
          ;; Prevent `pcomplete-completions-at-point' from inserting a TAB
          (buffer-read-only t))
      ;; `ielm-complete-filename' may illegaly move point
      (save-excursion
        (condition-case nil
            (catch 'illegal-comp-in-region
              (run-hook-wrapped 'completion-at-point-functions ...))
          (buffer-read-only nil))))

This way, old style capf functions are prevented from inserting a TAB or
moving point.