[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 9dbdc0f: Add define-thing-chars and use it for file
From: |
Sam Steingold |
Subject: |
[Emacs-diffs] master 9dbdc0f: Add define-thing-chars and use it for filename. |
Date: |
Mon, 18 Sep 2017 12:56:14 -0400 (EDT) |
branch: master
commit 9dbdc0f00567d0cf2d165ef9704983bfb588146f
Author: Sam Steingold <address@hidden>
Commit: Sam Steingold <address@hidden>
Add define-thing-chars and use it for filename.
(define-thing-chars): New defmacro.
(filename): Define this thing using `define-thing-chars'.
---
lisp/thingatpt.el | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 13f761e..d315040 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 9dbdc0f: Add define-thing-chars and use it for filename.,
Sam Steingold <=