Skip to content

Commit

Permalink
Merge pull request #64 from purcell/hide-safely-in-terminal
Browse files Browse the repository at this point in the history
Prevent constant errors when enabled in terminal
  • Loading branch information
expez authored Feb 26, 2017
2 parents 639baef + 29d7df2 commit 30197a3
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions company-quickhelp.el
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ be triggered manually using `company-quickhelp-show'."
(`hide
(when company-quickhelp-delay
(company-quickhelp--cancel-timer))
(pos-tip-hide))))
(company-quickhelp--hide))))

(defun company-quickhelp--doc-and-meta (doc)
;; The company backend can either return a buffer with the doc or a
Expand Down Expand Up @@ -152,8 +152,13 @@ currently active `company' completion candidate."
(let ((company-quickhelp-delay 0.01))
(company-quickhelp--set-timer)))

(defun company-quickhelp--hide ()
(when (company-quickhelp-pos-tip-available-p)
(pos-tip-hide)))

(defun company-quickhelp--show ()
(company-quickhelp--ensure-compatibility)
(unless (company-quickhelp-pos-tip-available-p)
(error "company-quickhelp is not available in this emacs version or frame"))
(company-quickhelp--cancel-timer)
(let* ((selected (nth company-selection company-candidates))
(doc (company-quickhelp--doc selected))
Expand Down Expand Up @@ -203,17 +208,13 @@ currently active `company' completion candidate."
(defun company-quickhelp-hide ()
(company-cancel))

(defun company-quickhelp--ensure-compatibility ()
;; Originally this code was in `company-quickhelp-enable' but that
;; caused trouble for --daemon users reported in #16.
(cond
((or (not (fboundp 'x-hide-tip))
(not (fboundp 'x-show-tip)))
(user-error "Company-quickhelp doesn't work on your system.
Most likely this means you're on a mac with an Emacs build using Cocoa instead of X"))
((or (null window-system)
(eq window-system 'pc))
(user-error "Company-quickhelp doesn't work in the terminal"))))

(defun company-quickhelp-pos-tip-available-p ()
"Return t if and only if pos-tip is expected work in the current frame."
(and
(fboundp 'x-hide-tip)
(fboundp 'x-show-tip)
(not (memq window-system (list nil 'pc)))))

(defun company-quickhelp--enable ()
(add-hook 'focus-out-hook #'company-quickhelp-hide)
Expand Down

0 comments on commit 30197a3

Please sign in to comment.