CSRaghunandan

My ivy configuration

Sep 23rd, 2016
1,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.79 KB | None | 0 0
  1. (use-package ivy :ensure t
  2.   :diminish ivy-mode
  3.   :init (setq projectile-completion-system 'ivy)
  4.   :bind
  5.   (:map ivy-mode-map ("C-'" . ivy-avy))
  6.   :config
  7.   (ivy-mode 1)
  8.   (setq ivy-use-virtual-buffers t)
  9.   (setq ivy-height 13)
  10.   (setq ivy-initial-inputs-alist nil)
  11.   (setq ivy-count-format "%d/%d ")
  12.   (setq ivy-virtual-abbreviate 'full) ; Show the full virtual file paths
  13.   (setq ivy-extra-directories '("./")) ; default value: ("../" "./")
  14.   (setq ivy-wrap t)
  15.   (setq ivy-re-builders-alist '((swiper . ivy--regex-plus)
  16.                 (counsel-ag . ivy--regex-plus)
  17.                 (counsel-grep-or-swiper . ivy--regex-plus)
  18.                 (t . ivy--regex-fuzzy))))
  19.  
  20. (use-package counsel-projectile :ensure t
  21.   :bind* (("C-c p p" . counsel-projectile))
  22.   :init
  23.   (setq counsel-projectile-drop-to-switch-project-binding "C-c s p")
  24.   (counsel-projectile-on))
  25.  
  26. (use-package counsel :ensure t
  27.   :bind*
  28.   (("M-x" . counsel-M-x)
  29.    ("C-c d d" . counsel-descbinds)
  30.    ("C-c s s" . counsel-ag)
  31.    ("C-c s d" . counsel-ag-projectile)
  32.    ("C-x C-f" . counsel-find-file)
  33.    ("C-x r f" . counsel-recentf)
  34.    ("C-c g g" . counsel-git)
  35.    ("C-c g G" . counsel-git-grep)
  36.    ("C-x l" . counsel-locate)
  37.    ("C-c g s" . counsel-grep-or-swiper)
  38.    ("C-M-y" . counsel-yank-pop)
  39.    ("C-c C-r" . ivy-resume)
  40.    ("C-c i m" . counsel-imenu)
  41.    ("C-c i M" . ivy-imenu-anywhere)
  42.    ("C-c d s" . describe-symbol)
  43.    :map ivy-minibuffer-map
  44.    ("M-y" . ivy-next-line-and-call))
  45.  
  46.   :config
  47.   (defun reloading (cmd)
  48.     (lambda (x)
  49.       (funcall cmd x)
  50.       (ivy--reset-state ivy-last)))
  51.   (defun given-file (cmd prompt) ; needs lexical-binding
  52.     (lambda (source)
  53.       (let ((target
  54.          (let ((enable-recursive-minibuffers t))
  55.            (read-file-name
  56.         (format "%s %s to:" prompt source)))))
  57.     (funcall cmd source target 1))))
  58.   (defun confirm-delete-file (x)
  59.     (dired-delete-file x 'confirm-each-subdirectory))
  60.  
  61.   (ivy-add-actions
  62.    'counsel-find-file
  63.    `(("c" ,(given-file #'copy-file "Copy") "copy")
  64.      ("d" ,(reloading #'confirm-delete-file) "delete")
  65.      ("m" ,(reloading (given-file #'rename-file "Move")) "move")))
  66.   (ivy-add-actions
  67.    'counsel-projectile-find-file
  68.    `(("c" ,(given-file #'copy-file "Copy") "copy")
  69.      ("d" ,(reloading #'confirm-delete-file) "delete")
  70.      ("m" ,(reloading (given-file #'rename-file "Move")) "move")
  71.      ("b" counsel-find-file-cd-bookmark-action "cd bookmark")))
  72.  
  73.   ;; to make counsel-ag search the root projectile directory.
  74.   (defun counsel-ag-projectile ()
  75.     (interactive)
  76.     (counsel-ag nil (projectile-project-root)))
  77.  
  78.   (setq counsel-find-file-at-point t)
  79.   ;; ignore . files or temporary files
  80.   (setq counsel-find-file-ignore-regexp
  81.     (concat
  82.      ;; File names beginning with # or .
  83.      "\\(?:\\`[#.]\\)"
  84.      ;; File names ending with # or ~
  85.      "\\|\\(?:\\`.+?[#~]\\'\\)")))
Add Comment
Please, Sign In to add comment