From 0adf2da1d62addce56afd5fb8866ecce77147bd5 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 4 Apr 2021 21:40:15 +0100 Subject: completion.org and minicomp --- attic/counsel.org | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'attic') diff --git a/attic/counsel.org b/attic/counsel.org index 6fbd591..f6814ae 100644 --- a/attic/counsel.org +++ b/attic/counsel.org @@ -1,5 +1,68 @@ #+title: Completion configuration using ivy, counsel and friends +* selectrum + #+begin_src emacs-lisp :load no + (use-package selectrum + :ensure t + :init + (defun jao-selectrum--ord-refine (&rest args) + (let ((completion-styles '(orderless))) + (apply #'selectrum-refine-candidates-using-completions-styles args))) + + (defun jao-selectrum-orderless () + (interactive) + (setq selectrum-refine-candidates-function #'jao-selectrum--ord-refine) + (setq selectrum-highlight-candidates-function #'orderless-highlight-matches) + (setq orderless-skip-highlighting (lambda () selectrum-is-active))) + + + :config + ;; https://github.com/raxod502/selectrum/wiki/Ido,-icomplete(fido)-emulation + (defun selectrum-fido-backward-updir () + "Delete char before or go up directory, like `ido-mode'." + (interactive) + (if (and (eq (char-before) ?/) + (eq (selectrum--get-meta 'category) 'file)) + (save-excursion + (goto-char (1- (point))) + (when (search-backward "/" (point-min) t) + (delete-region (1+ (point)) (point-max)))) + (call-interactively 'backward-delete-char))) + + (defun selectrum-fido-delete-char () + "Delete char or maybe call `dired', like `ido-mode'." + (interactive) + (let ((end (point-max))) + (if (or (< (point) end) (not (eq (selectrum--get-meta 'category) 'file))) + (call-interactively 'delete-char) + (dired (file-name-directory (minibuffer-contents))) + (exit-minibuffer)))) + + (defun selectrum-fido-ret () + "Exit minibuffer or enter directory, like `ido-mode'." + (interactive) + (let* ((dir (and (eq (selectrum--get-meta 'category) 'file) + (file-name-directory (minibuffer-contents)))) + (current (selectrum-get-current-candidate)) + (probe (and dir current + (expand-file-name (directory-file-name current) dir)))) + (if (and probe (file-directory-p probe) (not (string= current "./"))) + (selectrum-insert-current-candidate) + (selectrum-select-current-candidate)))) + + ;; (define-key selectrum-minibuffer-map (kbd "RET") 'selectrum-fido-ret) + (define-key selectrum-minibuffer-map (kbd "DEL") 'selectrum-fido-backward-updir) + (define-key selectrum-minibuffer-map (kbd "C-d") 'selectrum-fido-delete-char) + + :custom ((selectrum-complete-in-buffer t) + ;; (selectrum-display-action '(display-buffer-at-bottom)) + (selectrum-extend-current-candidate-highlight t) + (selectrum-fix-vertical-window-height nil) + (selectrum-max-window-height 20) + (selectrum-show-indices nil) + (selectrum-count-style 'current/matches)) + :bind (("C-R" . selectrum-repeat))) + #+end_src * ivy #+begin_src emacs-lisp (use-package ivy -- cgit v1.2.3