2019-09-06 17:40:33 +01:00
|
|
|
;;; fg42-keybindings --- Keybinding helper macros for FG42
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2019 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
;;
|
|
|
|
;; Author: Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
;; URL: https://gitlab.com/FG42/FG42
|
|
|
|
;; Keywords: keybinding
|
|
|
|
;; Version: 0.1.0
|
|
|
|
;;
|
|
|
|
;; 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 <http://www.gnu.org/licenses/>.
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
|
2019-09-09 09:05:36 +01:00
|
|
|
|
|
|
|
(defun -defkey-god (map key fn)
|
|
|
|
"Set the given KEY on key map MAP to FN."
|
|
|
|
(define-key map (kbd key) fn))
|
|
|
|
|
|
|
|
|
|
|
|
(defun -defkey-human (map key fn)
|
|
|
|
"Set the given KEY on key map MAP to FN."
|
|
|
|
(define-key map (kbd key) fn))
|
|
|
|
|
|
|
|
|
2020-03-11 23:26:25 +00:00
|
|
|
(defun -defkey-evil (map state-keys fn)
|
|
|
|
"Set the given STATE-KEYS on key map MAP to FN."
|
2020-03-12 17:32:22 +00:00
|
|
|
(let ((normal-key (plist-get state-keys :normal))
|
2020-03-11 23:50:57 +00:00
|
|
|
(visual-key (plist-get state-keys :visual))
|
|
|
|
(insert-key (plist-get state-keys :insert))
|
2020-03-12 02:08:05 +00:00
|
|
|
(emacs-key (plist-get state-keys :emacs)))
|
2020-03-12 17:32:22 +00:00
|
|
|
(cond
|
2020-03-15 11:53:06 +00:00
|
|
|
((not (null normal-key)) (evil-define-key 'normal map (kbd normal-key) fn))
|
|
|
|
((not (null visual-key)) (evil-define-key 'visual map (kbd visual-key) fn))
|
|
|
|
((not (null insert-key)) (evil-define-key 'insert map (kbd insert-key) fn))
|
|
|
|
((not (null emacs-key)) (evil-define-key 'emacs map (kbd emacs-key) fn)))))
|
2019-09-09 09:05:36 +01:00
|
|
|
|
|
|
|
|
2020-03-12 17:32:22 +00:00
|
|
|
(defmacro defkey (map fn &rest keys)
|
2019-09-06 17:40:33 +01:00
|
|
|
"Defines a key binding for FG42 for different types.
|
2019-09-09 09:05:36 +01:00
|
|
|
Defines a keybinding in the given MAP for the given KEYS that maps
|
2019-09-06 17:40:33 +01:00
|
|
|
to the given FN with the given DOCSTRING.
|
2020-03-15 11:53:06 +00:00
|
|
|
Example usage :
|
|
|
|
\\(defkey `'global-map`' 'goto-line
|
|
|
|
:evil \\(:normal \"SPC s u\"\\)
|
|
|
|
:god \"<f2>\"\\)"
|
2019-09-09 09:05:36 +01:00
|
|
|
(let ((god-key (plist-get keys :god))
|
|
|
|
(human-key (plist-get keys :human))
|
2020-03-11 23:26:25 +00:00
|
|
|
(evil-state-key (plist-get keys :evil)))
|
2020-03-19 23:07:44 +00:00
|
|
|
(when (and (is-evil?) (null evil-state-key)) (error "You should pass :evil keys when you are evil user"))
|
|
|
|
(when (and (is-god?) (null god-key)) (error "You should pass :god keys when you are a god user"))
|
|
|
|
(when (and (is-human?) (null human-key)) (error "You should pass :evil keys when you are a human user"))
|
2019-09-09 09:05:36 +01:00
|
|
|
(cond
|
2020-03-12 17:32:22 +00:00
|
|
|
((is-god?) `(-defkey-god ,map ,god-key ,fn))
|
|
|
|
((is-human?) `(-defkey-human ,map ,human-key ,fn))
|
|
|
|
((is-evil?) `(-defkey-evil ,map (quote ,evil-state-key) ,fn)))))
|
2020-03-15 11:53:06 +00:00
|
|
|
|
2019-09-06 17:40:33 +01:00
|
|
|
(provide 'fg42/key-bindings)
|
|
|
|
;;; key-bindings.el ends here
|