# HG changeset patch # User Richard M. Stallman # Date 868046443 0 # Node ID a3267de991c3f1933219b1d956fbfbe39f760e67 # Parent 4726c7bb05a9603bfcb3ec5b17a122edd2f0d207 Require thingatpt when compiling. (browse-url-url-at-point): Use `thing-at-point' (with URL code moved from here). (browse-url-looking-at): Moved to thingatpt.el, renamed and changed. diff -r 4726c7bb05a9 -r a3267de991c3 lisp/browse-url.el --- a/lisp/browse-url.el Fri Jul 04 19:59:49 1997 +0000 +++ b/lisp/browse-url.el Fri Jul 04 20:00:43 1997 +0000 @@ -208,7 +208,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Code: -(eval-when-compile (require 'dired)) +(eval-when-compile (require 'dired) + (require 'thingatpt)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variables @@ -378,61 +379,10 @@ ;; URL input (defun browse-url-url-at-point () - "Return the URL around or before point. -Search backwards for the start of a URL ending at or after -point. If no URL found, return the empty string. The -access scheme, `http://' will be prepended if absent." - (let ((url "") short strip) - (if (or (setq strip (browse-url-looking-at browse-url-markedup-regexp)) - (browse-url-looking-at browse-url-regexp) - ;; Access scheme omitted? - (setq short (browse-url-looking-at browse-url-short-regexp))) - (progn - (setq url (buffer-substring-no-properties (match-beginning 0) - (match-end 0))) - (and strip (setq url (substring url 5 -1))) ; Drop "" - ;; strip whitespace - (while (string-match "\\s +\\|\n+" url) - (setq url (replace-match "" t t url))) - (and short (setq url (concat (if (string-match "@" url) - "mailto:" "http://") url))))) + (let ((url (thing-at-point 'url))) + (set-text-properties 0 (length url) nil url) url)) -;; thingatpt.el doesn't work for complex regexps. This should work -;; for almost any regexp wherever we are in the match. To do a -;; perfect job for any arbitrary regexp would mean testing every -;; position before point. Regexp searches won't find matches that -;; straddle the start position so we search forwards once and then -;; back repeatedly and then back up a char at a time. - -(defun browse-url-looking-at (regexp) - "Return non-nil if point is in or just after a match for REGEXP. -Set the match data from the earliest such match ending at or after -point." - (save-excursion - (let ((old-point (point)) match) - (and (looking-at regexp) - (>= (match-end 0) old-point) - (setq match (point))) - ;; Search back repeatedly from end of next match. - ;; This may fail if next match ends before this match does. - (re-search-forward regexp nil 'limit) - (while (and (re-search-backward regexp nil t) - (or (> (match-beginning 0) old-point) - (and (looking-at regexp) ; Extend match-end past search start - (>= (match-end 0) old-point) - (setq match (point)))))) - (if (not match) nil - (goto-char match) - ;; Back up a char at a time in case search skipped - ;; intermediate match straddling search start pos. - (while (and (not (bobp)) - (progn (backward-char 1) (looking-at regexp)) - (>= (match-end 0) old-point) - (setq match (point)))) - (goto-char match) - (looking-at regexp))))) - ;; Having this as a separate function called by the browser-specific ;; functions allows them to be stand-alone commands, making it easier ;; to switch between browsers.