C-x b (switch-to-buffer)
This commit is contained in:
parent
337e26b6c3
commit
435a233c14
|
@ -3,6 +3,7 @@
|
||||||
(provide (struct-out buffer-mark-type)
|
(provide (struct-out buffer-mark-type)
|
||||||
make-buffergroup
|
make-buffergroup
|
||||||
initialize-buffergroup!
|
initialize-buffergroup!
|
||||||
|
buffergroup-buffer-titles
|
||||||
buffer?
|
buffer?
|
||||||
make-buffer
|
make-buffer
|
||||||
register-buffer!
|
register-buffer!
|
||||||
|
@ -116,6 +117,9 @@
|
||||||
(set-buffergroup-editor! g editor)
|
(set-buffergroup-editor! g editor)
|
||||||
g)
|
g)
|
||||||
|
|
||||||
|
(define (buffergroup-buffer-titles g)
|
||||||
|
(map buffer-title (circular-list->list (buffergroup-members g))))
|
||||||
|
|
||||||
(define (initial-contents-rope initial-contents)
|
(define (initial-contents-rope initial-contents)
|
||||||
(cond
|
(cond
|
||||||
[(string? initial-contents) (string->rope initial-contents)]
|
[(string? initial-contents) (string->rope initial-contents)]
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
(provide (except-out (struct-out editor) editor)
|
(provide (except-out (struct-out editor) editor)
|
||||||
make-editor
|
make-editor
|
||||||
configure-fresh-buffer!
|
configure-fresh-buffer!
|
||||||
|
find-buffer
|
||||||
window-layout
|
window-layout
|
||||||
window-width
|
window-width
|
||||||
window-height
|
window-height
|
||||||
|
@ -288,7 +289,7 @@
|
||||||
(message editor "Unbound key sequence: ~a" (keyseq->keyspec total-keyseq)))
|
(message editor "Unbound key sequence: ~a" (keyseq->keyspec total-keyseq)))
|
||||||
(loop '() '() (root-keyseq-handler editor) (request-repaint))]
|
(loop '() '() (root-keyseq-handler editor) (request-repaint))]
|
||||||
[(incomplete-key-sequence next-handler)
|
[(incomplete-key-sequence next-handler)
|
||||||
(message editor "~a-" (keyseq->keyspec total-keyseq))
|
(message #:log? #f editor "~a-" (keyseq->keyspec total-keyseq))
|
||||||
(wait-for-input next-handler)]
|
(wait-for-input next-handler)]
|
||||||
[(command-invocation selector prefix-arg remaining-input)
|
[(command-invocation selector prefix-arg remaining-input)
|
||||||
(define accepted-input
|
(define accepted-input
|
||||||
|
@ -318,16 +319,18 @@
|
||||||
(invalidate-layout! editor)))
|
(invalidate-layout! editor)))
|
||||||
|
|
||||||
(define (message #:duration [duration0 #f]
|
(define (message #:duration [duration0 #f]
|
||||||
|
#:log? [log? #t]
|
||||||
editor fmt . args)
|
editor fmt . args)
|
||||||
(define duration (or duration0 (and (editor-recursive-edit editor) 2)))
|
(define duration (or duration0 (and (editor-recursive-edit editor) 2)))
|
||||||
(define msg (string->rope (apply format fmt args)))
|
(define msg (string->rope (apply format fmt args)))
|
||||||
(define echo-area (editor-echo-area editor))
|
(define echo-area (editor-echo-area editor))
|
||||||
(let* ((msgbuf (find-buffer editor "*Messages*"))
|
(when log?
|
||||||
(msgwins (filter (lambda (w) (equal? (buffer-mark-pos msgbuf (window-point w))
|
(let* ((msgbuf (find-buffer editor "*Messages*"))
|
||||||
(buffer-size msgbuf)))
|
(msgwins (filter (lambda (w) (equal? (buffer-mark-pos msgbuf (window-point w))
|
||||||
(windows-for-buffer editor msgbuf))))
|
(buffer-size msgbuf)))
|
||||||
(buffer-insert! msgbuf (buffer-size msgbuf) (rope-append msg (string->rope "\n")))
|
(windows-for-buffer editor msgbuf))))
|
||||||
(for ((w msgwins)) (buffer-mark! msgbuf (window-point w) (buffer-size msgbuf))))
|
(buffer-insert! msgbuf (buffer-size msgbuf) (rope-append msg (string->rope "\n")))
|
||||||
|
(for ((w msgwins)) (buffer-mark! msgbuf (window-point w) (buffer-size msgbuf)))))
|
||||||
(buffer-replace-contents! echo-area msg)
|
(buffer-replace-contents! echo-area msg)
|
||||||
(set-window-buffer! (editor-mini-window editor) echo-area (buffer-size echo-area))
|
(set-window-buffer! (editor-mini-window editor) echo-area (buffer-size echo-area))
|
||||||
(invalidate-layout! editor)
|
(invalidate-layout! editor)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
(require racket/set)
|
(require racket/set)
|
||||||
(require racket/match)
|
(require racket/match)
|
||||||
|
(require racket/string)
|
||||||
(require "../api.rkt")
|
(require "../api.rkt")
|
||||||
|
|
||||||
(define fundamental-mode (make-mode "fundamental"))
|
(define fundamental-mode (make-mode "fundamental"))
|
||||||
|
@ -172,3 +173,18 @@
|
||||||
(invoke (copy-command cmd
|
(invoke (copy-command cmd
|
||||||
#:selector (string->symbol content)
|
#:selector (string->symbol content)
|
||||||
#:keyseq #f)))))
|
#:keyseq #f)))))
|
||||||
|
|
||||||
|
(define-command fundamental-mode (switch-to-buffer buf #:window win #:editor ed)
|
||||||
|
#:bind-key "C-x b"
|
||||||
|
(define default-target (buffer-next buf))
|
||||||
|
(completing-read ed
|
||||||
|
(format "Switch to buffer~a: "
|
||||||
|
(if default-target
|
||||||
|
(format " (default ~a)" (buffer-title default-target))
|
||||||
|
""))
|
||||||
|
(simple-completion (buffergroup-buffer-titles (editor-buffers ed)))
|
||||||
|
#:on-accept (lambda (title0)
|
||||||
|
(define title1 (string-trim title0))
|
||||||
|
(define title (if (equal? title1 "") #f title1))
|
||||||
|
(define target (if title (find-buffer ed title) default-target))
|
||||||
|
(set-window-buffer! win target))))
|
||||||
|
|
Loading…
Reference in New Issue