From da98498fd4b15b1efa9f044422e834b36107ceaf Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Fri, 10 May 2024 16:06:23 -0400 Subject: [PATCH] Add command to browse a URL or google the symbol at point --- emacs/.emacs.d/config/init-built-ins.el | 10 ++++++++++ emacs/.emacs.d/config/init-completion.el | 1 + 2 files changed, 11 insertions(+) diff --git a/emacs/.emacs.d/config/init-built-ins.el b/emacs/.emacs.d/config/init-built-ins.el index 3e740f6..d2b3307 100644 --- a/emacs/.emacs.d/config/init-built-ins.el +++ b/emacs/.emacs.d/config/init-built-ins.el @@ -70,4 +70,14 @@ :general ([remap dabbrev-expand] #'hippie-expand)) +(use-package browse-url + :straight (:type built-in) + :config + (defun browse-url-or-search (url-or-symbol) + "If URL-OR-SYMBOL is a URL, browse it. Otherwise, search for it." + (interactive (list (thing-at-point 'symbol))) + (if (ffap-url-p url-or-symbol) + (browse-url url-or-symbol) + (browse-url (format "https://www.google.com/search?q=%s" url-or-symbol))))) + (provide 'init-built-ins) diff --git a/emacs/.emacs.d/config/init-completion.el b/emacs/.emacs.d/config/init-completion.el index 51ebd8f..b683b3f 100644 --- a/emacs/.emacs.d/config/init-completion.el +++ b/emacs/.emacs.d/config/init-completion.el @@ -145,6 +145,7 @@ targets." ((emacs normal motion insert visual) "M-." #'embark-dwim) ("C-." #'embark-act) ("M-." #'embark-dwim) + (embark-general-map "C-k" #'browse-url-or-search) (embark-file-map "s" #'sudo-edit-find-file "l" #'vlf "g" #'magit-file-dispatch)