Add define-thing-chars and use it for filename.

(define-thing-chars): New defmacro.
(filename): Define this thing using `define-thing-chars'.
This commit is contained in:
Sam Steingold 2017-09-18 12:54:29 -04:00
parent 0925a20e0a
commit 9dbdc0f005

View 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