diff options
Diffstat (limited to 'counsel.org')
-rw-r--r-- | counsel.org | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/counsel.org b/counsel.org new file mode 100644 index 0000000..07035d6 --- /dev/null +++ b/counsel.org @@ -0,0 +1,228 @@ +#+title: Completion configuration using ivy, counsel and friends + +* ivy + #+begin_src emacs-lisp + (use-package ivy + :ensure t + :demand t + :custom + ((ivy-count-format "(%d/%d) ") + (ivy-do-completion-in-region t) + (ivy-height 20) + (ivy-re-builders-alist '((counsel-ag . ivy--regex) + (counsel-rg . ivy--regex) + (counsel-yank-pop . ivy--regex) + (swiper . ivy--regex) + (swiper-isearch . ivy--regex) + (t . ivy--regex-fuzzy))) + (ivy-use-virtual-buffers t) + (ivy-virtual-abbreviate 'abbreviate) + (ivy-wrap t)) + + :config + ;; used by ivy--regex-fuzzy to order results + (use-package flx :ensure t) + + ;; Try C-o in the minibuffer + (use-package ivy-hydra + :after ivy + :ensure t + :init (setq ivy-read-action-function #'ivy-hydra-read-action)) + + (add-to-list 'ivy-initial-inputs-alist + '(gnus-summary-move-article . "")) + + :bind (("C-R" . ivy-resume) + ("C-x b" . ivy-switch-buffer) + ("C-c v" . ivy-push-view) + ("C-c V" . ivy-pop-view)) + :diminish) + #+end_src +* counsel + #+begin_src emacs-lisp + (use-package counsel + :ensure t + :custom ((counsel-describe-function-function 'helpful-callable) + (counsel-describe-variable-function 'helpful-variable) + (counsel-find-file-at-point t) + (counsel-linux-app-format-function + #'counsel-linux-app-format-function-name-pretty) + (counsel-mode-override-describe-bindings nil) + (counsel-recentf-include-xdg-list t)) + :config + :bind (("C-s" . swiper-isearch) + ("C-S-s" . isearch-forward) + ("M-x" . counsel-M-x) + ("C-x f" . counsel-find-file) + ("C-c k" . counsel-ag) + ("C-c K" . counsel-rg) + ("C-c l" . counsel-locate) + ("C-c b" . counsel-git) + ("C-c i" . counsel-imenu) + ("C-c G" . counsel-search) + ("s-r" . counsel-linux-app)) + :diminish) + #+end_src +* counsel add-ons +*** recoll + #+BEGIN_SRC emacs-lisp + (use-package jao-recoll) + (use-package jao-counsel-recoll + :after counsel + :bind (("C-c R" . jao-counsel-recoll))) + #+END_SRC +*** notmuch + #+begin_src emacs-lisp + (use-package counsel-notmuch + :ensure t + :config (with-eval-after-load "gnus-group" + (define-key gnus-group-mode-map "Gg" 'counsel-notmuch))) + #+end_src +* ivy rich + #+begin_src emacs-lisp + (use-package ivy-rich + :after (ivy counsel) + :ensure t + :custom ((ivy-rich-path-style 'relative) + (ivy-rich-parse-remote-buffer nil) + (ivy-rich-parse-remote-file-path nil)) + :config + (ivy-rich-modify-columns + 'ivy-switch-buffer + '((ivy-rich-candidate (:width 80)) + (ivy-rich-switch-buffer-indicators (:face jao-themes-f00)) + (ivy-rich-switch-buffer-project (:width 15)) + (ivy-rich-switch-buffer-major-mode (:width 15 :face jao-themes-f12))))) + #+end_src +* dap + #+begin_src emacs-lisp + (jao-load-path "dap") + (use-package dap + :demand t + :bind (("C-'" . dap-dap))) + #+end_src +*** prompter + #+begin_src emacs-lisp + (defun jao-dap--hide-help () + (when-let ((w (get-buffer-window (help-buffer)))) + (with-selected-window w (kill-buffer-and-window)))) + + (defun jao-dap--prompter (keymap) + (let ((display-buffer-alist '(("*Help*" + (display-buffer-at-bottom) + (window-parameters (mode-line-format . none)) + (window-height . fit-window-to-buffer))))) + (let ((inhibit-message t)) + (describe-keymap keymap)))) + + (defun jao-dap--prompter-done () + (save-current-buffer (jao-dap--hide-help))) + + (setq dap-prompter #'jao-dap--prompter) + (setq dap-prompter-done #'jao-dap--prompter-done) + #+end_src +*** minibuffer actions + #+begin_src emacs-lisp + (defun jao-dap--completion-metadata () + (completion-metadata + (buffer-substring-no-properties (field-beginning) (point)) + minibuffer-completion-table + minibuffer-completion-predicate)) + + (defun jao-dap--completion-category () + (completion-metadata-get (jao-dap--completion-metadata) 'category)) + + (dap-define-keymap jao-dap-buffer-map + "Keymap for buffer actions." + ("k" kill-buffer) + ("b" switch-to-buffer) + ("o" switch-to-buffer-other-window) + ("z" bury-buffer) + ("q" kill-buffer-and-window) + ("=" ediff-buffers)) + + (dap-define-keymap espotify-item-keymap + "Actions for Spotify search results" + ("a" espotify--play-album) + ("h" espotify--show-info)) + + (defvar jao-dap--smaps + '((command . dap-command-map) + (espotify-search-item . espotify-item-keymap) + (function . dap-function-map) + (variable . dap-variable-map) + (face . dap-face-map) + (buffer . jao-dap-buffer-map) + (consult-buffer . jao-dap-buffer-map))) + + (defun jao-dap-target-minibuffer-candidate () + (when (minibuffer-window-active-p (selected-window)) + (let ((cand (ivy-state-current ivy-last)) + (cat (jao-dap--completion-category))) + (when-let (m (alist-get cat jao-dap--smaps)) + (cons m cand))))) + + (add-to-list 'dap-targets #'jao-dap-target-minibuffer-candidate) + #+end_src +*** url / video actions + #+begin_src emacs-lisp + (defvar jao-dap-video-url-rx + (format "^https?://\\(?:www\\.\\)?%s/.+" + (regexp-opt '("youtu.be" + "youtube.com" + "blip.tv" + "vimeo.com" + "infoq.com") + t)) + "A regular expression matching URLs that point to video streams") + + (defun jao-dap--play-video (player url) + (interactive "sURL: ") + (let ((cmd (format "%s %s" player (shell-quote-argument url)))) + (start-process-shell-command player nil cmd))) + + (defun jao-dap-mpv (&optional url) + "Play video stream with mpv" + (interactive "sURL: ") + (jao-dap--play-video "mpv" url)) + + (defun jao-dap-vlc (&optional url) + "Play video stream with vlc" + (interactive "sURL: ") + (jao-dap--play-video "vlc" url)) + + (defun jao-dap-target-w3m-url () + (when-let (url (or (thing-at-point-url-at-point) + (w3m-anchor) + w3m-current-url)) + (cons 'dap-url-map url))) + + (defun jao-dap-kill (&optional x) + "Save to kill ring" + (interactive "s") + (kill-new x)) + + (define-key dap-url-map "f" #'browse-url-firefox) + (define-key dap-url-map "w" #'jao-dap-kill) + (define-key dap-url-map [return] #'browse-url) + + (defun jao-dap-target-video-url () + (when-let (url (jao-dap-target-w3m-url)) + (when (string-match-p jao-dap-video-url-rx (cdr url)) + (cons 'jao-dap-video-url-map (cdr url))))) + + (dap-define-keymap jao-dap-video-url-map + "Actions on URLs pointing to remote video streams." + ("v" jao-dap-vlc) + ("m" jao-dap-mpv)) + + (add-to-list 'dap-targets #'jao-dap-target-w3m-url) + (add-to-list 'dap-targets #'jao-dap-target-video-url) + #+end_src +* startup + #+begin_src emacs-lisp + (ivy-mode 1) + (counsel-mode 1) + (ivy-rich-mode 1) + (ivy-rich-project-root-cache-mode 1) + #+end_src |