Embark provides the ability to execute commands on completion options found in the minibuffer.
(use-package embark
:straight t
:after vertico
:bind
(("C-." . embark-act)
("C-;" . embark-dwim)
("C-h B" . embark-bindings))
:init
(setq prefix-help-command #'embark-prefix-help-command)
:config
<<embark_config>>
(define-key embark-file-map (kbd "S") 'sudo-find-file))
Below are functions defined to be used with Embark.
This function creates a sudo-find-file
command that can be used to open files as the super user. This can be really useful when combined with Embark. This function was copied from https://karthinks.com/software/fifteen-ways-to-use-embark/.
(whicher "sudo")
(defun sudo-find-file (file)
"Open FILE as root."
(interactive "FOpen file as root: ")
(when (file-writable-p file)
(user-error "File is user writeable, aborting sudo"))
(find-file (if (file-remote-p file)
(concat "/" (file-remote-p file 'method) ":"
(file-remote-p file 'user) "@" (file-remote-p file 'host)
"|sudo:root@"
(file-remote-p file 'host) ":" (file-remote-p file 'localname))
(concat "/sudo:root@localhost:" file))))
Hide the mode line of the Embark live/completions buffers.
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none))))
Allow use of Embark commands after issuing a Consult command.
(use-package embark-consult
:straight t
:after (embark consult)
:demand t
:hook
(embark-collect-mode . consult-preview-at-point-mode))
Tell Emacs what pacakge this file provides.
(provide 'freemacs-embark)
;;; freemacs-embark.el ends here.