From 72d3cfca0a6a0dafaaa0fa271ac1934c9f836134 Mon Sep 17 00:00:00 2001 From: Sam Steingold Date: Wed, 8 May 2013 11:13:25 -0400 Subject: [PATCH] * lisp/thingatpt.el (thing-at-point): Accept optional second argument NO-PROPERTIES to strip the text properties from the return value. * lisp/net/browse-url.el (browse-url-url-at-point): Pass NO-PROPERTIES to `thing-at-point' instead of stripping the properties ourselves. Also, when `thing-at-point' fails to find a url, prepend "http://" to the filename at point on the assumption that the user is pointing at something like gnu.org/gnu. --- lisp/ChangeLog | 10 ++++++++++ lisp/net/browse-url.el | 7 ++++--- lisp/thingatpt.el | 19 +++++++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 119e46e52d8..bab58a62551 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2013-05-08 Sam Steingold + + * thingatpt.el (thing-at-point): Accept optional second argument + NO-PROPERTIES to strip the text properties from the return value. + * net/browse-url.el (browse-url-url-at-point): Pass NO-PROPERTIES + to `thing-at-point' instead of stripping the properties ourselves. + Also, when `thing-at-point' fails to find a url, prepend "http://" + to the filename at point on the assumption that the user is + pointing at something like gnu.org/gnu. + 2013-05-08 Juanma Barranquero * emacs-lisp/bytecomp.el (byte-compile-insert-header): diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 19e513a3354..695b7a11424 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -658,9 +658,10 @@ regarding its parameter treatment." ;; URL input (defun browse-url-url-at-point () - (let ((url (thing-at-point 'url))) - (set-text-properties 0 (length url) nil url) - url)) + (or (thing-at-point 'url t) + ;; assume that the user is pointing at something like gnu.org/gnu + (let ((f (thing-at-point 'filename t))) + (and f (concat "http://" f))))) ;; Having this as a separate function called by the browser-specific ;; functions allows them to be stand-alone commands, making it easier diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index f71a0d4647c..b7ecdb513f5 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -128,20 +128,27 @@ positions of the thing found." (error nil))))) ;;;###autoload -(defun thing-at-point (thing) +(defun thing-at-point (thing &optional no-properties) "Return the THING at point. THING should be a symbol specifying a type of syntactic entity. Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', `email', `word', `sentence', `whitespace', `line', `number', and `page'. +When the optional argument NO-PROPERTIES is non-nil, +strip text properties from the return value. + See the file `thingatpt.el' for documentation on how to define a symbol as a valid THING." - (if (get thing 'thing-at-point) - (funcall (get thing 'thing-at-point)) - (let ((bounds (bounds-of-thing-at-point thing))) - (if bounds - (buffer-substring (car bounds) (cdr bounds)))))) + (let ((text + (if (get thing 'thing-at-point) + (funcall (get thing 'thing-at-point)) + (let ((bounds (bounds-of-thing-at-point thing))) + (when bounds + (buffer-substring (car bounds) (cdr bounds))))))) + (when (and text no-properties) + (set-text-properties 0 (length text) nil text)) + text)) ;; Go to beginning/end -- 2.39.2