2016-01-04 19:17:35 +00:00
|
|
|
;;; packages.el --- Spacemacs Core Layer packages File
|
|
|
|
;;
|
2016-01-12 02:40:54 +00:00
|
|
|
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
|
2016-01-04 19:17:35 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
(setq spacemacs-ivy-packages
|
2016-02-01 18:24:58 +00:00
|
|
|
'(auto-highlight-symbol
|
|
|
|
counsel
|
2016-01-04 19:17:35 +00:00
|
|
|
flx
|
2016-01-09 20:29:37 +00:00
|
|
|
;; hack since ivy is part for swiper but I like to
|
|
|
|
;; treat it as a stand-alone package
|
|
|
|
(ivy :location built-in)
|
2016-01-04 19:17:35 +00:00
|
|
|
(ivy-spacemacs-help :location local)
|
|
|
|
smex
|
2016-02-11 21:21:46 +00:00
|
|
|
swiper
|
|
|
|
wgrep))
|
2016-01-04 19:17:35 +00:00
|
|
|
|
|
|
|
(defun spacemacs-ivy/init-counsel ()
|
|
|
|
(defvar spacemacs--counsel-commands
|
2016-02-11 21:21:46 +00:00
|
|
|
'(("ag" . "ag --nocolor --nogroup %s %S .")
|
|
|
|
("pt" . "pt -e --nocolor --nogroup %s %S .")
|
|
|
|
("ack" . "ack --nocolor --nogroup %s %S .")
|
2016-01-23 00:49:26 +00:00
|
|
|
("grep" . "grep -nrP %s %S ."))
|
2016-01-04 19:17:35 +00:00
|
|
|
"Alist of search commands and their corresponding commands
|
|
|
|
with options to run in the shell.")
|
|
|
|
|
|
|
|
(defvar spacemacs--counsel-search-max-path-length 30
|
|
|
|
"Truncate the current path in counsel search if it is longer
|
|
|
|
than this amount.")
|
|
|
|
|
2016-01-22 17:47:08 +00:00
|
|
|
(defvar spacemacs--counsel-initial-cands-shown nil)
|
|
|
|
(defvar spacemacs--counsel-initial-number-cand 100)
|
|
|
|
|
|
|
|
(defun spacemacs//counsel-async-command (cmd)
|
|
|
|
(let* ((counsel--process " *counsel*")
|
|
|
|
(proc (get-process counsel--process))
|
|
|
|
(buff (get-buffer counsel--process)))
|
|
|
|
(when proc
|
|
|
|
(delete-process proc))
|
|
|
|
(when buff
|
|
|
|
(kill-buffer buff))
|
|
|
|
(setq proc (start-process-shell-command
|
|
|
|
counsel--process
|
|
|
|
counsel--process
|
|
|
|
cmd))
|
|
|
|
(setq spacemacs--counsel-initial-cands-shown nil)
|
|
|
|
(setq counsel--async-time (current-time))
|
|
|
|
(set-process-sentinel proc #'counsel--async-sentinel)
|
|
|
|
(set-process-filter proc #'spacemacs//counsel-async-filter)))
|
|
|
|
|
|
|
|
(defun spacemacs//counsel-async-filter (process str)
|
|
|
|
(with-current-buffer (process-buffer process)
|
|
|
|
(insert str))
|
|
|
|
(when (or (null spacemacs--counsel-initial-cands-shown)
|
|
|
|
(time-less-p
|
|
|
|
;; 0.5s
|
|
|
|
'(0 0 500000 0)
|
|
|
|
(time-since counsel--async-time)))
|
|
|
|
(let (size display-now)
|
|
|
|
(with-current-buffer (process-buffer process)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(setq size (- (buffer-size) (forward-line (buffer-size))))
|
|
|
|
(when (and (null spacemacs--counsel-initial-cands-shown)
|
|
|
|
(> size spacemacs--counsel-initial-number-cand))
|
|
|
|
(setq ivy--all-candidates
|
|
|
|
(split-string (buffer-string) "\n" t))
|
|
|
|
(setq display-now t)
|
|
|
|
(setq spacemacs--counsel-initial-cands-shown t)))
|
|
|
|
(let ((ivy--prompt
|
|
|
|
(format (ivy-state-prompt ivy-last)
|
|
|
|
size)))
|
|
|
|
(if display-now
|
|
|
|
(ivy--insert-minibuffer
|
|
|
|
(ivy--format ivy--all-candidates))
|
|
|
|
(ivy--insert-prompt))))
|
|
|
|
(setq counsel--async-time (current-time))))
|
|
|
|
|
2016-02-14 00:30:30 +00:00
|
|
|
(defvar spacemacs--counsel-search-cmd)
|
|
|
|
|
2016-01-04 19:17:35 +00:00
|
|
|
;; see `counsel-ag-function'
|
|
|
|
(defun spacemacs//make-counsel-search-function (tool)
|
|
|
|
(lexical-let ((base-cmd
|
|
|
|
(cdr (assoc-string tool spacemacs--counsel-commands))))
|
|
|
|
(lambda (string &optional _pred &rest _unused)
|
|
|
|
"Grep in the current directory for STRING."
|
|
|
|
(if (< (length string) 3)
|
|
|
|
(counsel-more-chars 3)
|
2016-01-23 00:49:26 +00:00
|
|
|
(let* ((default-directory counsel--git-grep-dir)
|
|
|
|
(args (if (string-match-p " -- " string)
|
|
|
|
(let ((split (split-string string " -- ")))
|
|
|
|
(prog1 (pop split)
|
|
|
|
(setq string (mapconcat #'identity split " -- "))))
|
|
|
|
""))
|
|
|
|
(regex (counsel-unquote-regex-parens
|
|
|
|
(setq ivy--old-re
|
|
|
|
(ivy--regex string)))))
|
2016-02-14 00:30:30 +00:00
|
|
|
(setq spacemacs--counsel-search-cmd (format base-cmd args regex))
|
|
|
|
(spacemacs//counsel-async-command spacemacs--counsel-search-cmd)
|
2016-01-04 19:17:35 +00:00
|
|
|
nil)))))
|
|
|
|
|
|
|
|
;; see `counsel-ag'
|
|
|
|
(defun spacemacs/counsel-search
|
|
|
|
(&optional tools use-initial-input initial-directory)
|
|
|
|
"Search using the first available tool in TOOLS. Default tool
|
|
|
|
to try is grep. If INPUT is non nil, use the region or the symbol
|
2016-01-27 14:15:34 +00:00
|
|
|
around point as the initial input. If DIR is non nil start in
|
2016-01-04 19:17:35 +00:00
|
|
|
that directory."
|
|
|
|
(interactive)
|
2016-01-05 10:45:36 +00:00
|
|
|
(require 'counsel)
|
2016-03-11 15:21:34 +00:00
|
|
|
(letf* ((initial-input (if use-initial-input
|
2016-03-12 16:55:29 +00:00
|
|
|
(if (region-active-p)
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(region-beginning) (region-end))
|
|
|
|
(thing-at-point 'symbol t))
|
2016-03-11 15:21:34 +00:00
|
|
|
""))
|
2016-01-04 19:17:35 +00:00
|
|
|
(tool (catch 'tool
|
|
|
|
(dolist (tool tools)
|
|
|
|
(when (and (assoc-string tool spacemacs--counsel-commands)
|
|
|
|
(executable-find tool))
|
|
|
|
(throw 'tool tool)))
|
|
|
|
(throw 'tool "grep"))))
|
2016-01-10 18:12:22 +00:00
|
|
|
(setq counsel--git-grep-dir
|
|
|
|
(or initial-directory
|
|
|
|
(read-directory-name "Start from directory: ")))
|
2016-01-04 19:17:35 +00:00
|
|
|
(ivy-read
|
2016-01-22 17:47:08 +00:00
|
|
|
(concat "%-5d "
|
|
|
|
(format "%s from [%s]: "
|
|
|
|
tool
|
|
|
|
(if (< (length counsel--git-grep-dir)
|
|
|
|
spacemacs--counsel-search-max-path-length)
|
|
|
|
counsel--git-grep-dir
|
|
|
|
(concat
|
|
|
|
"..." (substring counsel--git-grep-dir
|
|
|
|
(- (length counsel--git-grep-dir)
|
|
|
|
spacemacs--counsel-search-max-path-length)
|
|
|
|
(length counsel--git-grep-dir))))))
|
2016-01-04 19:17:35 +00:00
|
|
|
(spacemacs//make-counsel-search-function tool)
|
2016-03-08 06:24:59 +00:00
|
|
|
:initial-input (rxt-quote-pcre initial-input)
|
2016-01-04 19:17:35 +00:00
|
|
|
:dynamic-collection t
|
|
|
|
:history 'counsel-git-grep-history
|
|
|
|
:action #'counsel-git-grep-action
|
2016-02-14 00:30:30 +00:00
|
|
|
:caller 'spacemacs/counsel-search
|
2016-01-04 19:17:35 +00:00
|
|
|
:unwind (lambda ()
|
|
|
|
(counsel-delete-process)
|
|
|
|
(swiper--cleanup)))))
|
|
|
|
|
2016-01-09 20:45:15 +00:00
|
|
|
(cl-loop
|
|
|
|
for (tools tool-name) in '((dotspacemacs-search-tools "auto")
|
|
|
|
((list "ag") "ag")
|
|
|
|
((list "pt") "pt")
|
|
|
|
((list "ack") "ack")
|
|
|
|
((list "grep") "grep"))
|
|
|
|
do
|
|
|
|
(eval
|
|
|
|
`(progn
|
|
|
|
(defun ,(intern (format "spacemacs/search-%s" tool-name)) ()
|
|
|
|
,(format
|
|
|
|
"Use `spacemacs/counsel-search' to search in the current
|
|
|
|
directory with %s." (if (string= tool-name "auto")
|
|
|
|
"a tool selected from `dotspacemacs-search-tools'."
|
|
|
|
tool-name))
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/counsel-search ,tools))
|
|
|
|
(defun ,(intern (format "spacemacs/search-%s-region-or-symbol"
|
|
|
|
tool-name)) ()
|
|
|
|
,(format
|
|
|
|
"Use `spacemacs/counsel-search' to search for
|
2016-01-27 14:15:34 +00:00
|
|
|
the selected region or the symbol around point in the current
|
2016-01-09 20:45:15 +00:00
|
|
|
directory with %s." (if (string= tool-name "auto")
|
|
|
|
"a tool selected from `dotspacemacs-search-tools'."
|
|
|
|
tool-name))
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/counsel-search ,tools t))
|
|
|
|
(defun ,(intern (format "spacemacs/search-project-%s" tool-name)) ()
|
|
|
|
,(format
|
|
|
|
"Use `spacemacs/counsel-search' to search in the current
|
|
|
|
project with %s." (if (string= tool-name "auto")
|
|
|
|
"a tool selected from `dotspacemacs-search-tools'."
|
|
|
|
tool-name))
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/counsel-search ,tools nil (projectile-project-root)))
|
|
|
|
(defun ,(intern (format "spacemacs/search-project-%s-region-or-symbol"
|
|
|
|
tool-name)) ()
|
|
|
|
,(format
|
|
|
|
"Use `spacemacs/counsel-search' to search for
|
2016-01-27 14:15:34 +00:00
|
|
|
the selected region or the symbol around point in the current
|
2016-01-09 20:45:15 +00:00
|
|
|
project with %s." (if (string= tool-name "auto")
|
|
|
|
"a tool selected from `dotspacemacs-search-tools'."
|
|
|
|
tool-name))
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/counsel-search ,tools t (projectile-project-root))))))
|
2016-01-04 19:17:35 +00:00
|
|
|
|
2016-02-14 00:30:30 +00:00
|
|
|
(defun spacemacs//counsel-occur ()
|
|
|
|
"Generate a custom occur buffer for `counsel-git-grep'."
|
|
|
|
(ivy-occur-grep-mode)
|
|
|
|
(setq default-directory counsel--git-grep-dir)
|
|
|
|
(let ((cands ivy--old-cands))
|
|
|
|
;; Need precise number of header lines for `wgrep' to work.
|
|
|
|
(insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
|
|
|
|
default-directory))
|
|
|
|
(insert (format "%d candidates:\n" (length cands)))
|
|
|
|
(ivy--occur-insert-lines
|
|
|
|
(mapcar
|
|
|
|
(lambda (cand) (concat "./" cand))
|
|
|
|
ivy--old-cands))))
|
|
|
|
|
|
|
|
(with-eval-after-load 'ivy
|
|
|
|
(ivy-set-occur 'spacemacs/counsel-search
|
|
|
|
'spacemacs//counsel-occur))
|
|
|
|
|
2016-01-18 19:11:33 +00:00
|
|
|
(defun spacemacs/counsel-search-docs ()
|
|
|
|
"Search spacemacs docs using `spacemacs/counsel-search'"
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/counsel-search dotspacemacs-search-tools
|
|
|
|
nil spacemacs-docs-directory))
|
|
|
|
|
2016-01-04 19:17:35 +00:00
|
|
|
(defun spacemacs/counsel-git-grep-region-or-symbol ()
|
|
|
|
"Use `counsel-git-grep' to search for the selected region or
|
2016-01-27 14:15:34 +00:00
|
|
|
the symbol around point in the current project with git grep."
|
2016-02-11 01:22:50 +00:00
|
|
|
(interactive)
|
2016-01-04 19:17:35 +00:00
|
|
|
(let ((input (if (region-active-p)
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(region-beginning) (region-end))
|
|
|
|
(thing-at-point 'symbol t))))
|
|
|
|
(counsel-git-grep nil input)))
|
|
|
|
|
2016-01-07 17:50:21 +00:00
|
|
|
(defun spacemacs//ivy-command-not-implemented-yet (key)
|
|
|
|
(lexical-let ((-key key))
|
|
|
|
(spacemacs/set-leader-keys
|
|
|
|
-key (lambda ()
|
2016-01-09 20:45:15 +00:00
|
|
|
(interactive)
|
|
|
|
(message "The command usually bound to %s %s has \
|
|
|
|
not been implemented for the spacemacs-ivy layer yet."
|
|
|
|
dotspacemacs-leader-key -key)))))
|
2016-01-07 17:50:21 +00:00
|
|
|
|
2016-01-04 19:17:35 +00:00
|
|
|
(use-package counsel
|
|
|
|
:config
|
2016-01-09 20:45:15 +00:00
|
|
|
(progn
|
2016-01-10 06:20:26 +00:00
|
|
|
(defun spacemacs/describe-mode ()
|
|
|
|
"Dummy wrapper to prevent an key binding error from helm.
|
|
|
|
|
|
|
|
By default the emacs leader is M-m, turns out that Helm does this:
|
|
|
|
|
|
|
|
(cl-dolist (k (where-is-internal 'describe-mode global-map))
|
|
|
|
(define-key map k 'helm-help))
|
|
|
|
|
|
|
|
after doing this:
|
|
|
|
|
|
|
|
(define-key map (kbd \"M-m\") 'helm-toggle-all-marks)
|
|
|
|
|
|
|
|
So when Helm is loaded we get the error:
|
|
|
|
|
|
|
|
Key sequence M-m h d m starts with non-prefix key M-m
|
|
|
|
|
|
|
|
To prevent this error we just wrap `describe-mode' to defeat the
|
|
|
|
Helm hack."
|
|
|
|
(interactive)
|
|
|
|
(call-interactively 'describe-mode))
|
|
|
|
|
2016-01-13 05:15:11 +00:00
|
|
|
(define-key counsel-find-file-map (kbd "C-h") 'counsel-up-directory)
|
2016-01-09 20:45:15 +00:00
|
|
|
(spacemacs/set-leader-keys
|
2016-01-10 06:22:49 +00:00
|
|
|
dotspacemacs-emacs-command-key 'counsel-M-x
|
2016-01-09 20:45:15 +00:00
|
|
|
;; files
|
|
|
|
"ff" 'counsel-find-file
|
|
|
|
"fL" 'counsel-locate
|
|
|
|
;; help
|
2016-01-12 14:35:33 +00:00
|
|
|
"?" 'counsel-descbinds
|
2016-01-09 20:45:15 +00:00
|
|
|
"hdf" 'counsel-describe-function
|
2016-01-10 06:20:26 +00:00
|
|
|
"hdm" 'spacemacs/describe-mode
|
2016-01-09 20:45:15 +00:00
|
|
|
"hdv" 'counsel-describe-variable
|
2016-01-18 19:11:33 +00:00
|
|
|
"hR" 'spacemacs/counsel-search-docs
|
2016-01-09 20:45:15 +00:00
|
|
|
;; insert
|
|
|
|
"iu" 'counsel-unicode-char
|
|
|
|
;; jump
|
|
|
|
;; projects
|
|
|
|
"pp" 'projectile-switch-project
|
2016-01-21 08:18:50 +00:00
|
|
|
"pv" 'projectile-vc
|
2016-01-10 18:12:22 +00:00
|
|
|
;; register/ring
|
|
|
|
"ry" 'counsel-yank-pop
|
2016-01-09 20:45:15 +00:00
|
|
|
;; jumping
|
|
|
|
"sj" 'counsel-imenu
|
|
|
|
;; themes
|
|
|
|
"Tc" 'counsel-load-theme
|
|
|
|
;; search
|
|
|
|
"/" 'spacemacs/search-project-auto
|
|
|
|
"*" 'spacemacs/search-project-auto-region-or-symbol
|
|
|
|
"sf" 'spacemacs/search-auto
|
|
|
|
"sF" 'spacemacs/search-auto-region-or-symbol
|
2016-01-11 04:00:20 +00:00
|
|
|
"sp" 'spacemacs/search-project-auto
|
|
|
|
"sP" 'spacemacs/search-project-auto-region-or-symbol
|
2016-01-09 20:45:15 +00:00
|
|
|
"saf" 'spacemacs/search-ag
|
|
|
|
"saF" 'spacemacs/search-ag-region-or-symbol
|
|
|
|
"sap" 'spacemacs/search-project-ag
|
|
|
|
"saP" 'spacemacs/search-project-ag-region-or-symbol
|
|
|
|
"stf" 'spacemacs/search-pt
|
|
|
|
"stF" 'spacemacs/search-pt-region-or-symbol
|
|
|
|
"stp" 'spacemacs/search-project-pt
|
|
|
|
"stP" 'spacemacs/search-project-pt-region-or-symbol
|
|
|
|
"sgf" 'spacemacs/search-grep
|
|
|
|
"sgF" 'spacemacs/search-grep-region-or-symbol
|
|
|
|
"sgp" 'counsel-git-grep
|
|
|
|
"sgP" 'spacemacs/counsel-git-grep-region-or-symbol
|
|
|
|
"skf" 'spacemacs/search-ack
|
|
|
|
"skF" 'spacemacs/search-ack-region-or-symbol
|
|
|
|
"skp" 'spacemacs/search-project-ack
|
|
|
|
"skP" 'spacemacs/search-project-ack-region-or-symbol)
|
2016-03-03 16:51:22 +00:00
|
|
|
|
|
|
|
;; remaps built-in commands that have a counsel replacement
|
|
|
|
(counsel-mode 1)
|
2016-03-06 04:24:51 +00:00
|
|
|
(spacemacs|hide-lighter counsel-mode)
|
2016-01-12 14:35:33 +00:00
|
|
|
|
|
|
|
;; Note: Must be set before which-key is loaded.
|
|
|
|
(setq prefix-help-command 'counsel-descbinds)
|
2016-01-09 20:45:15 +00:00
|
|
|
;; TODO: Commands to port
|
|
|
|
(spacemacs//ivy-command-not-implemented-yet "jI"))))
|
2016-01-04 19:17:35 +00:00
|
|
|
|
2016-02-01 18:24:58 +00:00
|
|
|
(defun spacemacs-ivy/post-init-auto-highlight-symbol ()
|
|
|
|
(setq spacemacs-symbol-highlight-transient-state-remove-bindings
|
|
|
|
'("/" "b" "f"))
|
|
|
|
(setq spacemacs-symbol-highlight-transient-state-add-bindings
|
|
|
|
'(("/" spacemacs/search-project-auto-region-or-symbol :exit t)
|
|
|
|
("b" spacemacs/swiper-all-region-or-symbol :exit t)
|
|
|
|
("f" spacemacs/search-auto-region-or-symbol :exit t))))
|
|
|
|
|
2016-01-04 19:17:35 +00:00
|
|
|
(defun spacemacs-ivy/init-flx ())
|
|
|
|
|
2016-01-09 20:29:37 +00:00
|
|
|
(defun spacemacs-ivy/init-ivy ()
|
2016-01-04 19:17:35 +00:00
|
|
|
(use-package ivy
|
|
|
|
:config
|
2016-01-09 20:29:37 +00:00
|
|
|
(progn
|
|
|
|
(spacemacs/set-leader-keys
|
2016-01-23 04:38:14 +00:00
|
|
|
"a'" 'spacemacs/ivy-available-repls
|
2016-01-09 20:29:37 +00:00
|
|
|
"fr" 'ivy-recentf
|
2016-02-17 04:58:44 +00:00
|
|
|
"rl" 'ivy-resume
|
2016-01-09 20:29:37 +00:00
|
|
|
"bb" 'ivy-switch-buffer)
|
2016-01-11 06:27:38 +00:00
|
|
|
(setq ivy-height 15
|
2016-01-22 00:26:03 +00:00
|
|
|
ivy-re-builders-alist '((t . ivy--regex-ignore-order)))
|
2016-01-09 20:29:37 +00:00
|
|
|
(with-eval-after-load 'recentf
|
|
|
|
;; merge recentf and bookmarks into buffer switching. If we set this
|
2016-01-09 20:45:15 +00:00
|
|
|
;; before recentf loads, then ivy-mode loads recentf for us,
|
|
|
|
;; which messes up the spacemacs version of recentf.
|
2016-01-09 20:29:37 +00:00
|
|
|
(setq ivy-use-virtual-buffers t))
|
|
|
|
(when (configuration-layer/package-usedp 'projectile)
|
|
|
|
(setq projectile-completion-system 'ivy))
|
2016-01-09 20:50:23 +00:00
|
|
|
(spacemacs|hide-lighter ivy-mode)
|
2016-01-09 20:29:37 +00:00
|
|
|
(ivy-mode 1)
|
|
|
|
(global-set-key (kbd "C-c C-r") 'ivy-resume)
|
|
|
|
(global-set-key (kbd "<f6>") 'ivy-resume)
|
|
|
|
|
2016-02-07 17:13:19 +00:00
|
|
|
(ido-mode -1)
|
|
|
|
|
2016-02-09 13:57:27 +00:00
|
|
|
;; Occur
|
|
|
|
(with-eval-after-load 'evil
|
|
|
|
(evil-make-overriding-map ivy-occur-mode-map 'normal))
|
|
|
|
|
2016-02-11 21:21:46 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'ivy-occur-grep-mode
|
|
|
|
"w" 'ivy-wgrep-change-to-wgrep-mode)
|
|
|
|
(evil-define-key 'normal wgrep-mode-map ",," 'wgrep-finish-edit)
|
|
|
|
(evil-define-key 'normal wgrep-mode-map ",c" 'wgrep-finish-edit)
|
|
|
|
(evil-define-key 'normal wgrep-mode-map ",a" 'wgrep-abort-changes)
|
|
|
|
(evil-define-key 'normal wgrep-mode-map ",k" 'wgrep-abort-changes)
|
|
|
|
|
2016-01-23 04:38:14 +00:00
|
|
|
(defun spacemacs/ivy-available-repls ()
|
|
|
|
"Show available repls."
|
|
|
|
(interactive)
|
|
|
|
(ivy-read "Repls: "
|
|
|
|
(mapcar #'car spacemacs-repl-list)
|
|
|
|
:action (lambda (candidate)
|
|
|
|
(let ((repl (cdr (assoc candidate spacemacs-repl-list))))
|
|
|
|
(require (car repl))
|
|
|
|
(call-interactively (cdr repl))))))
|
|
|
|
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(defun spacemacs//ivy-hjkl-navigation (style)
|
|
|
|
"Set navigation on 'hjkl' for the given editing STYLE."
|
|
|
|
(cond
|
|
|
|
((eq 'vim style)
|
|
|
|
(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"))
|
|
|
|
;; Move C-h to C-S-h
|
|
|
|
(define-key ivy-minibuffer-map (kbd "C-S-h") help-map)
|
|
|
|
(define-key ivy-minibuffer-map (kbd "C-l") 'ivy-alt-done)
|
|
|
|
(define-key ivy-minibuffer-map (kbd "<escape>")
|
|
|
|
'minibuffer-keyboard-quit))
|
|
|
|
(t
|
2016-01-09 20:29:37 +00:00
|
|
|
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-alt-done)
|
|
|
|
(define-key ivy-minibuffer-map (kbd "C-k") 'ivy-kill-line)
|
|
|
|
(define-key ivy-minibuffer-map (kbd "C-h") nil)
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(define-key ivy-minibuffer-map (kbd "C-l") nil))))
|
|
|
|
(add-hook 'spacemacs-editing-style-hook 'spacemacs//ivy-hjkl-navigation)
|
|
|
|
;; ensure that the correct bindings are set at startup
|
|
|
|
(spacemacs//ivy-hjkl-navigation dotspacemacs-editing-style)
|
2016-02-04 16:57:26 +00:00
|
|
|
|
|
|
|
(defun spacemacs/counsel-up-directory-no-error ()
|
|
|
|
"`counsel-up-directory' ignoring errors."
|
|
|
|
(interactive)
|
|
|
|
(ignore-errors
|
|
|
|
(call-interactively 'counsel-up-directory)))
|
|
|
|
|
|
|
|
(require 'ivy-hydra)
|
|
|
|
(spacemacs|define-transient-state ivy
|
|
|
|
:doc "
|
|
|
|
Move/Resize^^^^ | Select Action^^^^ | Call^^ | Cancel^^ | Toggles
|
|
|
|
--^-^-^-^-------------|--^-^-^-^------------|--^---^-----------|--^-^---------|---------------------
|
|
|
|
[_j_/_k_] by line | [_s_/_w_] next/prev | [_RET_] & done | [_i_] & ins | [_C_] calling: %s(if ivy-calling \"on\" \"off\")
|
|
|
|
[_g_/_G_] first/last | [_a_]^ ^ list all | [_TAB_] alt done | [_q_] & quit | [_m_] matcher: %s(ivy--matcher-desc)
|
|
|
|
[_d_/_u_] pg down/up | ^ ^ ^ ^ | [_c_] & cont | ^ ^ | [_f_] case-fold: %`ivy-case-fold-search
|
|
|
|
[_<_/_>_] resize | ^ ^ ^ ^ | [_o_] occur | ^ ^ | [_t_] truncate: %`truncate-lines
|
|
|
|
[_h_/_l_] out/in dir | ^ ^ ^ ^ | ^ ^ | ^ ^ | ^ ^
|
|
|
|
|
|
|
|
Current Action: %s(ivy-action-name)
|
|
|
|
"
|
|
|
|
:foreign-keys run
|
|
|
|
:bindings
|
|
|
|
;; arrows
|
|
|
|
("j" ivy-next-line)
|
|
|
|
("k" ivy-previous-line)
|
|
|
|
("l" ivy-alt-done)
|
|
|
|
("h" spacemacs/counsel-up-directory-no-error)
|
|
|
|
("g" ivy-beginning-of-buffer)
|
|
|
|
("G" ivy-end-of-buffer)
|
|
|
|
("d" ivy-scroll-up-command)
|
|
|
|
("u" ivy-scroll-down-command)
|
|
|
|
;; actions
|
|
|
|
("q" keyboard-escape-quit :exit t)
|
|
|
|
("C-g" keyboard-escape-quit :exit t)
|
|
|
|
("<escape>" keyboard-escape-quit :exit t)
|
|
|
|
("i" nil)
|
|
|
|
("C-o" nil)
|
|
|
|
("TAB" ivy-alt-done :exit nil)
|
|
|
|
;; ("C-j" ivy-alt-done :exit nil)
|
|
|
|
;; ("d" ivy-done :exit t)
|
|
|
|
("RET" ivy-done :exit t)
|
|
|
|
("c" ivy-call)
|
|
|
|
("C-m" ivy-done :exit t)
|
|
|
|
("C" ivy-toggle-calling)
|
|
|
|
("m" ivy-toggle-fuzzy)
|
|
|
|
(">" ivy-minibuffer-grow)
|
|
|
|
("<" ivy-minibuffer-shrink)
|
|
|
|
("w" ivy-prev-action)
|
|
|
|
("s" ivy-next-action)
|
|
|
|
("a" ivy-read-action)
|
|
|
|
("t" (setq truncate-lines (not truncate-lines)))
|
|
|
|
("f" ivy-toggle-case-fold)
|
|
|
|
("o" ivy-occur :exit t))
|
2016-02-08 02:13:32 +00:00
|
|
|
(define-key ivy-minibuffer-map "\C-o" 'spacemacs/ivy-transient-state/body)
|
|
|
|
|
|
|
|
(defun spacemacs/ivy-perspectives ()
|
|
|
|
"Control Panel for perspectives. Has many actions.
|
|
|
|
If match is found
|
|
|
|
\(default) Select perspective
|
|
|
|
c: Close Perspective(s) <- mark with C-SPC to close more than one-window
|
|
|
|
k: Kill Perspective(s)
|
|
|
|
|
|
|
|
If match is not found
|
|
|
|
<enter> Creates perspective
|
|
|
|
|
|
|
|
Closing doesn't kill buffers inside the perspective while killing
|
|
|
|
perspectives does."
|
|
|
|
(interactive)
|
|
|
|
(ivy-read "Perspective: "
|
|
|
|
(persp-names)
|
|
|
|
:caller 'spacemacs/ivy-perspectives
|
|
|
|
:action (lambda (name)
|
|
|
|
(let ((persp-reset-windows-on-nil-window-conf t))
|
|
|
|
(persp-switch name)
|
|
|
|
(unless
|
|
|
|
(member name
|
|
|
|
(persp-names-current-frame-fast-ordered))
|
|
|
|
(spacemacs/home))))))
|
|
|
|
|
|
|
|
(ivy-set-actions
|
|
|
|
'spacemacs/ivy-perspectives
|
|
|
|
'(("c" persp-kill-without-buffers "Close perspective(s)")
|
|
|
|
("k" persp-kill "Kill perspective(s)")))
|
|
|
|
|
|
|
|
(defun spacemacs/ivy-persp-buffer ()
|
|
|
|
"Switch to perspective buffer using ivy."
|
|
|
|
(interactive)
|
|
|
|
(let (ivy-use-virtual-buffers)
|
|
|
|
(with-persp-buffer-list ()
|
|
|
|
(call-interactively 'ivy-switch-buffer))))
|
|
|
|
|
|
|
|
(defun spacemacs/ivy-persp-close-other ()
|
|
|
|
"Kills perspectives without killing the buffers"
|
|
|
|
(interactive)
|
|
|
|
(ivy-read (format "Close perspective [current %s]: "
|
|
|
|
(spacemacs//current-layout-name))
|
|
|
|
(persp-names)
|
|
|
|
:action 'persp-kill-without-buffers))
|
|
|
|
|
|
|
|
(defun spacemacs/ivy-persp-kill-other ()
|
|
|
|
"Kills perspectives with all their buffers"
|
|
|
|
(interactive)
|
|
|
|
(ivy-read (format "Kill perspective [current %s]: "
|
|
|
|
(spacemacs//current-layout-name))
|
|
|
|
(persp-names)
|
|
|
|
:action 'persp-kill))
|
|
|
|
|
|
|
|
(setq spacemacs-layouts-transient-state-remove-bindings
|
|
|
|
'("b" "l" "C" "X"))
|
|
|
|
(setq spacemacs-layouts-transient-state-add-bindings
|
|
|
|
'(("b" spacemacs/ivy-persp-buffer)
|
|
|
|
("l" spacemacs/ivy-perspectives)
|
|
|
|
("C" spacemacs/ivy-persp-close-other :exit t)
|
|
|
|
("X" spacemacs/ivy-persp-kill-other :exit t))))))
|
2016-01-04 19:17:35 +00:00
|
|
|
|
2016-01-09 20:45:15 +00:00
|
|
|
(defun spacemacs-ivy/init-smex ()
|
|
|
|
(use-package smex
|
|
|
|
:defer t
|
|
|
|
:init (setq-default smex-history-length 32
|
|
|
|
smex-save-file (concat spacemacs-cache-directory
|
|
|
|
".smex-items"))))
|
|
|
|
|
|
|
|
(defun spacemacs-ivy/init-ivy-spacemacs-help ()
|
|
|
|
(use-package ivy-spacemacs-help
|
2016-01-13 05:37:26 +00:00
|
|
|
:commands (ivy-spacemacs-help-dotspacemacs
|
|
|
|
ivy-spacemacs-help
|
|
|
|
ivy-spacemacs-help-faq
|
|
|
|
ivy-spacemacs-help-layers
|
|
|
|
ivy-spacemacs-help-packages
|
|
|
|
ivy-spacemacs-help-docs
|
|
|
|
ivy-spacemacs-help-toggles)
|
2016-01-09 20:45:15 +00:00
|
|
|
:init (spacemacs/set-leader-keys
|
2016-01-13 05:37:26 +00:00
|
|
|
"h ." 'ivy-spacemacs-help-dotspacemacs
|
|
|
|
"h SPC" 'ivy-spacemacs-help
|
|
|
|
"h f" 'ivy-spacemacs-help-faq
|
|
|
|
"h l" 'ivy-spacemacs-help-layers
|
|
|
|
"h p" 'ivy-spacemacs-help-packages
|
|
|
|
"h r" 'ivy-spacemacs-help-docs
|
|
|
|
"h t" 'ivy-spacemacs-help-toggles)))
|
2016-01-09 20:45:15 +00:00
|
|
|
|
2016-01-09 20:29:37 +00:00
|
|
|
(defun spacemacs-ivy/init-swiper ()
|
2016-01-04 19:17:35 +00:00
|
|
|
(use-package swiper
|
|
|
|
:config
|
2016-01-09 20:45:15 +00:00
|
|
|
(progn
|
|
|
|
(defun spacemacs/swiper-region-or-symbol ()
|
2016-01-27 14:15:34 +00:00
|
|
|
"Run `swiper' with the selected region or the symbol
|
|
|
|
around point as the initial input."
|
2016-01-09 20:45:15 +00:00
|
|
|
(interactive)
|
|
|
|
(let ((input (if (region-active-p)
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(region-beginning) (region-end))
|
|
|
|
(thing-at-point 'symbol t))))
|
2016-02-24 05:50:58 +00:00
|
|
|
(swiper input)))
|
2016-01-04 19:17:35 +00:00
|
|
|
|
2016-01-09 20:45:15 +00:00
|
|
|
(defun spacemacs/swiper-all-region-or-symbol ()
|
|
|
|
"Run `swiper-all' with the selected region or the symbol
|
2016-01-27 14:15:34 +00:00
|
|
|
around point as the initial input."
|
2016-01-09 20:45:15 +00:00
|
|
|
(interactive)
|
|
|
|
(ivy-read "Swiper: " (swiper--multi-candidates
|
|
|
|
(cl-remove-if-not
|
|
|
|
#'buffer-file-name
|
|
|
|
(buffer-list)))
|
|
|
|
:initial-input (if (region-active-p)
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(region-beginning) (region-end))
|
|
|
|
(thing-at-point 'symbol t))
|
|
|
|
:action 'swiper-multi-action-2
|
|
|
|
:unwind #'swiper--cleanup
|
|
|
|
:caller 'swiper-multi))
|
2016-01-04 19:17:35 +00:00
|
|
|
|
2016-01-09 20:45:15 +00:00
|
|
|
(spacemacs/set-leader-keys
|
|
|
|
"ss" 'swiper
|
|
|
|
"sS" 'spacemacs/swiper-region-or-symbol
|
|
|
|
"sb" 'swiper-all
|
|
|
|
"sB" 'spacemacs/swiper-all-region-or-symbol)
|
|
|
|
(global-set-key "\C-s" 'swiper))))
|
2016-02-11 21:21:46 +00:00
|
|
|
|
|
|
|
(defun spacemacs-ivy/init-wgrep ())
|