diff options
| -rw-r--r-- | lisp/browse-url.el | 58 |
1 files changed, 4 insertions, 54 deletions
diff --git a/lisp/browse-url.el b/lisp/browse-url.el index af24a1cafc3..c81354e2c4e 100644 --- a/lisp/browse-url.el +++ b/lisp/browse-url.el | |||
| @@ -208,7 +208,8 @@ | |||
| 208 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 208 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 209 | ;;; Code: | 209 | ;;; Code: |
| 210 | 210 | ||
| 211 | (eval-when-compile (require 'dired)) | 211 | (eval-when-compile (require 'dired) |
| 212 | (require 'thingatpt)) | ||
| 212 | 213 | ||
| 213 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 214 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 214 | ;; Variables | 215 | ;; Variables |
| @@ -378,61 +379,10 @@ These might set the port, for instance." | |||
| 378 | ;; URL input | 379 | ;; URL input |
| 379 | 380 | ||
| 380 | (defun browse-url-url-at-point () | 381 | (defun browse-url-url-at-point () |
| 381 | "Return the URL around or before point. | 382 | (let ((url (thing-at-point 'url))) |
| 382 | Search backwards for the start of a URL ending at or after | 383 | (set-text-properties 0 (length url) nil url) |
| 383 | point. If no URL found, return the empty string. The | ||
| 384 | access scheme, `http://' will be prepended if absent." | ||
| 385 | (let ((url "") short strip) | ||
| 386 | (if (or (setq strip (browse-url-looking-at browse-url-markedup-regexp)) | ||
| 387 | (browse-url-looking-at browse-url-regexp) | ||
| 388 | ;; Access scheme omitted? | ||
| 389 | (setq short (browse-url-looking-at browse-url-short-regexp))) | ||
| 390 | (progn | ||
| 391 | (setq url (buffer-substring-no-properties (match-beginning 0) | ||
| 392 | (match-end 0))) | ||
| 393 | (and strip (setq url (substring url 5 -1))) ; Drop "<URL:" & ">" | ||
| 394 | ;; strip whitespace | ||
| 395 | (while (string-match "\\s +\\|\n+" url) | ||
| 396 | (setq url (replace-match "" t t url))) | ||
| 397 | (and short (setq url (concat (if (string-match "@" url) | ||
| 398 | "mailto:" "http://") url))))) | ||
| 399 | url)) | 384 | url)) |
| 400 | 385 | ||
| 401 | ;; thingatpt.el doesn't work for complex regexps. This should work | ||
| 402 | ;; for almost any regexp wherever we are in the match. To do a | ||
| 403 | ;; perfect job for any arbitrary regexp would mean testing every | ||
| 404 | ;; position before point. Regexp searches won't find matches that | ||
| 405 | ;; straddle the start position so we search forwards once and then | ||
| 406 | ;; back repeatedly and then back up a char at a time. | ||
| 407 | |||
| 408 | (defun browse-url-looking-at (regexp) | ||
| 409 | "Return non-nil if point is in or just after a match for REGEXP. | ||
| 410 | Set the match data from the earliest such match ending at or after | ||
| 411 | point." | ||
| 412 | (save-excursion | ||
| 413 | (let ((old-point (point)) match) | ||
| 414 | (and (looking-at regexp) | ||
| 415 | (>= (match-end 0) old-point) | ||
| 416 | (setq match (point))) | ||
| 417 | ;; Search back repeatedly from end of next match. | ||
| 418 | ;; This may fail if next match ends before this match does. | ||
| 419 | (re-search-forward regexp nil 'limit) | ||
| 420 | (while (and (re-search-backward regexp nil t) | ||
| 421 | (or (> (match-beginning 0) old-point) | ||
| 422 | (and (looking-at regexp) ; Extend match-end past search start | ||
| 423 | (>= (match-end 0) old-point) | ||
| 424 | (setq match (point)))))) | ||
| 425 | (if (not match) nil | ||
| 426 | (goto-char match) | ||
| 427 | ;; Back up a char at a time in case search skipped | ||
| 428 | ;; intermediate match straddling search start pos. | ||
| 429 | (while (and (not (bobp)) | ||
| 430 | (progn (backward-char 1) (looking-at regexp)) | ||
| 431 | (>= (match-end 0) old-point) | ||
| 432 | (setq match (point)))) | ||
| 433 | (goto-char match) | ||
| 434 | (looking-at regexp))))) | ||
| 435 | |||
| 436 | ;; Having this as a separate function called by the browser-specific | 386 | ;; Having this as a separate function called by the browser-specific |
| 437 | ;; functions allows them to be stand-alone commands, making it easier | 387 | ;; functions allows them to be stand-alone commands, making it easier |
| 438 | ;; to switch between browsers. | 388 | ;; to switch between browsers. |