sebastiencs / company-box

A company front-end with icons
561 stars 64 forks source link

company-box display error on org-contacts completion #128

Closed stardiviner closed 4 years ago

stardiviner commented 4 years ago

When I type name in the To: field of mu4e compose mode. I got error after toggled debug-on-error. Here is the backtrace:

Debugger entered--Lisp error: (args-out-of-range 0 24)
  put-text-property(0 24 mouse-face (company-tooltip-mouse) "唐鳳 <audreyt@audreyt.or")
  font-lock--add-text-property(0 24 mouse-face company-tooltip-mouse "唐鳳 <audreyt@audreyt.or" t)
  font-lock-append-text-property(0 24 mouse-face company-tooltip-mouse "唐鳳 <audreyt@audreyt.or")
  company-fill-propertize(#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)) nil 24 nil nil nil)
  company-box--candidate-string(#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)))
  company-box--make-line((#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)) nil 26 0 company-capf))
  apply(company-box--make-line (#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)) nil 26 0 company-capf))
  #f(compiled-function (fn xs) #<bytecode 0x28af7e8362088>)(company-box--make-line ((#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)) nil 26 0 company-capf)))
  -reduce-r-from(#f(compiled-function (fn xs) #<bytecode 0x28af7e8362088>) (#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold))) (company-box--make-line company-box--make-candidate))
  #f(compiled-function (&rest args) #<bytecode -0xf93544d8fd31247>)(#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)))
  mapcar(#f(compiled-function (&rest args) #<bytecode -0xf93544d8fd31247>) [#("Richard Stallman <rms@gnu.org>" 29 30 (font-lock-face bold)) #("Mike Zamansky <zamansky@stuycs.org>" 34 35 (font-lock-face bold)) #("larluo <larluo@clojurians.org>" 29 30 (font-lock-face bold)) #("Bastien Guerry <bzg@gnu.org>" 27 28 (font-lock-face bold)) #("Phil Rooke <phil@yax.org.uk>" 24 25 (font-lock-face bold)) #("Sean Corfield <sean@corfield.org>" 32 33 (font-lock-face bold)) #("Howard Abrams <http://www.howardism.org/formmail/m..." 39 40 (font-lock-face bold)) #("Guido van Rossum <guido@python.org>" 34 35 (font-lock-face bold)) #("Alex Schroeder <alex@gnu.org>" 28 29 (font-lock-face bold)) #("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)) #("Felix Yan <felixonmars@archlinux.org>" 36 37 (font-lock-face bold))])
  company-box--render-lines(1)
  company-box--move-selection(t)
  company-box--display(#("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" 0 1 (company-box-candidate #("Richard Stallman <rms@gnu.org>" 29 30 (font-lock-face bold))) 1 2 (company-box-candidate #("Mike Zamansky <zamansky@stuycs.org>" 34 35 (font-lock-face bold))) 2 3 (company-box-candidate #("larluo <larluo@clojurians.org>" 29 30 (font-lock-face bold))) 3 4 (company-box-candidate #("Bastien Guerry <bzg@gnu.org>" 27 28 (font-lock-face bold))) 4 5 (company-box-candidate #("Phil Rooke <phil@yax.org.uk>" 24 25 (font-lock-face bold))) 5 6 (company-box-candidate #("Sean Corfield <sean@corfield.org>" 32 33 (font-lock-face bold))) 6 7 (company-box-candidate #("Howard Abrams <http://www.howardism.org/formmail/m..." 39 40 (font-lock-face bold))) 7 8 (company-box-candidate #("Guido van Rossum <guido@python.org>" 34 35 (font-lock-face bold))) 8 9 (company-box-candidate #("Alex Schroeder <alex@gnu.org>" 28 29 (font-lock-face bold))) 9 10 (company-box-candidate #("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold))) 10 11 (company-box-candidate #("Felix Yan <felixonmars@archlinux.org>" 36 37 (font-lock-face bold))) 11 12 (company-box-candidate #("Lin Xu <lin@lastquestion.org>" 28 29 (font-lock-face bold))) 12 13 (company-box-candidate #("Mickey Petersen <mickey@masteringemacs.org>" 42 43 (font-lock-face bold))) 13 14 (company-box-candidate #("Manuel Uberti <manuel.uberti@inventati.org>" 42 43 (font-lock-face bold))) 14 15 (company-box-candidate #("Emacs Help <help-gnu-emacs@gnu.org>" 34 35 (font-lock-face bold))) 15 16 (company-box-candidate #("Emacs Devel <emacs-devel@gnu.org>" 32 33 (font-lock-face bold))) ...) nil)
  company-box-show()
  company-box-frontend(show)
  company-call-frontends(show)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer *draft*> #<window 82 on *draft*> 325 116)
  apply(company-idle-begin (#<buffer *draft*> #<window 82 on *draft*> 325 116))
  timer-event-handler([t 24408 19536 289426 nil company-idle-begin (#<buffer *draft*> #<window 82 on *draft*> 325 116) nil 493000])
  read-event(nil t 3)
  sit-for(3)
  flyspell-check-word-p()
  flyspell-post-command-hook()

I can see company-fill-propertize(#("唐鳳 <audreyt@audreyt.org>" 23 24 (font-lock-face bold)) nil 24 nil nil nil) becomes "唐鳳 <audreyt@audreyt.or". Seems somewhere changed the text.

sebastiencs commented 4 years ago

@stardiviner Does https://github.com/sebastiencs/company-box/commit/d28025fa0c833ce85c4cf3c965581914daebfab0 fix your issue ?

stardiviner commented 4 years ago

I pulled commit, and tested with same condition. Still not fixed. I try to get backtrace error log, but I got nothing when I toggle-debug-on-error. And no company auto popup neither. I press [TAB] to manually start company. Only get error:

Company: An error occurred in auto-begin
Company: frontend company-box-frontend error "Args out of range: 0, 26" on command show

Then I try to edebug on company-box--candidate-string. Then press TAB manually, but seems it's not invoked. Then I edbeug on company-box-frontend, and company-box-show. Got error:

Debugger entered--Lisp error: (error "Company: frontend company-box-frontend error \"Args out of range: 0, 26\" on command show")
  signal(error ("Company: frontend company-box-frontend error \"Args..."))
  error("Company: frontend %s error \"%s\" on command %s" company-box-frontend "Args out of range: 0, 26" show)
  company-call-frontends(show)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-manual-begin()
  company-complete()
  funcall-interactively(company-complete)
  call-interactively(company-complete nil nil)
  command-execute(company-complete)

Then I press q in backtrace buffer, then it auto popup another error log:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  company--continue()
  company--perform()
  company-post-command()

Sorry that I can't provide more detailed feedback. Hope this info can help you.

sebastiencs commented 4 years ago

@stardiviner Does the error occur without company-box enabled ?

@dgutov company-fill-propertize throws an error when called with:

(company-fill-propertize "唐鳳 <audreyt@audreyt.org>" nil 24 nil nil nil)
(company-fill-propertize "唐鳳 <audreyt@audreyt.org>" nil 26 nil nil nil)

24 & 26 refers to the result of calling length and string-width on the string.

Is this expected ?

stardiviner commented 4 years ago

@sebastiencs No, company-box popup is fine. Only occur in company-box.

dgutov commented 4 years ago

@sebastiencs Sorry, I can't answer that off the top of my head without debugging with exact example inputs.

company-fill-propertize is a weird function; in essence, it's a part of the default popup frontend so you might as well reimplement it in your frontend as well. It would be good if this function were more stable, but wide characters are a tricky issue. Help cleaning up their handling is welcome.

sebastiencs commented 4 years ago

@dgutov Thanks, I think calling company--clean-string fixes the issue.

@stardiviner Can you test again with https://github.com/sebastiencs/company-box/commit/b056a148558738790c6b9699cc216540b5628540

stardiviner commented 4 years ago

Confirme fixed, :) Thanks @sebastiencs 👍🏻