Encapsulates multiple cursors functionality in a layer

This commit is contained in:
Codruț Constantin Gușoi 2018-08-04 22:38:05 +03:00
parent afd3c8c127
commit 5c6057226e
7 changed files with 85 additions and 42 deletions

View File

@ -45,6 +45,7 @@ This function should only modify configuration layer settings."
emacs-lisp
;; git
;; markdown
multiple-cursors
neotree
;; org
;; (shell :variables

View File

View File

@ -0,0 +1,15 @@
;; -*- lexical-binding: t -*-
;;
;;; config.el --- Spacemacs Multiple Cursors Layer packages File
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Codruț Constantin Gușoi <codrut.gusoi@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defvar multiple-cursors-backend 'evil-mc
"The package used as the backend for multiple cursors functionality.")

View File

@ -0,0 +1,34 @@
;; -*- lexical-binding: t -*-
;;
;;; funcs.el --- Spacemacs Multiple Cursors Layer packages File
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Codruț Constantin Gușoi <codrut.gusoi@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun spacemacs//paste-transient-state-p ()
"Return non-nil if the paste transient state is enabled."
(and dotspacemacs-enable-paste-transient-state
(or (not (fboundp 'evil-mc-get-cursor-count))
(eq (evil-mc-get-cursor-count) 1))))
(defun spacemacs/evil-mc-paste-after (&optional count register)
"Disable paste transient state if there is more than 1 cursor."
(interactive "p")
(setq this-command 'evil-paste-after)
(if (spacemacs//paste-transient-state-p)
(spacemacs/paste-transient-state/evil-paste-after)
(evil-paste-after count (or register evil-this-register))))
(defun spacemacs/evil-mc-paste-before (&optional count register)
"Disable paste transient state if there is more than 1 cursor."
(interactive "p")
(setq this-command 'evil-paste-before)
(if (spacemacs//paste-transient-state-p)
(spacemacs/paste-transient-state/evil-paste-before)
(evil-paste-before count (or register evil-this-register))))

View File

@ -0,0 +1,35 @@
;; -*- lexical-binding: t -*-
;;
;;; packages.el --- Spacemacs Multiple Cursors Layer packages File
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Codruț Constantin Gușoi <codrut.gusoi@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq multiple-cursors-packages
'(evil-mc
))
(defun multiple-cursors/init-evil-mc ()
(use-package evil-mc
:config
(progn
(setq evil-mc-one-cursor-show-mode-line-text nil)
(when (or (spacemacs/system-is-mac) (spacemacs/system-is-mswindows))
(setq evil-mc-enable-bar-cursor nil))
;; evil-mc is not compatible with the paste transient state
(define-key evil-normal-state-map "p" 'spacemacs/evil-mc-paste-after)
(define-key evil-normal-state-map "P" 'spacemacs/evil-mc-paste-before)
(dolist (state-map `(,evil-normal-state-map ,evil-insert-state-map))
(dolist (keybinding `((,(kbd "C-M-j") . evil-mc-make-cursor-move-next-line)
(,(kbd "C-M-k") . evil-mc-make-cursor-move-prev-line)))
(define-key state-map (car keybinding) (cdr keybinding))))
(global-evil-mc-mode 1))))

View File

@ -80,31 +80,6 @@ Otherwise, revert to the default behavior (i.e. enable `evil-insert-state')."
(when buffer-read-only
(spacemacs/disable-vi-tilde-fringe)))
;; multiple-cursors
(defun spacemacs//paste-transient-state-p ()
"Return non-nil if the paste transient state is enabled."
(and dotspacemacs-enable-paste-transient-state
(or (not (fboundp 'evil-mc-get-cursor-count))
(eq (evil-mc-get-cursor-count) 1))))
(defun spacemacs/evil-mc-paste-after (&optional count register)
"Disable paste transient state if there is more than 1 cursor."
(interactive "p")
(setq this-command 'evil-paste-after)
(if (spacemacs//paste-transient-state-p)
(spacemacs/paste-transient-state/evil-paste-after)
(evil-paste-after count (or register evil-this-register))))
(defun spacemacs/evil-mc-paste-before (&optional count register)
"Disable paste transient state if there is more than 1 cursor."
(interactive "p")
(setq this-command 'evil-paste-before)
(if (spacemacs//paste-transient-state-p)
(spacemacs/paste-transient-state/evil-paste-before)
(evil-paste-before count (or register evil-this-register))))
;; lisp state

View File

@ -21,10 +21,6 @@
evil-indent-plus
evil-lion
evil-lisp-state
;; for testing purpose, contribute by reporting bugs and sending PRs
;; to https://github.com/gabesoft/evil-mc
;; To enable it add `(global-evil-mc-mode)' to user-config function
evil-mc
evil-nerd-commenter
evil-matchit
evil-numbers
@ -209,19 +205,6 @@
(setq evil-lisp-state-global t))
:config (spacemacs/set-leader-keys "k" evil-lisp-state-map)))
(defun spacemacs-evil/init-evil-mc ()
(use-package evil-mc
:defer t
:init
(progn
;; evil-mc is not compatible with the paste transient state
(define-key evil-normal-state-map "p" 'spacemacs/evil-mc-paste-after)
(define-key evil-normal-state-map "P" 'spacemacs/evil-mc-paste-before)
(setq evil-mc-one-cursor-show-mode-line-text nil)
(when (or (spacemacs/system-is-mac) (spacemacs/system-is-mswindows))
(setq evil-mc-enable-bar-cursor nil)))))
;; other commenting functions in funcs.el with keybinds in keybindings.el
(defun spacemacs-evil/init-evil-nerd-commenter ()
(use-package evil-nerd-commenter