unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: <emacs-devel@gnu.org>
Subject: Re: [sdl.web@gmail.com: 23.0.0; (thing-at-point 'url) returns invalid urls]
Date: Fri, 31 Aug 2007 23:35:08 +0200	[thread overview]
Message-ID: <87wsvbie0j.fsf@gnuvola.org> (raw)
In-Reply-To: <BNELLINCGFJLDJIKDGACEEPLCBAA.drew.adams@oracle.com> (Drew Adams's message of "Fri\, 31 Aug 2007 13\:34\:41 -0700")

() "Drew Adams" <drew.adams@oracle.com>
() Fri, 31 Aug 2007 13:34:41 -0700

   That's OK too. I thought people were asking for the ability to
   get only "valid" URLs in the sense of having live
   targets. Isn't that what the initial request was for?

iiuc the initial request was to disambiguate the two cases whereby
(thing-at-point 'url) when point is on one of:

  something
  http://something

(both cases return "http://something").  i posted a suggestion (to
gnu-emacs-help but i guess it got dropped somehow) along the lines
of adding a variable thing-at-point-url-autoprefix which when t
would do the heuristic autoprefixing (http:// or ftp://) that is
the present behavior, and when nil, would not.  default value is
another question, of course.

below is a quick patch.  here are some tests from *scratch*:

 (defun test (setting text)
   (setq thing-at-point-url-autoprefix setting)
   (save-excursion
     (insert text))
   (prog1 (thing-at-point 'url)
     (delete-char (length text))))
 
 (test   t "http://something")
 "http://something"
 
 (test nil "http://something")
 "http://something"
 
 (test   t "something")
 "http://something"
 
 (test nil "something")
 "something"

seems harmless enough.  what do people think?

thi


_______________________________________
*** thingatpt.el	26 Jul 2007 05:26:35 -0000	1.43
--- thingatpt.el	31 Aug 2007 21:26:54 -0000
***************
*** 238,243 ****
--- 238,247 ----
    "A regular expression matching a URL marked up per RFC1738.
  This may contain whitespace (including newlines) .")
  
+ (defvar thing-at-point-url-autoprefix nil
+   "Controls how `thing-at-point' recognizes URLs.
+ If nil, no access scheme is presumed.")
+ 
  (put 'url 'bounds-of-thing-at-point 'thing-at-point-bounds-of-url-at-point)
  (defun thing-at-point-bounds-of-url-at-point ()
    (let ((strip (thing-at-point-looking-at
***************
*** 261,267 ****
  
  Search backwards for the start of a URL ending at or after point.  If
  no URL found, return nil.  The access scheme will be prepended if
! absent: \"mailto:\" if the string contains \"@\", \"ftp://\" if it
  starts with \"ftp\" and not \"ftp:/\", or \"http://\" by default."
  
    (let ((url "") short strip)
--- 265,272 ----
  
  Search backwards for the start of a URL ending at or after point.  If
  no URL found, return nil.  The access scheme will be prepended if
! absent (and if `thing-at-point-url-autoprefix' has non-nil value),
! one of \"mailto:\" if the string contains \"@\", \"ftp://\" if it
  starts with \"ftp\" and not \"ftp:/\", or \"http://\" by default."
  
    (let ((url "") short strip)
***************
*** 278,284 ****
  	  ;; strip whitespace
  	  (while (string-match "[ \t\n\r]+" url)
  	    (setq url (replace-match "" t t url)))
! 	  (and short (setq url (concat (cond ((string-match "^[a-zA-Z]+:" url)
  					       ;; already has a URL scheme.
  					       "")
  					     ((string-match "@" url)
--- 283,290 ----
  	  ;; strip whitespace
  	  (while (string-match "[ \t\n\r]+" url)
  	    (setq url (replace-match "" t t url)))
! 	  (and short thing-at-point-url-autoprefix
!                      (setq url (concat (cond ((string-match "^[a-zA-Z]+:" url)
  					       ;; already has a URL scheme.
  					       "")
  					     ((string-match "@" url)

  reply	other threads:[~2007-08-31 21:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-30  7:15 [sdl.web@gmail.com: 23.0.0; (thing-at-point 'url) returns invalid urls] Richard Stallman
2007-08-31  8:32 ` Glenn Morris
2007-08-31 14:42   ` Stefan Monnier
2007-08-31 16:18     ` Drew Adams
2007-08-31 20:27       ` Stefan Monnier
2007-08-31 20:34         ` Drew Adams
2007-08-31 21:35           ` Thien-Thi Nguyen [this message]
2007-08-31 23:57             ` Drew Adams
2007-09-01 19:13               ` Johannes Weiner
2007-09-01 19:59                 ` Leo
2007-09-01 20:04                   ` Johannes Weiner
2007-09-01  1:57           ` Leo
2007-09-01 16:39             ` Drew Adams
2007-09-01 20:57               ` Leo
2007-09-02  6:39                 ` David Kastrup
2007-09-02 19:20                   ` Glenn Morris
2007-09-04 22:37                 ` Davis Herring
2007-09-03 20:51               ` Stefan Monnier
2007-09-04 22:40               ` Davis Herring
2007-09-01  4:06   ` Richard Stallman
2007-09-01 21:00 ` (thing-at-point 'defun) always returns NIL (was: [sdl.web@gmail.com: 23.0.0; (thing-at-point 'url) returns invalid urls]) Leo
2007-09-01 21:41   ` (thing-at-point 'defun) always returns NIL (was:[sdl.web@gmail.com: " Drew Adams

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=87wsvbie0j.fsf@gnuvola.org \
    --to=ttn@gnuvola.org \
    --cc=emacs-devel@gnu.org \
    /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).