;;; -*- lexical-binding: t; -*- ;;; Commentary: ;;; Code: (require 'f) (use-package icomplete :demand t :bind ((:map icomplete-minibuffer-map ("RET" . icomplete-force-complete-and-exit))) :config (setopt completing-read-function #'completing-read-default read-file-name-function #'read-file-name-default completion-styles '(basic substring initials flex) icomplete-delay-completions-threshold 0 icomplete-compute-delay 0.10 icomplete-show-matches-on-no-input t icomplete-separator " | " completions-max-height '30) (icomplete-vertical-mode t)) (defun bd/selector-rg () "Sources for lines found via grep (or a clone)." (interactive) (let ((query (read-string "rg: "))) (defun conv (x) (cons (car x) (cons (- (string-to-number (cadr x)) 1) (caddr x)))) (defun all-in-file (key list) (--map (to-candidate (cdr it)) (--filter (s-equals? key (car it)) list))) (defun to-candidate (x) (selector-candidate-create (cdr x) :value (car x))) (let* ((dir (expand-file-name (bd/get-directory-dwim))) (result (with-temp-buffer (call-process "rg" nil t nil "-n" "-." query dir) (buffer-string))) (lines (--map (conv (s-split-up-to ":" it 2)) (--filter (not (s-blank? it)) (s-split "\n" result)))) (files (-uniq (-map #'car lines))) (sources (--map (selector-source-create it :candidates (all-in-file it lines) :actions (selector-file-contents-actions it)) files))) (when (not (null sources)) (selector sources))))) (provide 'bd--minibuffer) ;;; bd--minibuffer.el ends here