emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r112515: * lisp/thingatpt.el (thing-a


From: Sam Steingold
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112515: * lisp/thingatpt.el (thing-at-point): Accept optional second argument
Date: Wed, 08 May 2013 11:10:17 -0400
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 112515
committer: Sam Steingold <address@hidden>
branch nick: trunk
timestamp: Wed 2013-05-08 11:10:17 -0400
message:
  * 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.
modified:
  lisp/net/browse-url.el
  lisp/thingatpt.el
=== modified file 'lisp/net/browse-url.el'
--- a/lisp/net/browse-url.el    2013-01-01 09:11:05 +0000
+++ b/lisp/net/browse-url.el    2013-05-08 15:10:17 +0000
@@ -658,9 +658,10 @@
 ;; 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

=== modified file 'lisp/thingatpt.el'
--- a/lisp/thingatpt.el 2013-03-30 01:32:12 +0000
+++ b/lisp/thingatpt.el 2013-05-08 15:10:17 +0000
@@ -128,20 +128,27 @@
        (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
 


reply via email to

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