4d678386be6a3973b9a71070db4190e6d92a5880
[~bandali/configs] / .emacs.d / lisp / bandali-ivy.el
1 ;;; bandali-ivy.el --- bandali's Ivy setup -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali
4
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: matching
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; My configuration for Ivy and family.
24
25 ;;; Code:
26
27 (run-with-idle-timer 0.3 nil #'require 'ivy)
28 (with-eval-after-load 'ivy
29 ;; ivy
30 (csetq ivy-wrap t
31 ;; ivy-height 14
32 ivy-use-virtual-buffers t
33 ivy-virtual-abbreviate 'abbreviate
34 ivy-count-format "%d/%d ")
35
36 (defvar b/ivy-ignore-buffer-modes
37 '(;; dired-mode
38 ;; magit-mode
39 erc-mode))
40 (defun b/ivy-ignore-buffer-p (str)
41 "Return non-nil if str names a buffer with a major mode
42 derived from one of `b/ivy-ignore-buffer-modes'.
43
44 This function is intended for use with `ivy-ignore-buffers'."
45 (let* ((buf (get-buffer str))
46 (mode (and buf (buffer-local-value 'major-mode buf))))
47 (and mode
48 (apply #'provided-mode-derived-p mode b/ivy-ignore-buffer-modes))))
49 (add-to-list 'ivy-ignore-buffers #'b/ivy-ignore-buffer-p)
50
51 (define-key ivy-minibuffer-map [escape] #'keyboard-escape-quit)
52 (define-key ivy-minibuffer-map [S-up]
53 #'ivy-previous-history-element)
54 (define-key ivy-minibuffer-map [S-down]
55 #'ivy-next-history-element)
56 (define-key ivy-minibuffer-map (kbd "DEL")
57 #'ivy-backward-delete-char)
58
59 (ido-mode -1)
60 (ivy-mode 1)
61
62 ;; swiper
63 (require 'swiper)
64 (global-set-key (kbd "C-S-s") #'swiper-isearch)
65
66 ;; counsel
67 (require 'counsel)
68 (counsel-mode 1)
69 (defalias 'locate #'counsel-locate)
70 (global-set-key (kbd "C-c f r") #'counsel-recentf)
71 (define-key minibuffer-local-map
72 (kbd "C-r") #'counsel-minibuffer-history))
73
74 (provide 'bandali-ivy)
75 ;;; bandali-ivy.el ends here