]> code.delx.au - dotemacs/commitdiff
counsel improvements
authorJames Bunton <jbunton@atlassian.com>
Mon, 19 Nov 2018 08:20:54 +0000 (19:20 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Mon, 19 Nov 2018 08:37:12 +0000 (19:37 +1100)
.ignore [new file with mode: 0644]
README_KEYBINDINGS.md
lisp/my-ivy.el
lisp/my-keys.el
packages/swiper
rg-ignore [new file with mode: 0644]

diff --git a/.ignore b/.ignore
new file mode 100644 (file)
index 0000000..3309a4d
--- /dev/null
+++ b/.ignore
@@ -0,0 +1,2 @@
+# ripgrep ignore file
+packages
index c1b590e494951f5ac47a2352e303f0140a1b02fc..97d98fca2f4fa139ab98f58add36ce46ffb653b3 100644 (file)
@@ -40,6 +40,7 @@ M-i                                             Insert selected item (while sear
 M-q                                             Replace searched item (while searching)
 M-p                                             Search for previous item (while searching)
 M-n                                             Search for symbol at point (while searching)
+C-M-A                                           Read Ivy action
 C-c C-o                                         Dump all results into a buffer (ivy-occur)
 C-c C-p                                         Switch to wgrep mode
 M-.                                             Find thing at point
index d58dcf12efa02ff279776749097d8f13cac61756..c3e57a65163d4059368c9c50bbe24dad22c35915 100644 (file)
@@ -4,6 +4,9 @@
 (require 'ivy)
 (require 'swiper)
 
+(ivy-mode 1)
+(counsel-mode 1)
+
 (setq ivy-wrap t)
 (setq ivy-extra-directories '("./"))
 (setq ivy-count-format "%d/%d ")
 (setq counsel-find-file-at-point t)
 (setq counsel-find-file-ignore-regexp "\\(?:\\`[#.]\\)\\|\\(?:[#~]\\'\\)")
 
-(setq counsel-git-cmd "git ls-files --full-name --cached --others --exclude-standard --")
-(setq counsel-git-grep-cmd-default "git --no-pager grep --full-name -n --no-color --untracked -i -e \"%s\"")
+(setq counsel-grep-base-command "grep -E -n -i -e %s %s")
+(setq counsel-rg-base-command "rg -S --no-heading --line-number --color never --hidden --ignore-file ~/.emacs.d/rg-ignore %s .")
+(defvar counsel-rg-files-command "rg --files --hidden --ignore-file ~/.emacs.d/rg-ignore")
 
-(setq counsel-grep-base-command "grep -niE %s %s")
-
-(ivy-mode 1)
+(defun counsel-rg-jump (&optional initial-input initial-directory)
+  "Jump to a file below the current directory.
+List all files within the current directory or any of its subdirectories.
+INITIAL-INPUT can be given as the initial minibuffer input.
+INITIAL-DIRECTORY, if non-nil, is used as the root directory for search."
+  (interactive
+   (list nil
+         (when current-prefix-arg
+           (read-directory-name "From directory: "))))
+  (counsel-require-program "rg")
+  (let ((default-directory (or initial-directory
+                               (locate-dominating-file default-directory ".git")
+                               default-directory)))
+    (ivy-read "rg --files: "
+              (split-string
+               (shell-command-to-string counsel-rg-files-command)
+               "\n" t)
+              :matcher #'counsel--find-file-matcher
+              :initial-input initial-input
+              :action (lambda (x)
+                        (with-ivy-window
+                          (find-file (expand-file-name x ivy--directory))))
+              :preselect (counsel--preselect-file)
+              :require-match 'confirm-after-completion
+              :history 'file-name-history
+              :keymap counsel-find-file-map
+              :caller 'counsel-rg-jump)))
index 0d55f3aae2c867840beb3d90fc59832026d01974..0de61d399000d041f4f392480cc5c74834ce593b 100644 (file)
@@ -4,17 +4,13 @@
 (global-set-key (kbd "C-z") nil)
 (global-set-key (kbd "C-x C-z") nil)
 
-;; General commands
-(global-set-key (kbd "M-x") 'counsel-M-x)
-
 ;; Search
 (global-set-key (kbd "C-s") 'counsel-grep-or-swiper)
 (global-set-key (kbd "C-r") 'ivy-resume)
 
 ;; Files/buffers
-(global-set-key (kbd "C-x C-f") 'counsel-find-file)
-(global-set-key (kbd "C-x f") 'counsel-git)
-(global-set-key (kbd "C-x g") 'counsel-git-grep)
+(global-set-key (kbd "C-x f") 'counsel-rg-jump)
+(global-set-key (kbd "C-x g") 'counsel-rg)
 (global-set-key (kbd "C-x l") 'counsel-locate)
 (global-set-key (kbd "C-x c") 'my/kill-buffers-not-in-frame)
 (global-set-key (kbd "C-x C-b") 'ibuffer)
@@ -59,7 +55,6 @@
 (global-set-key (kbd "C-,") 'goto-last-change-reverse)
 
 ;; Killing and deleting
-(global-set-key (kbd "M-y") 'counsel-yank-pop)
 (global-set-key (kbd "M-z") 'zap-up-to-char)
 (global-set-key (kbd "C-c k") 'kill-whole-line)
 (global-set-key (kbd "C-c s") 'my/substitute-line)
index 97c909368dcd43b174527fd9e6ca855d014acde4..31b5423d9ea7a0e0b83fa953bedff02aa4663f63 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 97c909368dcd43b174527fd9e6ca855d014acde4
+Subproject commit 31b5423d9ea7a0e0b83fa953bedff02aa4663f63
diff --git a/rg-ignore b/rg-ignore
new file mode 100644 (file)
index 0000000..466cb5d
--- /dev/null
+++ b/rg-ignore
@@ -0,0 +1,4 @@
+.git
+.hg
+.svn
+CVS