emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: address@hidden: 23.0.0; (thing-at-point 'url) returns invalid urls]


From: Thien-Thi Nguyen
Subject: Re: address@hidden: 23.0.0; (thing-at-point 'url) returns invalid urls]
Date: Fri, 31 Aug 2007 23:35:08 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux)

() "Drew Adams" <address@hidden>
() 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 via email to

[Prev in Thread] Current Thread [Next in Thread]