branch: master commit 91fc865360d783d26fe5f486ef691ebd2d63f9dc Author: Nikita Leshenko <nik...@leshenko.net> Commit: Nikita Leshenko <nik...@leshenko.net>
Unread whole command instead of last input The intent of `company--unread-last-input' was to push the current command keys back to `unread-command-events' in order to evaluate them again on the next iteration of the Emacs command loop. This function didn't work for multi-keys commands because `last-input-event' contains the last terminal input event read and not the entire command keys. For example, for the command C-x C-e `last-input-event' would contain C-e. Pushing C-e back to `unread-command-events' would result a different command invoked. Use `(this-command-keys)' instead of `last-input-event' to push the entire key sequence that invoked this command. Also rename the function to make it's intent clearer after this change. --- company.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/company.el b/company.el index 1cb02ab..9c9fb13 100644 --- a/company.el +++ b/company.el @@ -1840,7 +1840,7 @@ each one wraps a part of the input string." (interactive) (company--search-assert-enabled) (company-search-mode 0) - (company--unread-last-input)) + (company--unread-this-command-keys)) (defun company-search-delete-char () (interactive) @@ -1984,7 +1984,7 @@ With ARG, move by that many elements." (if (> company-candidates-length 1) (company-select-next arg) (company-abort) - (company--unread-last-input))) + (company--unread-this-command-keys))) (defun company-select-previous-or-abort (&optional arg) "Select the previous candidate if more than one, else abort @@ -1995,7 +1995,7 @@ With ARG, move by that many elements." (if (> company-candidates-length 1) (company-select-previous arg) (company-abort) - (company--unread-last-input))) + (company--unread-this-command-keys))) (defun company-next-page () "Select the candidate one page further." @@ -2063,7 +2063,7 @@ With ARG, move by that many elements." 0))) t) (company-abort) - (company--unread-last-input) + (company--unread-this-command-keys) nil))) (defun company-complete-mouse (event) @@ -2240,10 +2240,12 @@ character, stripping the modifiers. That character must be a digit." (< (- (window-height) row 2) company-tooltip-limit) (recenter (- (window-height) row 2)))))) -(defun company--unread-last-input () - (when last-input-event - (clear-this-command-keys t) - (setq unread-command-events (list last-input-event)))) +(defun company--unread-this-command-keys () + (when (> (length (this-command-keys)) 0) + (setq unread-command-events (nconc + (listify-key-sequence (this-command-keys)) + unread-command-events)) + (clear-this-command-keys t))) (defun company-show-doc-buffer () "Temporarily show the documentation buffer for the selection."