aboutsummaryrefslogtreecommitdiffstats
path: root/oni-ivy.el
blob: bfedcc28dd970ba0f8243849cb59a7fe5fead228 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;; oni-ivy.el --- Ivy configuration                 -*- lexical-binding: t; -*-

;; Copyright (C) 2019  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2021.1123.003513
;; Package-Requires: (ivy oni-prescient oni-hydra ivy-hydra diminish ivy-posframe ivy-prescient)

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Ivy configuration.

;;; Code:

(require 'ivy)
(require 'ivy-hydra)
(require 'ivy-posframe)
(require 'ivy-prescient)

(defun oni-ivy--disable (orig-fun &rest args)
  "Disable ivy while running ORIG-FUN with ARGS."
  (let ((ivy-enabled ivy-mode))
    (unwind-protect
        (progn
          (when ivy-enabled
            (ivy-mode -1))
          (apply orig-fun args))
      (when ivy-enabled
        (ivy-mode 1)))))

(defun ivy-posframe-display-at-frame-bottom-center (str)
  "Display STR in ivy’s posframe at the bottom centre of the current frame."
  (ivy-posframe--display str #'posframe-poshandler-frame-bottom-center))

(when (eq system-type 'windows-nt)
  (with-eval-after-load 'grep
    (add-function :around (symbol-function 'grep-read-files)
                  #'oni-ivy--disable)))

(global-set-key (kbd "C-<up>") 'ivy-push-view)
(global-set-key (kbd "C-<down>") 'ivy-switch-view)

(setq ivy-posframe-style 'frame-bottom-center)

;;;###autoload
(add-hook 'emacs-startup-hook 'ivy-mode)

(ivy-posframe-mode)
(ivy-prescient-mode)

(with-eval-after-load 'ivy-posframe (diminish 'ivy-posframe-mode))
(with-eval-after-load 'ivy (diminish 'ivy-mode))

(provide 'oni-ivy)
;;; oni-ivy.el ends here