refactor(tazjin/emacs): Always use completing-read instead of ivy

This is a step towards making the completing-read framework more
easily interchangeable (I'm eyeing selectrum).

Change-Id: I7a066e212a5384136defbba8f11ef9ed57abf22e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2240
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2020-12-09 14:57:25 +01:00 committed by tazjin
parent 93f0ab5af8
commit 2485006197
5 changed files with 36 additions and 40 deletions

View file

@ -15,7 +15,7 @@
;; Start eshell or switch to it if it's active. ;; Start eshell or switch to it if it's active.
(global-set-key (kbd "C-x m") 'eshell) (global-set-key (kbd "C-x m") 'eshell)
(global-set-key (kbd "C-x C-p") 'ivy-browse-repositories) (global-set-key (kbd "C-x C-p") 'browse-repositories)
(global-set-key (kbd "M-g M-g") 'goto-line-with-feedback) (global-set-key (kbd "M-g M-g") 'goto-line-with-feedback)
;; Miscellaneous editing commands ;; Miscellaneous editing commands

View file

@ -131,8 +131,8 @@
;; Launch applications / any command with completion (dmenu style!) ;; Launch applications / any command with completion (dmenu style!)
(exwm-input-set-key (kbd "s-d") #'counsel-linux-app) (exwm-input-set-key (kbd "s-d") #'counsel-linux-app)
(exwm-input-set-key (kbd "s-x") #'ivy-run-external-command) (exwm-input-set-key (kbd "s-x") #'run-external-command)
(exwm-input-set-key (kbd "s-p") #'ivy-password-store) (exwm-input-set-key (kbd "s-p") #'password-store-lookup)
;; Add X11 terminal selector to a key ;; Add X11 terminal selector to a key
(exwm-input-set-key (kbd "C-x t") #'ts/switch-to-terminal) (exwm-input-set-key (kbd "C-x t") #'ts/switch-to-terminal)

View file

@ -59,9 +59,6 @@
(buffer-name) (buffer-name)
require-final-newline)) require-final-newline))
;; Helm includes a command to run external applications, which does
;; not seem to exist in ivy. This implementation uses some of the
;; logic from Helm to provide similar functionality using ivy.
(defun list-external-commands () (defun list-external-commands ()
"Creates a list of all external commands available on $PATH "Creates a list of all external commands available on $PATH
while filtering NixOS wrappers." while filtering NixOS wrappers."
@ -82,9 +79,9 @@
'(("google-chrome" . "--force-device-scale-factor=1.4")) '(("google-chrome" . "--force-device-scale-factor=1.4"))
"This setting lets me add additional flags to specific commands "This setting lets me add additional flags to specific commands
that are run interactively via `ivy-run-external-command'.") that are run interactively via `run-external-command'.")
(defun run-external-command (cmd) (defun run-external-command--handler (cmd)
"Execute the specified command and notify the user when it "Execute the specified command and notify the user when it
finishes." finishes."
(let* ((extra-flags (cdr (assoc cmd external-command-flag-overrides))) (let* ((extra-flags (cdr (assoc cmd external-command-flag-overrides)))
@ -96,28 +93,33 @@
(when (string= event "finished\n") (when (string= event "finished\n")
(message "%s process finished." process)))))) (message "%s process finished." process))))))
(defun ivy-run-external-command () (defun run-external-command ()
"Prompts the user with a list of all installed applications and "Prompts the user with a list of all installed applications and
lets them select one to launch." lets them select one to launch."
(interactive) (interactive)
(let ((external-commands-list (list-external-commands))) (let ((external-commands-list (list-external-commands)))
(ivy-read "Command:" external-commands-list (run-external-command--handler
:require-match t (completing-read "Command: " external-commands-list
:history 'external-commands-history nil ;; predicate
:action #'run-external-command))) t ;; require-match
nil ;; initial-input
;; hist
'external-commands-history))))
(defun ivy-password-store (&optional password-store-dir) (defun password-store-lookup (&optional password-store-dir)
"Custom version of password-store integration with ivy that "Interactive password-store lookup function that actually uses
actually uses the GPG agent correctly." the GPG agent correctly."
(interactive) (interactive)
(ivy-read "Copy password of entry: "
(password-store-list (or password-store-dir (password-store-dir))) (let* ((entry (completing-read "Copy password of entry: "
:require-match t (password-store-list (or password-store-dir
:keymap ivy-pass-map (password-store-dir)))
:action (lambda (entry) nil ;; predicate
(let ((password (auth-source-pass-get 'secret entry))) t ;; require-match
))
(password (auth-source-pass-get 'secret entry)))
(password-store-clear) (password-store-clear)
(kill-new password) (kill-new password)
(setq password-store-kill-ring-pointer kill-ring-yank-pointer) (setq password-store-kill-ring-pointer kill-ring-yank-pointer)
@ -125,17 +127,14 @@
entry (password-store-timeout)) entry (password-store-timeout))
(setq password-store-timeout-timer (setq password-store-timeout-timer
(run-at-time (password-store-timeout) (run-at-time (password-store-timeout)
nil 'password-store-clear)))))) nil 'password-store-clear))))
(defun ivy-browse-repositories () (defun browse-repositories ()
"Select a git repository and open its associated magit buffer." "Select a git repository and open its associated magit buffer."
(interactive) (interactive)
(ivy-read "Repository: " (magit-status
(magit-list-repos) (completing-read "Repository: " (magit-list-repos))))
:require-match t
:sort t
:action #'magit-status))
(defun bottom-right-window-p () (defun bottom-right-window-p ()
"Determines whether the last (i.e. bottom-right) window of the "Determines whether the last (i.e. bottom-right) window of the

View file

@ -69,8 +69,6 @@
(setq enable-recursive-minibuffers t) (setq enable-recursive-minibuffers t)
(setq ivy-use-virtual-buffers t)) (setq ivy-use-virtual-buffers t))
(use-package ivy-pass :after (ivy))
(use-package ivy-prescient (use-package ivy-prescient
:after (ivy prescient) :after (ivy prescient)
:config :config

View file

@ -60,7 +60,6 @@ let
idle-highlight-mode idle-highlight-mode
intero intero
ivy ivy
ivy-pass
ivy-prescient ivy-prescient
jq-mode jq-mode
kotlin-mode kotlin-mode