From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#52973: Adding a few context-menu-mode commands Date: Thu, 06 Jan 2022 18:59:44 +0000 Message-ID: <87pmp4lmfz.fsf@posteo.net> References: <87o84tp69h.fsf@posteo.net> <868rvwsezi.fsf@mail.linkov.net> <87czl75lyz.fsf@posteo.net> <86czl6au29.fsf@mail.linkov.net> <874k6idjod.fsf@posteo.net> <86o84pthgp.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39317"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 52973@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 06 20:01:12 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n5Y0d-000A4R-Tb for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 06 Jan 2022 20:01:12 +0100 Original-Received: from localhost ([::1]:47384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Y0d-0006sb-0e for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 06 Jan 2022 14:01:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5Y0U-0006rT-PS for bug-gnu-emacs@gnu.org; Thu, 06 Jan 2022 14:01:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5Y0T-0002kh-VP for bug-gnu-emacs@gnu.org; Thu, 06 Jan 2022 14:01:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n5Y0T-000731-OW for bug-gnu-emacs@gnu.org; Thu, 06 Jan 2022 14:01:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 06 Jan 2022 19:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52973 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 52973-submit@debbugs.gnu.org id=B52973.164149560826843 (code B ref 52973); Thu, 06 Jan 2022 19:01:01 +0000 Original-Received: (at 52973) by debbugs.gnu.org; 6 Jan 2022 19:00:08 +0000 Original-Received: from localhost ([127.0.0.1]:42333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5Xzb-0006yr-Qh for submit@debbugs.gnu.org; Thu, 06 Jan 2022 14:00:08 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:53061) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5XzW-0006xQ-Rn for 52973@debbugs.gnu.org; Thu, 06 Jan 2022 14:00:06 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id BCF3D240103 for <52973@debbugs.gnu.org>; Thu, 6 Jan 2022 19:59:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1641495596; bh=rgypaqb1p3nWcZ21pIG5M955sCTrm1G4bcRp6pjBQVk=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=pJEQgA41i899xUZtFuNiycyfb1dIcwq3zddPSj5+CrE1aCM2RPQtY7NI8GbOeX/gM t71/aP3JBtu4fTKR6sKSSvfI8JRLtnraKPl68KfYkjc7xXLm4j2wisfSWrsR+rsluM +/do2PZ6ScU8QMBHL5dw67PRSSIDkEy+vwXw8bRBw5Fypax8na/RDJ5YSMnBUhIApq sxOPmqmV0YTciq/SLysFOCWApKa2nKqTn7Kw+Esbftt6YnIPoCzODoGTDdHbFntady 7YvKrG0BbKUEOJ6mVKtMGJ97EwE4e3KvsZW8nC7A4BBQFYQgyWeRq+yT7wTIlGA/K8 be1ZVxDV4bepQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4JVFz00XSJz9rxD; Thu, 6 Jan 2022 19:59:55 +0100 (CET) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB In-Reply-To: <86o84pthgp.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 06 Jan 2022 10:17:10 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:223744 Archived-At: --=-=-= Content-Type: text/plain Juri Linkov writes: >>> Maybe then a better place to add new functions would be in >>> lisp/net/webjump.el. webjump is a package created exactly >>> for this purpose. Then new functions could share the same >>> prefix webjump-. >> >> I didn't know about webjump, thank you for the hint. My only fear is >> that the prefix would make the functionality harder to discover. > > The fact that its name starts with the word "web" improves > discoverability. How is this? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-search-engine-functionality.patch >From 2a32d1f7df0b8dfdceb3f63476df150d55215b5d Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 4 Jan 2022 20:36:32 +0100 Subject: [PATCH] Add search engine functionality * lisp/net/eww.el (eww-search-prefix): Deprecate user option (eww): Use webjump-search-query * lisp/net/webjump.el (webjump-default-search-engine): Add user option (webjump-choose-search-engine): Add function (webjump-search-query): Add function (webjump-search): Add autoloaded command (webjump-search-at-point): Add autoloaded command (webjump-search-at-mouse): Add command (webjump-search-context-menu): Add function for context-menu support. --- lisp/misc.el | 1 + lisp/net/eww.el | 10 +++--- lisp/net/webjump.el | 80 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/lisp/misc.el b/lisp/misc.el index 39ec9497d7..6e5aede789 100644 --- a/lisp/misc.el +++ b/lisp/misc.el @@ -27,6 +27,7 @@ (eval-when-compile (require 'tabulated-list)) +(require 'cl-lib) ;;;###autoload (defun copy-from-above-command (&optional arg) diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 8930eb427d..2ef6b35100 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -33,6 +33,7 @@ (require 'url) (require 'url-queue) (require 'xdg) +(require 'webjump) (eval-when-compile (require 'subr-x)) (defgroup eww nil @@ -55,6 +56,9 @@ eww-search-prefix :version "24.4" :group 'eww :type 'string) +(make-obsolete-variable 'eww-search-prefix + "webjump-default-search-engine" + "29.1") (defcustom eww-use-browse-url "\\`mailto:" "EWW will use `browse-url' when following links that match this regexp. @@ -355,7 +359,7 @@ eww-browse (defun eww (url &optional new-buffer buffer) "Fetch URL and render the page. If the input doesn't look like an URL or a domain name, the -word(s) will be searched for via `eww-search-prefix'. +word(s) will be searched for via `webjump-search'. If NEW-BUFFER is non-nil (interactively, the prefix arg), use a new buffer instead of reusing the default EWW buffer. @@ -464,9 +468,7 @@ eww--dwim-expand-url ;; Some sites do not redirect final / (when (string= (url-filename (url-generic-parse-url url)) "") (setq url (concat url "/")))) - (setq url (concat eww-search-prefix - (mapconcat - #'url-hexify-string (split-string url) "+")))))) + (setq url (webjump-search-query url))))) url) (defun eww--preprocess-html (start end) diff --git a/lisp/net/webjump.el b/lisp/net/webjump.el index 7547f92d7d..17c9312c54 100644 --- a/lisp/net/webjump.el +++ b/lisp/net/webjump.el @@ -370,7 +370,85 @@ webjump-url-fix-trailing-slash (concat url "/") url)) -;;----------------------------------------------------------------------------- + +;;; Search engine functionality + +(defcustom webjump-default-search-engine "DuckDuckGo" + "Search engine to use for `webjump-search' and related commands. +The string should denote an entry in `webjump-sites', with a +`simple-query' entry." + :type 'string) + +(defun webjump-choose-search-engine () + "Choose a search engine to use from `webjump-sites'. +If no prefix argument was used, the function will return the +entry for `webjump-default-search-engine'." + (assoc-string + (if current-prefix-arg + (completing-read + (format-prompt "Use search engine" + webjump-default-search-engine) + webjump-sites + (lambda (ent) + (and (vectorp (cdr ent)) + (eq (aref (cdr ent) 0) 'simple-query))) + t nil nil webjump-default-search-engine) + webjump-default-search-engine) + webjump-sites t)) + +(defun webjump-search-query (string) + "Generate an URL query to search for STRING." + (let ((engine (cdr (webjump-choose-search-engine)))) + (webjump-url-fix + (concat (aref engine 2) + (webjump-url-encode string) + (aref engine 3))))) + +;;;###autoload +(defun webjump-search (string) + "Search for STRING using a search engine. +If the optional argument ENGINE may be used to override +`webjump-default-search-engine'." + (interactive (list (if (use-region-p) + (buffer-substring (region-beginning) (region-end)) + (read-string "Search: ")))) + (browse-url (webjump-search-query string))) + +;;;###autoload +(defun webjump-search-at-point () + "Search for symbol at point online. +See `webjump-search' for more details." + (interactive) + (let ((query (thing-at-point 'symbol))) + (unless query + (user-error "Nothing to search for")) + (webjump-search query))) + +;;;###autoload +(defun webjump-search-at-mouse (click) + "Query an online search engine at CLICK. +If a region is active, the entire region will be sent, otherwise +the symbol at point will be used. See `webjump-search' for more +details." + (interactive "e") + (let ((query (if (use-region-p) + (buffer-substring (region-beginning) + (region-end)) + (thing-at-mouse click 'symbol)))) + (unless (or query (string-match-p "\\`[[:space:]\n]*\\'" query)) + (user-error "Nothing to search for")) + (webjump-search query))) + +;;;###autoload +(defun webjump-search-context-menu (menu click) + "Populate MENU with command to search online at CLICK." + (save-excursion + (mouse-set-point click) + (define-key-after menu [webjump-search-separator] menu-bar-separator) + (define-key-after menu [webjump-search-at-mouse] + '(menu-item "Online search" webjump-search-at-mouse + :help "Search for region or word online"))) + menu) (provide 'webjump) -- 2.34.0 --=-=-= Content-Type: text/plain While I agree that web helps, I think a search-online defalias for webjump-search would be appreciated when looking for commands via apropos. -- Philip Kaludercic --=-=-=--