aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Kaludercic2021-12-31 15:21:13 +0100
committerLars Ingebrigtsen2022-01-14 09:47:02 +0100
commit3f36d0836274a01d3cfc73f53ddbc76afc1d8a5e (patch)
treebb40c66851cafa8428f59e43c0976659a221e37c
parentf62fe2ebde840da0bcef4899840c594b7b7d9169 (diff)
downloademacs-3f36d0836274a01d3cfc73f53ddbc76afc1d8a5e.tar.gz
emacs-3f36d0836274a01d3cfc73f53ddbc76afc1d8a5e.zip
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
-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."
531 :help "Find file or URL from text around mouse click")))) 531 :help "Find file or URL from text around mouse click"))))
532 menu) 532 menu)
533 533
534(defun context-menu-online-search (menu click)
535 "Populate MENU with command to search online."
536 (save-excursion
537 (mouse-set-point click)
538 (define-key-after menu [online-search-separator] menu-bar-separator)
539 (define-key-after menu [online-search-at-mouse]
540 '(menu-item "Online search" mouse-online-search-at-point
541 :help "Search for region or word online")))
542 menu)
543
534(defvar context-menu-entry 544(defvar context-menu-entry
535 `(menu-item ,(purecopy "Context Menu") ,(make-sparse-keymap) 545 `(menu-item ,(purecopy "Context Menu") ,(make-sparse-keymap)
536 :filter ,(lambda (_) (context-menu-map))) 546 :filter ,(lambda (_) (context-menu-map)))
@@ -3217,6 +3227,26 @@ is copied instead of being cut."
3217 (with-current-buffer (window-buffer window) 3227 (with-current-buffer (window-buffer window)
3218 (setq cursor-type (nth 3 state))))))) 3228 (setq cursor-type (nth 3 state)))))))
3219 3229
3230(defvar eww-search-prefix)
3231(defun mouse-online-search-at-point (event)
3232 "Query an online search engine at EVENT.
3233If a region is active, the entire region will be sent, otherwise
3234the symbol at point will be used. This command uses EWW's
3235default search engine, as configured by `eww-search-prefix'."
3236 (interactive "e")
3237 (require 'eww)
3238 (let ((query (if (use-region-p)
3239 (buffer-substring (region-beginning)
3240 (region-end))
3241 (save-excursion
3242 (mouse-set-point event)
3243 (thing-at-point 'symbol)))))
3244 (unless query
3245 (user-error "Nothing to search for"))
3246 (browse-url (concat
3247 eww-search-prefix
3248 (mapconcat #'url-hexify-string (split-string query) "+")))))
3249
3220 3250
3221;;; Bindings for mouse commands. 3251;;; Bindings for mouse commands.
3222 3252