-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
hydra-posframe.el
124 lines (103 loc) · 4.07 KB
/
hydra-posframe.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
;;; hydra-posframe.el --- Display hydra diagnostics at point -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Aya Igarashi
;; Author: Aya Igarashi <[email protected]>
;; URL: https://github.com/Ladicle/hydra-posframe
;; Keywords: convenience, languages, tools
;; Version: 1.0.0
;; Package-Requires: ((emacs "26.1") (hydra "0.14.0") (posframe "1.1.4"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Display hydra message at point using a posframe.
;; Check out the README for more information.
;;; Code:
(require 'hydra)
(require 'posframe)
(defgroup hydra-posframe nil
"Using posframe to show hydra"
:group 'hydra
:prefix "hydra-posframe")
(defcustom hydra-posframe-parameters nil
"The frame parameters used by hydra-posframe."
:type 'string
:group 'hydra-posframe)
(defcustom hydra-posframe-border-width 1
"The border width used by hydra-posframe.
When 0, no border is showed."
:group 'hydra-posframe
:type 'number)
(defcustom hydra-posframe-poshandler 'posframe-poshandler-frame-center
"The poshandler used by hydra-posframe."
:group 'hydra-posframe
:type 'function)
(defcustom hydra-posframe-font nil
"The font used by hydra-posframe.
When nil, Using current frame's font as fallback."
:group 'hydra-posframe
:type 'string)
(defface hydra-posframe-face
'((t :inherit default))
"The background and foreground color of the posframe.
`background' and `foreground` are used in this face."
:group 'hydra-posframe)
(defface hydra-posframe-border-face
'((t (:background "gray50")))
"The border color of the posframe.
Only `background` is used in this face."
:group 'hydra-posframe)
(defvar hydra-posframe-buffer " *hydra-posframe-buffer*"
"The posframe-buffer used by hydra-posframe.")
(defun hydra-posframe-hide-window ()
"Hide the hydra posframe"
(posframe-hide hydra-posframe-buffer))
(defun hydra-posframe-show-window (str)
"Show hydra hints on the posframe"
(posframe-show
hydra-posframe-buffer
:font hydra-posframe-font
:poshandler hydra-posframe-poshandler
:foreground-color (face-foreground 'hydra-posframe-face nil t)
:background-color (face-background 'hydra-posframe-face nil t)
:border-width hydra-posframe-border-width
:border-color (face-attribute 'hydra-posframe-border-face :background)
:string (concat str "\n")
:override-parameters hydra-posframe-parameters)
(let ((current-frame
(buffer-local-value 'posframe--frame
(get-buffer hydra-posframe-buffer))))
(redirect-frame-focus current-frame
(frame-parent current-frame))))
;;;###autoload
(define-minor-mode hydra-posframe-mode
"Display hydra via posframe."
:init-value nil
:global t
:require 'hydra-posframe
:group 'hydra-posframe
(let ((hydra-posframe-list (list 'hydra-posframe
#'hydra-posframe-show-window
#'hydra-posframe-hide-window)))
(if hydra-posframe-mode
(progn
(add-to-list 'hydra-hint-display-alist hydra-posframe-list)
(setq hydra-hint-display-type 'hydra-posframe))
(progn
(setq hydra-hint-display-alist
(delete hydra-posframe-list hydra-hint-display-alist))
(setq hydra-hint-display-type 'lv)))))
;;;###autoload
(defun hydra-posframe-enable ()
"Enable hydra-posframe."
(interactive)
(hydra-posframe-mode 1)
(message "hydra-posframe: suggest use `hydra-posframe-mode` instead."))
(provide 'hydra-posframe)
;;; hydra-posframe.el ends here