]> git.eshelyaron.com Git - emacs.git/commitdiff
Add define-thing-chars and use it for filename.
authorSam Steingold <sds@gnu.org>
Mon, 18 Sep 2017 16:54:29 +0000 (12:54 -0400)
committerSam Steingold <sds@gnu.org>
Mon, 18 Sep 2017 16:54:57 +0000 (12:54 -0400)
(define-thing-chars): New defmacro.
(filename): Define this thing using `define-thing-chars'.

lisp/thingatpt.el

index 13f761e69e72b07959a9c65d24a1440398fe90b7..d315040392739b05e4ca1e08025fa212324a7a4c 100644 (file)
@@ -42,6 +42,9 @@
 ;;   beginning-op      Function to call to skip to the beginning of a "thing".
 ;;   end-op            Function to call to skip to the end of a "thing".
 ;;
+;; For simple things, defined as sequences of specific kinds of characters,
+;; use macro define-thing-chars.
+;;
 ;; Reliance on existing operators means that many `things' can be accessed
 ;; without further code:  eg.
 ;;     (thing-at-point 'line)
@@ -237,21 +240,28 @@ The bounds of THING are determined by `bounds-of-thing-at-point'."
 (put 'defun 'end-op       'end-of-defun)
 (put 'defun 'forward-op   'end-of-defun)
 
+;; Things defined by sets of characters
+
+(defmacro define-thing-chars (thing chars)
+  "Define THING as a sequence of CHARS.
+E.g.:
+\(define-thing-chars twitter-screen-name \"[:alnum:]_\")"
+  `(progn
+     (put ',thing 'end-op
+          (lambda ()
+            (re-search-forward (concat "\\=[" ,chars "]*") nil t)))
+     (put ',thing 'beginning-op
+          (lambda ()
+            (if (re-search-backward (concat "[^" ,chars "]") nil t)
+               (forward-char)
+             (goto-char (point-min)))))))
+
 ;;  Filenames
 
 (defvar thing-at-point-file-name-chars "-~/[:alnum:]_.${}#%,:"
   "Characters allowable in filenames.")
 
-(put 'filename 'end-op
-     (lambda ()
-       (re-search-forward (concat "\\=[" thing-at-point-file-name-chars "]*")
-                         nil t)))
-(put 'filename 'beginning-op
-     (lambda ()
-       (if (re-search-backward (concat "[^" thing-at-point-file-name-chars "]")
-                              nil t)
-          (forward-char)
-        (goto-char (point-min)))))
+(define-thing-chars filename thing-at-point-file-name-chars)
 
 ;;  URIs