unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Juri Linkov <juri@linkov.net>
Cc: 52973@debbugs.gnu.org
Subject: bug#52973: Adding a few context-menu-mode commands
Date: Sat, 22 Jan 2022 19:39:29 +0000	[thread overview]
Message-ID: <87bl038sr2.fsf@posteo.net> (raw)
In-Reply-To: <87pmp4lmfz.fsf@posteo.net> (Philip Kaludercic's message of "Thu,  06 Jan 2022 19:59:44 +0100")


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 <philipk@posteo.net> writes:

> Juri Linkov <juri@linkov.net> 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 <philipk@posteo.net>
> 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))
>  
> -;;-----------------------------------------------------------------------------
> +\f
> +;;; 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





  parent reply	other threads:[~2022-01-22 19:39 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03  8:34 bug#52973: Adding a few context-menu-mode commands Philip Kaludercic
2022-01-03 12:45 ` Eli Zaretskii
2022-01-03 13:52   ` Philip Kaludercic
2022-01-03 14:32     ` Eli Zaretskii
2022-01-03 17:23       ` Philip Kaludercic
2022-01-03 17:36         ` Eli Zaretskii
2022-01-03 21:17         ` Juri Linkov
2022-01-04 12:26           ` Eli Zaretskii
2022-01-04 17:46             ` Juri Linkov
2022-01-04 20:01               ` Eli Zaretskii
2022-01-04 20:08                 ` Philip Kaludercic
2022-01-04 20:15                   ` Eli Zaretskii
2022-01-05 19:09                     ` Juri Linkov
2022-01-05 19:29                       ` Eli Zaretskii
2022-01-05 20:57                         ` Juri Linkov
2022-01-06  6:54                           ` Eli Zaretskii
2022-01-06  8:20                             ` Juri Linkov
2022-01-06  9:10                               ` Eli Zaretskii
2022-01-03 21:12 ` Juri Linkov
2022-01-04 19:39   ` Philip Kaludercic
2022-01-05 18:58     ` Juri Linkov
2022-01-05 20:14       ` Philip Kaludercic
2022-01-06  8:17         ` Juri Linkov
2022-01-06 18:59           ` Philip Kaludercic
2022-01-06 20:03             ` Juri Linkov
2022-01-06 20:32               ` Eli Zaretskii
2022-01-06 20:35                 ` Juri Linkov
2022-01-07  6:38                   ` Eli Zaretskii
2022-01-07  6:46                     ` Lars Ingebrigtsen
2022-01-07  8:20                       ` Eli Zaretskii
2022-01-07  8:29                     ` Philip Kaludercic
2022-01-07  8:37                       ` Eli Zaretskii
2022-01-08 18:30                         ` Juri Linkov
2022-01-08 18:44                           ` Eli Zaretskii
2022-01-08 19:01                             ` Philip Kaludercic
2022-01-08 19:10                               ` Eli Zaretskii
2022-01-08 19:39                                 ` Philip Kaludercic
2022-01-08 20:09                                   ` Eli Zaretskii
2022-01-12  6:16                           ` Lars Ingebrigtsen
2022-01-12 13:12                             ` Eli Zaretskii
2022-01-12 17:16                               ` Juri Linkov
2022-01-12 17:36                                 ` Eli Zaretskii
2022-01-12 18:03                                   ` Juri Linkov
2022-01-12 19:27                                     ` Eli Zaretskii
2022-01-12 19:41                                       ` Juri Linkov
2022-01-12 19:53                                         ` Eli Zaretskii
2022-01-12 20:00                                           ` Juri Linkov
2022-01-12 20:42                                             ` Eli Zaretskii
2022-01-13  8:39                                               ` Juri Linkov
2022-01-13 10:06                                                 ` Eli Zaretskii
2022-01-13  6:03                                 ` Lars Ingebrigtsen
2022-01-13  8:35                                   ` Juri Linkov
2022-01-13  8:53                                     ` Lars Ingebrigtsen
2022-01-13  9:10                                       ` Juri Linkov
2022-01-13  9:23                                         ` Lars Ingebrigtsen
2022-01-13 10:11                                         ` Eli Zaretskii
2022-01-13  8:54                                   ` Eli Zaretskii
2022-01-06 20:19             ` Lars Ingebrigtsen
2022-01-06 20:32               ` Juri Linkov
2022-01-22 19:39             ` Philip Kaludercic [this message]
2022-01-23  9:08               ` Juri Linkov
2022-01-23 12:09                 ` Philip Kaludercic
2022-01-23 12:13                   ` Lars Ingebrigtsen
2022-01-23 16:30                     ` Philip Kaludercic
2022-01-23 18:06                       ` Juri Linkov
2022-01-23 19:49                         ` Philip Kaludercic
2022-01-23 20:04                           ` Juri Linkov
2022-01-24  9:14                       ` Lars Ingebrigtsen
2022-01-25 12:06                         ` Philip Kaludercic
2022-01-25 12:24                           ` Lars Ingebrigtsen
2022-01-04 20:09   ` Philip Kaludercic
2022-01-05 19:03     ` Juri Linkov
2022-01-14  8:52 ` Lars Ingebrigtsen
2022-01-14 14:33   ` Philip Kaludercic
2022-01-15  8:07     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bl038sr2.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=52973@debbugs.gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).