Skip to content

Commit

Permalink
spacemacs-core: Fix issues with major-mode-leader
Browse files Browse the repository at this point in the history
Use same hook as evil-leader for major-mode-leader. This fixes an
inconsistency that could arise between the leader key being bound but
the major-mode leader key not being bound (See for example #3000). By
using the same hook as evil-leader-mode, we ensure that either both keys
or bound or neither.

A minor problem that was fixed was `mode-map` and `major-mode-map` were
not let bound and had global scope.
  • Loading branch information
justbur authored and syl20bnr committed Sep 14, 2015
1 parent 18ea193 commit 846fa30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
42 changes: 21 additions & 21 deletions layers/+distribution/spacemacs-core/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,27 @@ used as the prefix command."

(defun spacemacs/activate-major-mode-leader ()
"Bind major mode key map to `dotspacemacs-major-mode-leader-key'."
(setq mode-map (cdr (assoc major-mode evil-leader--mode-maps)))
(when mode-map
(setq major-mode-map (lookup-key mode-map (kbd "m")))
(mapc (lambda (s)
(eval `(define-key
,(intern (format "evil-%S-state-local-map" s))
,(kbd dotspacemacs-major-mode-leader-key)
major-mode-map)))
'(normal motion))
(mapc (lambda (s)
(eval `(define-key
,(intern (format "evil-%S-state-local-map" s))
,(kbd dotspacemacs-major-mode-emacs-leader-key)
major-mode-map)))
'(emacs insert normal motion visual))
;; using `bound-and-true-p', because hybrid-mode may not be loaded when
;; using emacs or vim style
(when (bound-and-true-p hybrid-mode)
(define-key evil-hybrid-state-map
(kbd dotspacemacs-major-mode-emacs-leader-key)
major-mode-map))))
(let* ((mode-map (cdr (assoc major-mode evil-leader--mode-maps)))
(major-mode-map (when mode-map (lookup-key mode-map (kbd "m")))))
(when major-mode-map
(mapc (lambda (s)
(eval `(define-key
,(intern (format "evil-%S-state-local-map" s))
,(kbd dotspacemacs-major-mode-leader-key)
major-mode-map)))
'(normal motion))
(mapc (lambda (s)
(eval `(define-key
,(intern (format "evil-%S-state-local-map" s))
,(kbd dotspacemacs-major-mode-emacs-leader-key)
major-mode-map)))
'(emacs insert normal motion visual))
;; using `bound-and-true-p', because hybrid-mode may not be loaded when
;; using emacs or vim style
(when (bound-and-true-p hybrid-mode)
(define-key evil-hybrid-state-map
(kbd dotspacemacs-major-mode-emacs-leader-key)
major-mode-map)))))

(defun spacemacs/split-and-new-line ()
"Split a quoted string or s-expression and insert a new line with
Expand Down
4 changes: 2 additions & 2 deletions layers/+distribution/spacemacs-core/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ Example: (evil-map visual \"<\" \"<gv\")"
'(emacs insert normal visual motion))
;; experimental: map SPC m to ,
(when dotspacemacs-major-mode-leader-key
(add-hook 'after-change-major-mode-hook
'spacemacs/activate-major-mode-leader)))))
(add-hook 'evil-local-mode-hook
'spacemacs/activate-major-mode-leader t)))))

(defun spacemacs-core/init-evil-surround ()
(use-package evil-surround
Expand Down

0 comments on commit 846fa30

Please sign in to comment.