aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Steingold2017-09-18 12:54:29 -0400
committerSam Steingold2017-09-18 12:54:57 -0400
commit9dbdc0f00567d0cf2d165ef9704983bfb588146f (patch)
tree2cb03ab4183a0b23c591cca4a24a01bf826f68e7
parent0925a20e0a48bc5ff8e9bad6ca4aa0a4c91fdc3c (diff)
downloademacs-9dbdc0f00567d0cf2d165ef9704983bfb588146f.tar.gz
emacs-9dbdc0f00567d0cf2d165ef9704983bfb588146f.zip
Add define-thing-chars and use it for filename.
(define-thing-chars): New defmacro. (filename): Define this thing using `define-thing-chars'.
-rw-r--r--lisp/thingatpt.el30
1 files changed, 20 insertions, 10 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 13f761e69e7..d3150403927 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -42,6 +42,9 @@
42;; beginning-op Function to call to skip to the beginning of a "thing". 42;; beginning-op Function to call to skip to the beginning of a "thing".
43;; end-op Function to call to skip to the end of a "thing". 43;; end-op Function to call to skip to the end of a "thing".
44;; 44;;
45;; For simple things, defined as sequences of specific kinds of characters,
46;; use macro define-thing-chars.
47;;
45;; Reliance on existing operators means that many `things' can be accessed 48;; Reliance on existing operators means that many `things' can be accessed
46;; without further code: eg. 49;; without further code: eg.
47;; (thing-at-point 'line) 50;; (thing-at-point 'line)
@@ -237,21 +240,28 @@ The bounds of THING are determined by `bounds-of-thing-at-point'."
237(put 'defun 'end-op 'end-of-defun) 240(put 'defun 'end-op 'end-of-defun)
238(put 'defun 'forward-op 'end-of-defun) 241(put 'defun 'forward-op 'end-of-defun)
239 242
243;; Things defined by sets of characters
244
245(defmacro define-thing-chars (thing chars)
246 "Define THING as a sequence of CHARS.
247E.g.:
248\(define-thing-chars twitter-screen-name \"[:alnum:]_\")"
249 `(progn
250 (put ',thing 'end-op
251 (lambda ()
252 (re-search-forward (concat "\\=[" ,chars "]*") nil t)))
253 (put ',thing 'beginning-op
254 (lambda ()
255 (if (re-search-backward (concat "[^" ,chars "]") nil t)
256 (forward-char)
257 (goto-char (point-min)))))))
258
240;; Filenames 259;; Filenames
241 260
242(defvar thing-at-point-file-name-chars "-~/[:alnum:]_.${}#%,:" 261(defvar thing-at-point-file-name-chars "-~/[:alnum:]_.${}#%,:"
243 "Characters allowable in filenames.") 262 "Characters allowable in filenames.")
244 263
245(put 'filename 'end-op 264(define-thing-chars filename thing-at-point-file-name-chars)
246 (lambda ()
247 (re-search-forward (concat "\\=[" thing-at-point-file-name-chars "]*")
248 nil t)))
249(put 'filename 'beginning-op
250 (lambda ()
251 (if (re-search-backward (concat "[^" thing-at-point-file-name-chars "]")
252 nil t)
253 (forward-char)
254 (goto-char (point-min)))))
255 265
256;; URIs 266;; URIs
257 267