diff options
Diffstat (limited to '.config/emacs/modules/bd--minibuffer.el')
-rw-r--r-- | .config/emacs/modules/bd--minibuffer.el | 129 |
1 files changed, 26 insertions, 103 deletions
diff --git a/.config/emacs/modules/bd--minibuffer.el b/.config/emacs/modules/bd--minibuffer.el index fe2ed78..4a928e3 100644 --- a/.config/emacs/modules/bd--minibuffer.el +++ b/.config/emacs/modules/bd--minibuffer.el @@ -7,6 +7,7 @@ (use-package icomplete + :demand t :bind ((:map icomplete-minibuffer-map ("RET" . icomplete-force-complete-and-exit))) @@ -22,109 +23,31 @@ icomplete-show-matches-on-no-input t icomplete-separator " | " completions-max-height '30) - (icomplete-vertical-mode)) - -(use-package selector - :demand t - :bind (("M-x" . 'selector-M-x)) - :config - (defvar bd/navigate-recent-display-number 6 - "The number of recent buffers that show up in bd/navigate.") - (defvar bd/blacklisted-buffer-regexp-list - '( - "\\*Async Shell Command\\*" - "\\*http" - "\\magit-process" - "\\*Minibuf" - "\\*Echo Area" - "\\*newsticker" - "\\*Org Preview LaTeX Output\\*" - "\\*Shell Command Output\\*" - "\\*tramp" - "\\*eldoc" - "\\*server\\*" - ) - "Buffers that should not show up in buffer-related -selection commands.") - - (defun bd/buffer-blacklisted-p (buf) - "Return non-nil if BUF is blacklisted." - (cl-reduce (lambda (x y) (or x y)) (mapcar (lambda (r) (string-match r buf)) - bd/blacklisted-buffer-regexp-list))) - - (defun bd/buffer-list () - "Return a list of non-blacklisted buffers." - (cl-remove-if #'bd/buffer-blacklisted-p (mapcar 'buffer-name (buffer-list)))) - - (defun bd/selector-recent-buffers () - (selector-source-create - "Recent" - :candidates - (take bd/navigate-recent-display-number - (cl-remove-if (lambda (b) - (get-buffer-window b 'visible)) - (bd/buffer-list))) - :actions - selector-buffer-actions)) - - (defun bd/selector-project-files () - (selector-source-create - "Project Files" - :candidates - (let ((proj (project-current))) - (when proj - (project-files proj))) - :actions - selector-file-actions)) - - (defmacro bd/selector-buffer-type (name c) - `(selector-source-create - ,name - :candidates - (cl-remove-if-not ,c (bd/buffer-list)) - :actions - selector-buffer-actions)) - - (defun bd/navigate () - (interactive) - (selector - (list - (bd/selector-recent-buffers) - (bd/selector-buffer-type "EXWM" #'bd/buffer-exwm-p) - (bd/selector-buffer-type "Text" #'bd/buffer-text-p) - (bd/selector-buffer-type "Source" #'bd/buffer-prog-p) - (bd/selector-buffer-type "Scratch" #'bd/buffer-scratch-p) - (bd/selector-buffer-type "Directories" #'bd/buffer-dired-p) - (bd/selector-buffer-type "IRC" #'bd/buffer-irc-p) - (bd/selector-buffer-type "Ordinary" #'bd/buffer-ordinary-p) - (bd/selector-project-files) - (selector-recentf-source)))) - (keymap-global-set "C-x b" 'bd/navigate) - - (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))))) - (keymap-global-set "C-z s" 'bd/selector-rg)) + (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) |