diff options
| author | Gerry Agbobada <10496163+gagbo@users.noreply.github.com> | 2019-06-25 14:44:29 +0200 |
|---|---|---|
| committer | Gerry Agbobada <gerry.agbobada@external.engie.com> | 2019-06-26 13:04:57 +0200 |
| commit | 556c9a960c902164ef4fe059dfa6f3b19d9154dc (patch) | |
| tree | b348c29e80b0cee098234d89cca24ef6899c4ed7 | |
| parent | c6543667223ee69ff2214a0116cf1883f19de2a1 (diff) | |
Check (display-graphic-p) dynamically in advices
Add an advice for all ivy-posframe-advices
With this advice, we can wrap all ivy-posframe-advice with a function
which will bypass ivy-posframe for any predicate we would like.
(display-graphic-p) is hardcoded for now, but it's unlikely to change.
| -rw-r--r-- | ivy-posframe.el | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/ivy-posframe.el b/ivy-posframe.el index 5392f6e..63c5906 100644 --- a/ivy-posframe.el +++ b/ivy-posframe.el @@ -467,6 +467,20 @@ selection, non-nil otherwise." ;;; Advice +(defun ivy-posframe--posframe-p-advice (advice-fn &rest args) + "Advice function of ADVICE-FN, used to bypass the advice from +`ivy-posframe-advice-alist' if the posframe cannot be displayed. + +ADVICE-FN should be a value from `ivy-posframe-advice-alist', but +the function only errors if ARGS is empty. There should at least be +the advised function there (a key from `ivy-posframe-advice-alist')." + (unless (< 0 (length args)) + (error "This function should advise an advice, so args should be at least a key from ivy-posframe-advice-alist")) + (if (display-graphic-p) + (apply advice-fn args) + (apply (car args) (cdr args))) + ) + (defun ivy-posframe--minibuffer-setup (fn &rest args) "Advice function of FN, `ivy--minibuffer-setup' with ARGS." (let ((ivy-fixed-height-minibuffer nil)) @@ -532,10 +546,14 @@ selection, non-nil otherwise." (let ((advices ivy-posframe-advice-alist)) (if ivy-posframe-mode (mapcar (lambda (elm) - (advice-add (car elm) :around (cdr elm))) + (progn + (advice-add (cdr elm) :around 'ivy-posframe--posframe-p-advice) + (advice-add (car elm) :around (cdr elm)))) advices) (mapcar (lambda (elm) - (advice-remove (car elm) (cdr elm))) + (progn + (advice-remove (cdr elm) 'ivy-posframe--posframe-p-advice) + (advice-remove (car elm) (cdr elm)))) advices)))) ;;;###autoload |
