2014-12-20 04:47:35 +00:00
|
|
|
#lang racket/base
|
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(provide (struct-out buffer-mark-type)
|
|
|
|
make-buffergroup
|
2014-12-23 16:49:17 +00:00
|
|
|
initialize-buffergroup!
|
2014-12-20 22:14:27 +00:00
|
|
|
buffer?
|
|
|
|
make-buffer
|
2014-12-22 22:14:13 +00:00
|
|
|
register-buffer!
|
|
|
|
lookup-buffer
|
2014-12-23 16:09:22 +00:00
|
|
|
unused-buffer-title
|
2014-12-22 22:14:13 +00:00
|
|
|
file->buffer
|
|
|
|
buffer-rename!
|
|
|
|
buffer-reorder!
|
|
|
|
buffer-next
|
|
|
|
buffer-prev
|
|
|
|
buffer-title
|
2014-12-27 22:15:57 +00:00
|
|
|
buffer-rope
|
2014-12-22 22:14:13 +00:00
|
|
|
buffer-group
|
2014-12-23 16:49:17 +00:00
|
|
|
buffer-editor
|
2014-12-23 06:43:01 +00:00
|
|
|
buffer-modeset
|
|
|
|
buffer-column
|
2014-12-23 16:09:22 +00:00
|
|
|
buffer-apply-modeset!
|
2014-12-23 06:43:01 +00:00
|
|
|
buffer-add-mode!
|
|
|
|
buffer-remove-mode!
|
|
|
|
buffer-toggle-mode!
|
2014-12-20 22:14:27 +00:00
|
|
|
buffer-size
|
2014-12-23 06:43:01 +00:00
|
|
|
buffer-start-of-line
|
|
|
|
buffer-end-of-line
|
2014-12-28 04:59:12 +00:00
|
|
|
buffer-mark-types
|
|
|
|
buffer-mark*
|
|
|
|
buffer-mark
|
|
|
|
buffer-mark-pos*
|
|
|
|
buffer-mark-pos
|
2014-12-20 22:14:27 +00:00
|
|
|
buffer-mark!
|
|
|
|
buffer-clear-mark!
|
2014-12-28 04:59:12 +00:00
|
|
|
buffer-move-mark!
|
|
|
|
buffer-move-mark-to-start-of-line!
|
|
|
|
buffer-move-mark-to-end-of-line!
|
2014-12-20 22:14:27 +00:00
|
|
|
buffer-region-split
|
|
|
|
buffer-region
|
|
|
|
buffer-region-update!
|
2014-12-23 06:43:01 +00:00
|
|
|
buffer-insert!
|
2014-12-23 16:09:22 +00:00
|
|
|
buffer-replace-contents!
|
2014-12-20 22:14:27 +00:00
|
|
|
buffer-search
|
2014-12-27 23:16:28 +00:00
|
|
|
buffer-findf
|
|
|
|
|
|
|
|
command?
|
|
|
|
command-selector
|
|
|
|
command-buffer
|
|
|
|
command-window
|
|
|
|
command-editor
|
|
|
|
(rename-out [make-command command])
|
|
|
|
invoke
|
|
|
|
|
|
|
|
define-key
|
|
|
|
define-command)
|
|
|
|
|
|
|
|
(require racket/match)
|
|
|
|
(require (for-syntax syntax/parse))
|
|
|
|
(require (for-syntax racket/base))
|
|
|
|
(require (only-in racket/string string-join))
|
|
|
|
(require (only-in racket/path normalize-path))
|
|
|
|
(require (only-in racket/file file->string))
|
2014-12-20 22:14:27 +00:00
|
|
|
|
2014-12-20 04:47:35 +00:00
|
|
|
(require "rope.rkt")
|
|
|
|
(require "search.rkt")
|
2014-12-22 22:14:13 +00:00
|
|
|
(require "circular-list.rkt")
|
2014-12-23 06:43:01 +00:00
|
|
|
(require "mode.rkt")
|
2014-12-23 16:49:17 +00:00
|
|
|
(require "keys.rkt")
|
2014-12-22 22:14:13 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(struct buffer-mark-type (kind ;; Symbol
|
|
|
|
window-id ;; Symbol
|
|
|
|
preserve? ;; Boolean
|
|
|
|
) #:prefab)
|
2014-12-20 17:52:35 +00:00
|
|
|
|
2014-12-22 22:14:13 +00:00
|
|
|
(struct buffergroup ([members #:mutable] ;; (CircularList Buffer)
|
2014-12-23 16:49:17 +00:00
|
|
|
[editor #:mutable] ;; (Option Editor), for bidirectional editor/group linkage
|
2014-12-22 22:17:05 +00:00
|
|
|
) #:prefab)
|
2014-12-22 22:14:13 +00:00
|
|
|
|
2014-12-20 04:47:35 +00:00
|
|
|
(struct buffer ([rope #:mutable]
|
2014-12-22 22:14:13 +00:00
|
|
|
[title #:mutable]
|
|
|
|
[group #:mutable] ;; (Option BufferGroup)
|
2014-12-23 06:43:01 +00:00
|
|
|
[modeset #:mutable] ;; ModeSet
|
2014-12-22 22:17:05 +00:00
|
|
|
) #:prefab)
|
2014-12-20 04:47:35 +00:00
|
|
|
|
2014-12-27 23:16:28 +00:00
|
|
|
(struct command (selector ;; Symbol
|
|
|
|
buffer ;; Buffer
|
|
|
|
window ;; (Option Window)
|
|
|
|
editor ;; Editor
|
|
|
|
keyseq ;; (Option Keyseq)
|
|
|
|
prefix-arg ;; Any
|
|
|
|
) #:prefab)
|
|
|
|
|
2014-12-22 22:14:13 +00:00
|
|
|
(define (make-buffergroup)
|
2014-12-23 16:49:17 +00:00
|
|
|
(buffergroup circular-empty #f))
|
|
|
|
|
|
|
|
(define (initialize-buffergroup! g editor)
|
|
|
|
(when (buffergroup-editor g)
|
|
|
|
(error 'initialize-buffergroup! "Duplicate initialization of buffergroup"))
|
|
|
|
(set-buffergroup-editor! g editor)
|
|
|
|
g)
|
2014-12-22 22:14:13 +00:00
|
|
|
|
2014-12-23 16:09:22 +00:00
|
|
|
(define (initial-contents-rope initial-contents)
|
|
|
|
(cond
|
|
|
|
[(string? initial-contents) (string->rope initial-contents)]
|
|
|
|
[(rope? initial-contents) initial-contents]
|
|
|
|
[(procedure? initial-contents) (initial-contents-rope (initial-contents))]
|
|
|
|
[else (error 'initial-contents-rope "Invalid initial-contents: ~v" initial-contents)]))
|
|
|
|
|
2014-12-22 22:14:13 +00:00
|
|
|
(define (make-buffer group ;; (Option BufferGroup)
|
|
|
|
title ;; String
|
|
|
|
#:initial-contents [initial-contents ""])
|
2014-12-23 16:09:22 +00:00
|
|
|
(register-buffer! group (buffer (initial-contents-rope initial-contents)
|
2014-12-22 22:14:13 +00:00
|
|
|
title
|
2014-12-23 06:43:01 +00:00
|
|
|
#f
|
|
|
|
kernel-modeset)))
|
2014-12-22 22:14:13 +00:00
|
|
|
|
|
|
|
(define (register-buffer! group buf)
|
|
|
|
(define old-group (buffer-group buf))
|
|
|
|
(when old-group
|
|
|
|
(set-buffergroup-members! old-group
|
|
|
|
(circular-list-remove buf (buffergroup-members old-group) eq?))
|
|
|
|
(set-buffer-group! buf #f))
|
|
|
|
(cond
|
|
|
|
[(not group) buf]
|
|
|
|
[(title->buffer* group (buffer-title buf)) #f]
|
|
|
|
[else
|
|
|
|
(set-buffer-group! buf group)
|
|
|
|
(set-buffergroup-members! group (circular-cons buf (buffergroup-members group)))
|
|
|
|
buf]))
|
|
|
|
|
|
|
|
(define (title->buffer* group title)
|
|
|
|
(and group
|
2014-12-28 04:59:12 +00:00
|
|
|
(circular-list-memf (lambda (b) (equal? (buffer-title b) title))
|
|
|
|
(buffergroup-members group))))
|
2014-12-22 22:14:13 +00:00
|
|
|
|
|
|
|
(define (buffer->buffer* group b)
|
|
|
|
(and group
|
|
|
|
(circular-list-memf (lambda (b1) (eq? b b1)) (buffergroup-members group))))
|
|
|
|
|
|
|
|
(define (lookup-buffer group title)
|
|
|
|
(cond [(title->buffer* group title) => circular-car] [else #f]))
|
|
|
|
|
|
|
|
(define (title-exists-in-group? group title)
|
|
|
|
(and (title->buffer* group title) #t))
|
|
|
|
|
2014-12-23 16:09:22 +00:00
|
|
|
(define (unused-buffer-title group context-pieces)
|
|
|
|
(define primary-piece (if (null? context-pieces) "*anonymous*" (car context-pieces)))
|
|
|
|
(define uniquifiers (if (null? context-pieces) '() (cdr context-pieces)))
|
|
|
|
(let search ((used '()) (remaining uniquifiers))
|
|
|
|
(define candidate
|
|
|
|
(if (null? used)
|
|
|
|
primary-piece
|
|
|
|
(format "~a<~a>" primary-piece (string-join used "/"))))
|
|
|
|
(if (title-exists-in-group? group candidate)
|
|
|
|
(if (pair? remaining)
|
|
|
|
(search (cons (car remaining) used) (cdr remaining))
|
|
|
|
(let search ((counter 2))
|
|
|
|
(define candidate (format "~a<~a>" primary-piece counter))
|
|
|
|
(if (title-exists-in-group? group candidate)
|
|
|
|
(search (+ counter 1))
|
|
|
|
candidate)))
|
|
|
|
candidate)))
|
|
|
|
|
2014-12-22 22:14:13 +00:00
|
|
|
;; (Option Group) Path -> String
|
|
|
|
(define (filename->unique-buffer-title group filename)
|
|
|
|
(define pieces (reverse (map path->string (explode-path filename))))
|
|
|
|
(if (not group)
|
2014-12-23 16:09:22 +00:00
|
|
|
(car pieces)
|
|
|
|
(unused-buffer-title group pieces)))
|
2014-12-22 22:14:13 +00:00
|
|
|
|
|
|
|
(define (file->buffer group filename)
|
|
|
|
(let* ((filename (normalize-path (simplify-path filename)))
|
|
|
|
(title (filename->unique-buffer-title group filename))
|
|
|
|
(b (make-buffer group title)))
|
2014-12-28 04:59:12 +00:00
|
|
|
(buffer-replace-contents! b (string->rope (file->string filename)))))
|
2014-12-22 22:14:13 +00:00
|
|
|
|
|
|
|
(define (buffer-rename! b new-title)
|
|
|
|
(if (title-exists-in-group? (buffer-group b) new-title)
|
|
|
|
#f
|
|
|
|
(begin (set-buffer-title! b new-title)
|
|
|
|
b)))
|
|
|
|
|
|
|
|
(define (buffer-reorder! b)
|
|
|
|
;; Reorders b to the top of the group as a side-effect
|
|
|
|
(register-buffer! (buffer-group b) b))
|
|
|
|
|
|
|
|
(define (buffer-next b)
|
|
|
|
(cond [(buffer->buffer* (buffer-group b) b) => (compose circular-car circular-list-rotate-forward)]
|
|
|
|
[else #f]))
|
|
|
|
|
|
|
|
(define (buffer-prev b)
|
|
|
|
(cond [(buffer->buffer* (buffer-group b) b) => (compose circular-car circular-list-rotate-backward)]
|
|
|
|
[else #f]))
|
2014-12-20 04:47:35 +00:00
|
|
|
|
|
|
|
(define (buffer-size buf) (rope-size (buffer-rope buf)))
|
|
|
|
|
2014-12-23 16:49:17 +00:00
|
|
|
(define (buffer-editor b)
|
|
|
|
(define g (buffer-group b))
|
|
|
|
(and g (buffergroup-editor g)))
|
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-column buf pos-or-mtype)
|
|
|
|
;; TODO: count actual columns!
|
|
|
|
(define pos (->pos buf pos-or-mtype 'buffer-column))
|
|
|
|
(- pos (buffer-start-of-line buf pos)))
|
2014-12-23 06:43:01 +00:00
|
|
|
|
2014-12-23 16:09:22 +00:00
|
|
|
(define (buffer-apply-modeset! buf modeset)
|
|
|
|
(set-buffer-modeset! buf modeset))
|
|
|
|
|
2014-12-23 06:43:01 +00:00
|
|
|
(define (buffer-add-mode! buf mode)
|
|
|
|
(set-buffer-modeset! buf (modeset-add-mode (buffer-modeset buf) mode)))
|
|
|
|
(define (buffer-remove-mode! buf mode)
|
|
|
|
(set-buffer-modeset! buf (modeset-remove-mode (buffer-modeset buf) mode)))
|
|
|
|
(define (buffer-toggle-mode! buf mode)
|
|
|
|
(set-buffer-modeset! buf (modeset-toggle-mode (buffer-modeset buf) mode)))
|
|
|
|
|
|
|
|
(define (clamp pos buf)
|
|
|
|
(max 0 (min (buffer-size buf) pos)))
|
|
|
|
|
2014-12-20 04:47:35 +00:00
|
|
|
(define (buffer-seek! buf pos)
|
2014-12-28 04:59:12 +00:00
|
|
|
(buffer-lift rope-seek buf (clamp pos buf)))
|
|
|
|
|
|
|
|
(define (buffer-start-of-line buf pos-or-mtype)
|
|
|
|
(buffer-findf buf pos-or-mtype (lambda (ch) (equal? ch #\newline)) #:forward? #f))
|
2014-12-20 04:47:35 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-end-of-line buf pos-or-mtype)
|
|
|
|
(buffer-findf buf pos-or-mtype (lambda (ch) (equal? ch #\newline)) #:forward? #t))
|
2014-12-20 04:47:35 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (->pos buf pos-or-mtype what)
|
|
|
|
(clamp (if (number? pos-or-mtype)
|
|
|
|
pos-or-mtype
|
|
|
|
(buffer-mark-pos buf pos-or-mtype what))
|
|
|
|
buf))
|
2014-12-23 06:43:01 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-mark-types buf)
|
|
|
|
(rope-marks (buffer-rope buf)))
|
2014-12-23 06:43:01 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-mark* buf mtype)
|
|
|
|
(find-mark (buffer-rope buf) mtype))
|
2014-12-23 06:43:01 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-mark buf mtype [what 'buffer-mark])
|
|
|
|
(or (buffer-mark* buf mtype)
|
|
|
|
(error what "Mark type ~v not found; available mark types ~v" mtype (buffer-mark-types buf))))
|
2014-12-23 06:43:01 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-mark-pos* buf mtype)
|
|
|
|
(find-mark-pos (buffer-rope buf) mtype))
|
|
|
|
|
|
|
|
(define (buffer-mark-pos buf mtype [what 'buffer-mark-pos])
|
|
|
|
(or (buffer-mark-pos* buf mtype)
|
|
|
|
(error what "Mark type ~v not found; available mark types ~v" mtype (buffer-mark-types buf))))
|
2014-12-20 22:14:27 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-mark! buf mtype pos-or-mtype #:value [value #t])
|
|
|
|
(buffer-lift replace-mark buf mtype (->pos buf pos-or-mtype 'buffer-mark!) value))
|
|
|
|
|
|
|
|
(define (buffer-clear-mark! buf mtype)
|
|
|
|
(define pos (buffer-mark-pos* buf mtype))
|
2014-12-20 22:14:27 +00:00
|
|
|
(if pos
|
|
|
|
(buffer-lift clear-mark buf mtype pos)
|
|
|
|
buf))
|
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-move-mark! buf mtype delta)
|
|
|
|
(match-define (cons pos val) (buffer-mark buf mtype 'buffer-move-mark!))
|
|
|
|
(buffer-mark! buf mtype (+ pos delta) #:value val))
|
2014-12-20 22:14:27 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-move-mark-to-start-of-line! buf mtype)
|
|
|
|
(define pos (buffer-mark-pos buf mtype 'buffer-move-mark-to-start-of-line!))
|
|
|
|
(buffer-mark! buf mtype (buffer-start-of-line buf pos)))
|
|
|
|
|
|
|
|
(define (buffer-move-mark-to-end-of-line! buf mtype)
|
|
|
|
(define pos (buffer-mark-pos buf mtype 'buffer-move-mark-to-end-of-line!))
|
|
|
|
(buffer-mark! buf mtype (buffer-end-of-line buf pos)))
|
|
|
|
|
|
|
|
(define (buffer-region-split buf pm1 pm2)
|
|
|
|
(define p1 (->pos buf pm1 'buffer-region-split))
|
|
|
|
(define p2 (->pos buf pm2 'buffer-region-split))
|
|
|
|
(define lo (min p1 p2))
|
|
|
|
(define hi (max p1 p2))
|
2014-12-20 22:14:27 +00:00
|
|
|
(define-values (l mr) (rope-split (buffer-rope buf) lo))
|
|
|
|
(define-values (m r) (rope-split mr (- hi lo)))
|
2014-12-23 06:43:01 +00:00
|
|
|
(values l lo m hi r))
|
2014-12-20 22:14:27 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-region buf pm1 pm2)
|
|
|
|
(define-values (_l _lo m _hi _r) (buffer-region-split buf pm1 pm2))
|
2014-12-20 22:14:27 +00:00
|
|
|
m)
|
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (transfer-marks ro rn)
|
|
|
|
(define mtypes-to-transfer
|
|
|
|
(for/list ((mtype (rope-marks ro))
|
|
|
|
#:when (buffer-mark-type-preserve? (mark-type-info mtype)))
|
|
|
|
mtype))
|
|
|
|
(for/fold [(rn rn)] [(mtype mtypes-to-transfer)]
|
|
|
|
(define pos (case (mark-type-stickiness mtype)
|
|
|
|
[(left) 0]
|
|
|
|
[(right) (rope-size rn)]))
|
|
|
|
(set-mark rn mtype pos #t)))
|
|
|
|
|
|
|
|
(define (buffer-region-update! buf pm1 pm2 updater)
|
|
|
|
(define-values (l lo old-m hi r) (buffer-region-split buf pm1 pm2))
|
|
|
|
(define new-m (transfer-marks old-m (updater old-m)))
|
2014-12-23 06:43:01 +00:00
|
|
|
(define delta (- (rope-size new-m) (rope-size old-m)))
|
|
|
|
(set-buffer-rope! buf (rope-append (rope-append l new-m) r))
|
2014-12-28 04:59:12 +00:00
|
|
|
buf)
|
|
|
|
|
|
|
|
(define (buffer-insert! buf pos-or-mtype content-rope)
|
|
|
|
(define pos (->pos buf pos-or-mtype 'buffer-insert!))
|
2014-12-23 06:43:01 +00:00
|
|
|
(define-values (l r) (rope-split (buffer-rope buf) pos))
|
|
|
|
(set-buffer-rope! buf (rope-append (rope-append l content-rope) r))
|
2014-12-20 22:14:27 +00:00
|
|
|
buf)
|
|
|
|
|
2014-12-23 16:09:22 +00:00
|
|
|
(define (buffer-replace-contents! buf content-rope)
|
2014-12-28 04:59:12 +00:00
|
|
|
(buffer-region-update! buf 0 (buffer-size buf) (lambda (_dontcare) content-rope)))
|
|
|
|
|
|
|
|
(define (buffer-search* buf start-pos-or-mtype forward? find-delta)
|
|
|
|
(define start-pos (->pos buf start-pos-or-mtype 'buffer-search*))
|
2014-12-20 17:52:35 +00:00
|
|
|
(define-values (l r) (rope-split (buffer-rope buf) start-pos))
|
2014-12-20 04:47:35 +00:00
|
|
|
(define delta (find-delta (if forward? r l)))
|
2014-12-23 06:43:01 +00:00
|
|
|
(and delta
|
|
|
|
(let ((new-pos (clamp (+ start-pos (cond [(not delta) 0]
|
|
|
|
[forward? delta]
|
|
|
|
[else (- delta (rope-size l))]))
|
|
|
|
buf)))
|
2014-12-28 04:59:12 +00:00
|
|
|
(buffer-seek! buf new-pos)
|
2014-12-23 06:43:01 +00:00
|
|
|
new-pos)))
|
2014-12-20 04:47:35 +00:00
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-search buf start-pos-or-mtype needle #:forward? [forward? #t])
|
|
|
|
(buffer-search* buf start-pos-or-mtype forward?
|
2014-12-20 04:47:35 +00:00
|
|
|
(lambda (piece) (search-rope needle piece #:forward? forward?))))
|
|
|
|
|
2014-12-28 04:59:12 +00:00
|
|
|
(define (buffer-findf buf start-pos-or-mtype f #:forward? [forward? #t])
|
|
|
|
(buffer-search* buf start-pos-or-mtype forward?
|
2014-12-22 22:14:13 +00:00
|
|
|
(lambda (piece) (findf-in-rope f piece #:forward? forward?))))
|
2014-12-20 04:47:35 +00:00
|
|
|
|
2014-12-20 22:14:27 +00:00
|
|
|
(define (buffer-lift f buf . args)
|
2014-12-20 04:47:35 +00:00
|
|
|
(define new-rope (apply f (buffer-rope buf) args))
|
|
|
|
(set-buffer-rope! buf new-rope)
|
|
|
|
buf)
|
2014-12-27 23:16:28 +00:00
|
|
|
|
|
|
|
;;---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(define (make-command selector buffer-or-command
|
|
|
|
#:window [window #f]
|
|
|
|
#:editor [editor #f]
|
|
|
|
#:keyseq [keyseq #f]
|
|
|
|
#:prefix-arg [prefix-arg '#:default])
|
|
|
|
(define buffer (cond
|
|
|
|
[(buffer? buffer-or-command) buffer-or-command]
|
|
|
|
[(command? buffer-or-command) (command-buffer buffer-or-command)]))
|
|
|
|
(command selector buffer window (or editor (buffer-editor buffer)) keyseq prefix-arg))
|
|
|
|
|
|
|
|
(define (invoke cmd)
|
|
|
|
(match-define (command selector buf _ _ keyseq _) cmd)
|
|
|
|
(define handler (modeset-lookup-command (buffer-modeset buf) selector))
|
|
|
|
(when (not handler)
|
|
|
|
(error 'invoke "Unhandled command ~a (key sequence: ~a)"
|
|
|
|
selector
|
|
|
|
(if keyseq (keyseq->keyspec keyseq) "N/A")))
|
|
|
|
(handler cmd))
|
|
|
|
|
|
|
|
(define-syntax-rule (define-key mode-exp keyspec-exp command-symbol)
|
|
|
|
(void (mode-keymap-bind! mode-exp keyspec-exp 'command-symbol)))
|
|
|
|
|
|
|
|
(define-syntax define-command
|
|
|
|
(lambda (stx)
|
|
|
|
(syntax-parse stx
|
|
|
|
[(_ mode-exp
|
|
|
|
(selector buffer
|
|
|
|
(~or (~optional (~seq #:next-method next-method)
|
|
|
|
#:defaults ([next-method #'nm])
|
|
|
|
#:name "#:next-method")
|
|
|
|
(~optional (~seq #:command cmd)
|
|
|
|
#:defaults ([cmd #'cmd])
|
|
|
|
#:name "#:command")
|
|
|
|
(~optional (~seq #:selector self-selector)
|
|
|
|
#:defaults ([self-selector #'self])
|
|
|
|
#:name "#:selector")
|
|
|
|
(~optional (~seq #:window window)
|
|
|
|
#:defaults ([window #'win])
|
|
|
|
#:name "#:window")
|
|
|
|
(~optional (~seq #:editor editor)
|
|
|
|
#:defaults ([editor #'ed])
|
|
|
|
#:name "#:editor")
|
|
|
|
(~optional (~seq #:keyseq keyseq)
|
|
|
|
#:defaults ([keyseq #'keyseq])
|
|
|
|
#:name "#:keyseq")
|
|
|
|
(~optional (~seq #:prefix-arg
|
|
|
|
(~or (~seq [prefix-arg prefix-default prefix-prefix])
|
|
|
|
(~seq [prefix-arg prefix-default])
|
|
|
|
prefix-arg))
|
|
|
|
#:defaults ([prefix-arg #'pa]
|
|
|
|
[prefix-default #''#:default]
|
|
|
|
[prefix-prefix #''#:prefix])
|
|
|
|
#:name "#:prefix-arg"))
|
|
|
|
...)
|
|
|
|
(~seq #:bind-key bind-keyspec-exps) ...
|
|
|
|
body ...)
|
|
|
|
#`(let ((mode mode-exp))
|
|
|
|
(mode-define-command! mode
|
|
|
|
'selector
|
|
|
|
(lambda (cmd next-method)
|
|
|
|
(match-define (command self-selector
|
|
|
|
buffer
|
|
|
|
window
|
|
|
|
editor
|
|
|
|
keyseq
|
|
|
|
prefix-arg) cmd)
|
|
|
|
(let ((prefix-arg (match prefix-arg
|
|
|
|
['#:default prefix-default]
|
|
|
|
['#:prefix prefix-prefix]
|
|
|
|
[_ prefix-arg])))
|
|
|
|
body ...)))
|
|
|
|
#,@(for/list ((bind-keyspec-exp (syntax->list #'(bind-keyspec-exps ...))))
|
|
|
|
#`(mode-keymap-bind! mode #,bind-keyspec-exp 'selector))
|
|
|
|
(void))])))
|