all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Po Lu <luangruo@yahoo.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: tumashu <tumashu@163.com>,  "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: Subject: [PATCH] * lisp/xwidget.el (xwidget-webkit-browse-url): Remove space prefix of url.
Date: Sat, 13 Nov 2021 09:08:50 +0800	[thread overview]
Message-ID: <87wnlcoo9p.fsf@yahoo.com> (raw)
In-Reply-To: <87ilwy6fr8.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 11 Nov 2021 13:25:31 +0100")

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Well, it's a DWIM function, so: 😅.  It just tries to do what any
> browser does when a user types something into the address bar, and it'll
> probably change over time (as users' expectations change).
>
> But basically tries to guess whether a user is typing in a (possibly
> incomplete) URL or a search term.

I'd like to add this:

(defun url-dwim-expand-url (url local-regex search-prefix)
  "Canonicalize URL.
Try to determine if URL is an incomplete URL or a search query, and
return the canonical form of URL.
SEARCH-PREFIX is the prefix to be prepended to URL if it is a search query.
LOCAL-REGEX is a regular expression that URL is matched against.  If the
match is successful, then URL is treated as an address."
  (setq url (string-trim url))
  (cond ((string-match-p "\\`file:/" url))
	;; Don't mangle file: URLs at all.
        ((string-match-p "\\`ftp://" url)
         (user-error "FTP is not supported"))
        (t
	 ;; Anything that starts with something that vaguely looks
	 ;; like a protocol designator is interpreted as a full URL.
         (if (or (string-match "\\`[A-Za-z]+:" url)
		 ;; Also try to match "naked" URLs like
		 ;; en.wikipedia.org/wiki/Free software
		 (string-match "\\`[A-Za-z_]+\\.[A-Za-z._]+/" url)
		 (and (= (length (split-string url)) 1)
		      (or (and (not (string-match-p "\\`[\"'].*[\"']\\'" url))
			       (> (length (split-string url "[.:]")) 1))
			  (string-match local-regex url))))
             (progn
               (unless (string-match-p "\\`[a-zA-Z][-a-zA-Z0-9+.]*://" url)
                 (setq url (concat "http://" url)))
               ;; Some sites do not redirect final /
               (when (string= (url-filename (url-generic-parse-url url)) "")
                 (setq url (concat url "/"))))
           (setq url (concat search-prefix
                             (mapconcat
                              #'url-hexify-string (split-string url) "+"))))))
  url)

to url-util.

Does this look good to you?  Thanks in advance.



  reply	other threads:[~2021-11-13  1:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11  9:36 Subject: [PATCH] * lisp/xwidget.el (xwidget-webkit-browse-url): Remove space prefix of url tumashu
2021-11-11  9:39 ` Po Lu
2021-11-11 10:49   ` tumashu
2021-11-11 10:53     ` Po Lu
2021-11-11 10:53   ` Lars Ingebrigtsen
2021-11-11 11:15     ` Po Lu
2021-11-11 11:58       ` Lars Ingebrigtsen
2021-11-11 12:21         ` Po Lu
2021-11-11 12:25           ` Lars Ingebrigtsen
2021-11-13  1:08             ` Po Lu [this message]
2021-11-13  7:45               ` Eli Zaretskii
2021-11-13  9:34                 ` Po Lu
2021-11-13 10:26                   ` Eli Zaretskii
2021-11-13 10:45                     ` Po Lu
2021-11-13 13:29                       ` Eli Zaretskii
2021-11-13 15:32                         ` Stephen Berman

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

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

  git send-email \
    --in-reply-to=87wnlcoo9p.fsf@yahoo.com \
    --to=luangruo@yahoo.com \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=tumashu@163.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.