From 624b9916d7680278a96d7c638a6420bad1edec21 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 20 Jan 2021 16:25:25 -0800 Subject: Add fallback for hydra display In case posframe can’t be used, when working from a non-graphical client for example, fall back to the default ‘lv’. --- oni-hydra.el | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'oni-hydra.el') diff --git a/oni-hydra.el b/oni-hydra.el index 7960d4c..6c95ca8 100644 --- a/oni-hydra.el +++ b/oni-hydra.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2020.0306.225035 +;; Version: 2021.0120.162336 ;; Package-Requires: (hydra posframe) ;; This program is free software; you can redistribute it and/or modify @@ -27,8 +27,26 @@ ;;; Code: (require 'hydra) - -(setq hydra-hint-display-type 'posframe) +(require 'lv) +(require 'posframe) + +(defun oni-hydra-custom-show (&rest args) + "Use ‘hydra-posframe-show’ when possible, fall back to ‘lv-message’. +ARGS are passed on without modification." + (if (posframe-workable-p) + (apply #'hydra-posframe-show args) + (apply #'lv-message args))) + +(defun oni-hydra-custom-hide (&rest args) + "Use ‘hydra-posframe-hide’ when possible, fall back to ‘lv-delete-window’. +ARGS are passed on without modification." + (if (posframe-workable-p) + (apply #'hydra-posframe-hide args) + (apply #'lv-delete-window args))) + +(add-to-list 'hydra-hint-display-alist '(custom oni-hydra-custom-show oni-hydra-custom-hide)) + +(setq hydra-hint-display-type 'custom) ;;;###autoload(with-eval-after-load 'hydra (require 'oni-hydra)) -- cgit v1.2.3-54-g00ecf