Skip to content

Commit

Permalink
Merge pull request #3 from florence/new-bindings
Browse files Browse the repository at this point in the history
New bindings
  • Loading branch information
takikawa committed Nov 20, 2013
2 parents b757dc1 + 480cbd9 commit d553994
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compiled
*~
29 changes: 28 additions & 1 deletion private/text.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
get-position
set-position
move-position
insert
copy paste kill undo redo delete
line-start-position line-end-position position-line
get-view-size local-to-global
Expand Down Expand Up @@ -178,7 +179,8 @@
(let ([b (box 0)])
(get-position b)
(define line (position-line (unbox b)))
(f (line-start-position line)
(define start (line-start-position line))
(f (if (zero? start) start (sub1 start))
(line-end-position line))))

(define-syntax-rule (do-word f)
Expand Down Expand Up @@ -209,6 +211,12 @@
[#\i (set-mode! 'insert)]
[#\I (begin (move-position 'left #f 'line)
(set-mode! 'insert))]
[#\O (begin (insert-line-before)
(move-position 'up)
(set-mode! 'insert))]
[#\o (begin (insert-line-after)
(move-position 'down)
(set-mode! 'insert))]
;; modes
[#\v (set-mode! 'visual)]
[#\V (set-mode! 'visual-line)]
Expand Down Expand Up @@ -383,6 +391,25 @@
(get-position b)
(set-position (unbox b) 'same)
(set-mode! 'command)))

;; insert line after the line the cursor is currently on
(define/private (insert-line-after)
(define-values (_start end) (get-current-line-start-end))
(send this insert "\n" end))

;; insert line before the line the cursor is currently on
(define/private (insert-line-before)
(define-values (start _end) (get-current-line-start-end))
(send this insert "\n" (if (zero? start) start (sub1 start))))

;; -> (values int int)
;; gets the start and end position of the line at the start of current selection
(define/private (get-current-line-start-end)
(define b (box 0))
(get-position b)
(define line (position-line (unbox b)))
(values (line-start-position line)
(line-end-position line)))

(super-new))))

0 comments on commit d553994

Please sign in to comment.