summaryrefslogtreecommitdiff
path: root/lisp/mouse.el
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2021-12-31 15:21:13 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2022-01-14 09:47:02 +0100
commit3f36d0836274a01d3cfc73f53ddbc76afc1d8a5e (patch)
treebb40c66851cafa8428f59e43c0976659a221e37c /lisp/mouse.el
parentf62fe2ebde840da0bcef4899840c594b7b7d9169 (diff)
downloademacs-3f36d0836274a01d3cfc73f53ddbc76afc1d8a5e.tar.gz
Add command to invoke a search engine
* mouse.el (context-menu-online-search): Add new function (eww-search-prefix): Declare variable from eww.el (mouse-online-search-at-point): Add new command
Diffstat (limited to 'lisp/mouse.el')
-rw-r--r--lisp/mouse.el30
1 files changed, 30 insertions, 0 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 1a76b9a0b66..cfe212c3e9b 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -531,6 +531,16 @@ Some context functions add menu items below the separator."
:help "Find file or URL from text around mouse click"))))
menu)
+(defun context-menu-online-search (menu click)
+ "Populate MENU with command to search online."
+ (save-excursion
+ (mouse-set-point click)
+ (define-key-after menu [online-search-separator] menu-bar-separator)
+ (define-key-after menu [online-search-at-mouse]
+ '(menu-item "Online search" mouse-online-search-at-point
+ :help "Search for region or word online")))
+ menu)
+
(defvar context-menu-entry
`(menu-item ,(purecopy "Context Menu") ,(make-sparse-keymap)
:filter ,(lambda (_) (context-menu-map)))
@@ -3217,6 +3227,26 @@ is copied instead of being cut."
(with-current-buffer (window-buffer window)
(setq cursor-type (nth 3 state)))))))
+(defvar eww-search-prefix)
+(defun mouse-online-search-at-point (event)
+ "Query an online search engine at EVENT.
+If a region is active, the entire region will be sent, otherwise
+the symbol at point will be used. This command uses EWW's
+default search engine, as configured by `eww-search-prefix'."
+ (interactive "e")
+ (require 'eww)
+ (let ((query (if (use-region-p)
+ (buffer-substring (region-beginning)
+ (region-end))
+ (save-excursion
+ (mouse-set-point event)
+ (thing-at-point 'symbol)))))
+ (unless query
+ (user-error "Nothing to search for"))
+ (browse-url (concat
+ eww-search-prefix
+ (mapconcat #'url-hexify-string (split-string query) "+")))))
+
;;; Bindings for mouse commands.