-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwords.rkt
41 lines (36 loc) · 1.12 KB
/
words.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#lang racket/base
(provide forward-word
backward-word)
;;;
;;; WORDS
;;;
; In text based modes the document is divided into:
; characters, words, sentences, and, paragraphs.
;
(require "chars.rkt"
"commands.rkt"
"region.rkt")
(define-interactive (forward-word [n 1])
"Move point n word forwards."
"If n is negative, move backwards.
The phrase 'move one word' means move until point the beginning of
a word is found, then move across that word."
(deactivate-region-mark)
(define (forward-word1)
(forward-char-predicate (λ (c) (not (char-alphabetic? c))))
(forward-char-predicate char-alphabetic?))
(cond
[(= n 1) (forward-word1)]
[(= n 0) (void)]
[(< n 0) (backward-word (- n))]
[else (for ([_ n]) (forward-word1))]))
(define-interactive (backward-word [n 1])
(deactivate-region-mark)
(define (backward-word1)
(backward-char-predicate (λ (c) (not (char-alphabetic? c))))
(backward-char-predicate char-alphabetic?))
(cond
[(= n 1) (backward-word1)]
[(= n 0) (void)]
[(< n 0) (forward-word (- n))]
[else (for ([_ n]) (backward-word1))]))