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: Sat, 22 Jan 2022 19:39:29 +0000 Message-ID: <87bl038sr2.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> <87pmp4lmfz.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39628"; 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 Sat Jan 22 20:41:07 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 1nBMG3-000A5z-AV for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Jan 2022 20:41:07 +0100 Original-Received: from localhost ([::1]:60134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nBMG2-0004OW-2g for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Jan 2022 14:41:06 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBMF1-0004OJ-H9 for bug-gnu-emacs@gnu.org; Sat, 22 Jan 2022 14:40:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45074) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nBMF0-0005LT-Ci for bug-gnu-emacs@gnu.org; Sat, 22 Jan 2022 14:40:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nBMF0-0004aq-AQ for bug-gnu-emacs@gnu.org; Sat, 22 Jan 2022 14:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Jan 2022 19:40:02 +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.164288038117618 (code B ref 52973); Sat, 22 Jan 2022 19:40:02 +0000 Original-Received: (at 52973) by debbugs.gnu.org; 22 Jan 2022 19:39:41 +0000 Original-Received: from localhost ([127.0.0.1]:37977 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBMEe-0004a6-QO for submit@debbugs.gnu.org; Sat, 22 Jan 2022 14:39:41 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:45543) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBMEc-0004Zr-2v for 52973@debbugs.gnu.org; Sat, 22 Jan 2022 14:39:38 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 674C6240026 for <52973@debbugs.gnu.org>; Sat, 22 Jan 2022 20:39:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1642880371; bh=ksM5zUNBLInrHBgn5+DvW873ieh9OJ0EJVh2aYGevUg=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=UXbxgD9MMNA6GNKvJQdWH+PP5Y0+7egk8uObndI4wOVHiguBy6kDsIf6qbEb4r/Kx F0rUA1F2ujMySCuFKj3ACRx6hlFJ/PDsIDq3UXzT1kxf1VzLMu5oLZjKV/kDjzxThu gNLkB5gUxt+g0iZoNJTBL90WewdHh2GoS87vr2l/7yepLx1zQQEqJAl9iUuq9/bznX ln7rxdUnWfdc52FYmbxOrNL+a5qT+46pBmm5UFw9CqdbAbDNUbf2b6zPt7VFE2sJSd lywNfGCR9qnTa94SxfAFcLhWq4WuesTGiJ1iQOT2+11+sYe4PP5NgOl5Ru5bdg4uNq /iIt2PlRzDDDw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Jh65G4KL7z9rxD; Sat, 22 Jan 2022 20:39:30 +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: <87pmp4lmfz.fsf@posteo.net> (Philip Kaludercic's message of "Thu, 06 Jan 2022 19:59:44 +0100") 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:224861 Archived-At: I just wanted to apply this patch, then I noticed that this would also change the default browser for EWW from html.duckduckgo.com to duckduckgo.com. The effect is that every search query it redirected to the JS-free version. Any ideas how to fix this? Should I just remove the EWW integration, or change the DuckDuckGo URL to the HTML-version? Philip Kaludercic writes: > 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? > > 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 > > > 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