;; In case this is run via the mouse, give temporary modes such as
;; isearch a chance to turn off.
(run-hooks 'mouse-leave-buffer-hook)
- (with-current-buffer (window-buffer (posn-window (event-start event)))
- (let ((buffer completion-reference-buffer)
- (base-position completion-base-position)
- (insert-function completion-list-insert-choice-function)
- (completion-no-auto-exit (if no-exit t completion-no-auto-exit))
- (choice (get-text-property (posn-point (event-start event))
- 'completion--string)))
- (unless choice (error "No completion here"))
- (unless (buffer-live-p buffer) (error "Destination buffer is dead"))
- (unless no-quit
- (quit-window nil (posn-window (event-start event))))
- (let ((mstate completions-minibuffer-state))
- (with-current-buffer buffer
- (choose-completion-string
- choice buffer
- (or base-position
- ;; If all else fails, just guess.
- (list (choose-completion-guess-base-position choice)))
- insert-function)
- (or (null mstate)
- (equal mstate (car completion-history))
- (prog1 (push mstate completion-history)
- (run-hooks 'minibuffer-new-completion-input-hook)))))
- (setq completions-minibuffer-state nil))))
+ (let ((buf (if event (window-buffer (posn-window (event-start event)))
+ (current-buffer)))
+ (pos (if event (posn-point (event-start event)) (point))))
+ (with-current-buffer buf
+ (let ((buffer completion-reference-buffer)
+ (base-position completion-base-position)
+ (insert-function completion-list-insert-choice-function)
+ (completion-no-auto-exit (if no-exit t completion-no-auto-exit))
+ (choice (get-text-property pos 'completion--string)))
+ (unless choice (error "No completion here"))
+ (unless (buffer-live-p buffer) (error "Destination buffer is dead"))
+ (unless no-quit
+ (quit-window nil (posn-window (event-start event))))
+ (let ((mstate completions-minibuffer-state))
+ (with-current-buffer buffer
+ (choose-completion-string
+ choice buffer
+ (or base-position
+ ;; If all else fails, just guess.
+ (list (choose-completion-guess-base-position choice)))
+ insert-function)
+ (or (null mstate)
+ (equal mstate (car completion-history))
+ (prog1 (push mstate completion-history)
+ (run-hooks 'minibuffer-new-completion-input-hook)))))
+ (setq completions-minibuffer-state nil)))))
;; Delete the longest partial match for STRING
;; that can be found before POINT.