core: add support for :variables keyword in dotspacemacs-editing-style

Add variable `hybrid-mode-enable-hjkl-bindings` to enable hjkl
navigation in hybrid mode.

example:

dotspacemacs-editing-style '(hybrid :variables
                                     hybrid-mode-enable-hjkl-bindings t
                                     hybrid-mode-default-state 'normal)
This commit is contained in:
syl20bnr 2016-03-16 22:43:50 -04:00
parent c2296f71f8
commit 2d61e5304e
5 changed files with 52 additions and 6 deletions

View file

@ -309,6 +309,30 @@ are caught and signalled to user in spacemacs buffer."
(error-message-string err))
t))))))
(defun dotspacemacs//read-editing-style-config (config)
"Read editing style CONFIG: apply variables and return the editing style.
CONFIG can be the symbol of an editing style or a list where the car is
the symbol of an editing style and the cdr is a list of keyword arguments like
`:variables'."
(cond
((symbolp config) config)
((listp config)
(let ((variables (spacemacs/mplist-get config :variables)))
(while variables
(let ((var (pop variables)))
(if (consp variables)
(condition-case-unless-debug err
(set-default var (eval (pop variables)))
('error
(spacemacs-buffer/append
(format (concat "\nAn error occurred while reading the "
"editing style variable %s "
"(error: %s). Be sure to quote the value "
"if needed.\n") var err))))
(spacemacs-buffer/warning "Missing value for variable %s !"
var)))))
(car config))))
(defun dotspacemacs/sync-configuration-layers (&optional arg)
"Synchronize declared layers in dotfile with spacemacs.
@ -326,6 +350,11 @@ Called with `C-u C-u' skips `dotspacemacs/user-config' _and_ preleminary tests."
(load-file buffer-file-name)
(dotspacemacs|call-func dotspacemacs/init
"Calling dotfile init...")
(dotspacemacs|call-func dotspacemacs/user-init
"Calling dotfile user init...")
(setq dotspacemacs-editing-style
(dotspacemacs//read-editing-style-config
dotspacemacs-editing-style))
(configuration-layer/sync)
(if (member arg '((4) (16)))
(message (concat "Done (`dotspacemacs/user-config' "
@ -539,8 +568,11 @@ error recovery."
(dotspacemacs||let-init-test
(dotspacemacs/init)
(spacemacs//test-var
(lambda (x) (member x '(vim emacs hybrid)))
'dotspacemacs-editing-style "is \'vim, \'emacs or \'hybrid")
(lambda (x) (or (member x '(vim emacs hybrid))
(and (listp x)
(spacemacs/mplist-get x :variables))))
'dotspacemacs-editing-style
"is \'vim, \'emacs or \'hybrid or and list with `:variable' keyword")
(spacemacs//test-var
(lambda (x) (member x '(original cache nil)))
'dotspacemacs-auto-save-file-location (concat "is one of \'original, "

View file

@ -76,6 +76,8 @@
(require 'core-configuration-layer)
(dotspacemacs|call-func dotspacemacs/init "Calling dotfile init...")
(dotspacemacs|call-func dotspacemacs/user-init "Calling dotfile user init...")
(setq dotspacemacs-editing-style (dotspacemacs//read-editing-style-config
dotspacemacs-editing-style))
(configuration-layer/initialize)
;; default theme
(let ((default-theme (car dotspacemacs-themes)))

View file

@ -392,7 +392,9 @@ Removes the automatic guessing of the initial value based on thing at point. "
(defun spacemacs//helm-hjkl-navigation (style)
"Set navigation on 'hjkl' for the given editing STYLE."
(cond
((eq 'vim style)
((or (eq 'vim style)
(and (eq 'hybrid style)
hybrid-mode-enable-hjkl-bindings))
(define-key helm-map (kbd "C-j") 'helm-next-line)
(define-key helm-map (kbd "C-k") 'helm-previous-line)
(define-key helm-map (kbd "C-h") 'helm-next-source)

View file

@ -379,7 +379,9 @@ Helm hack."
(defun spacemacs//ivy-hjkl-navigation (style)
"Set navigation on 'hjkl' for the given editing STYLE."
(cond
((eq 'vim style)
((or (eq 'vim style)
(and (eq 'hybrid style)
hybrid-mode-enable-hjkl-bindings))
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-next-line)
(define-key ivy-minibuffer-map (kbd "C-k") 'ivy-previous-line)
(define-key ivy-minibuffer-map (kbd "C-h") (kbd "DEL"))

View file

@ -31,8 +31,7 @@
(require 'evil)
(defvar hybrid-mode-default-state-backup evil-default-state
"Backup of `evil-default-state'.")
(defvar hybrid-mode-enable-hjkl-bindings)
(defcustom hybrid-mode-default-state 'normal
"Value of `evil-default-state' for hybrid-mode. Set to hybrid
@ -40,6 +39,15 @@ to start in hybrid state (emacs bindings) by default."
:group 'spacemacs
:type 'symbol)
(defcustom hybrid-mode-enable-hjkl-bindings nil
"If non nil then packages configuration should define the
key bindings for hjkl navigation."
:group 'spacemacs
:type 'boolean)
(defvar hybrid-mode-default-state-backup evil-default-state
"Backup of `evil-default-state'.")
(defadvice evil-insert-state (around hybrid-insert-to-hybrid-state disable)
"Forces Hybrid state."
(evil-hybrid-state))