Skip to content

Commit

Permalink
Luke Gorrie's (luke@bluetail.com) patches for implementing C-p and C-…
Browse files Browse the repository at this point in the history
…n in

Goatee.
  • Loading branch information
Timothy Moore committed Sep 9, 2002
1 parent 9b7b21b commit 0e42036
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Goatee/buffer.lisp
Expand Up @@ -85,6 +85,18 @@
(dbl-insert-after (make-buffer-line obj :tick (incf (tick obj))) (lines
obj)))

(defgeneric first-line-p (line)
(:documentation "Returns true if line is the first line in a buffer"))

(defmethod first-line-p ((line buffer-line))
(not (typep (prev line) 'buffer-line)))

(defgeneric last-line-p (line)
(:documentation "Returns true if line is the last line in a buffer"))

(defmethod last-line-p ((line buffer-line))
(null (next line)))

(defgeneric char-ref (buffer position))

(defmethod char-ref ((buf basic-buffer) position)
Expand Down
6 changes: 5 additions & 1 deletion Goatee/editable-area.lisp
Expand Up @@ -22,7 +22,11 @@
:documentation "buffer pointer to line in buffer
that's at the bottom of the area. The bp is not necessarily at the
beginning of the line.")
(last-line :accessor last-line :initarg :last-line :initform nil))
(last-line :accessor last-line :initarg :last-line :initform nil)
(last-command :accessor last-command :initform nil)
(goal-column :accessor goal-column :initform nil
:documentation "Goal column for next-line command when
moving over a short line"))
(:documentation "An abstract superclass for the on-screen area
devoted to Goatee editing. Roughly equivalent to a window in GNU Emacs."))

Expand Down
19 changes: 19 additions & 0 deletions Goatee/editable-buffer.lisp
Expand Up @@ -242,6 +242,25 @@
(defmethod end-of-buffer* ((buf editable-buffer))
(location* (buffer-end buf)))

(defgeneric next-line (buffer &optional n &key position line pos)
(:documentation "Return the line N places from LINE, and a POS in it.
If LINE is not given, uses the BUFFER's current line.
If N is negative, goes backwards.
POS is the position in the line to return as the second value (trimmed
if beyond the actual line's maximum)."))

(defmethod next-line ((buf editable-buffer) &optional (n 1)
&key (position (point buf)) line (pos 0))
(let ((line (or line (location* position)))
(forward (> n 0))
(times (abs n)))
(loop for i upto times
for cur-line = line then (if forward (next line) (prev line))
when (or (not (typep cur-line 'buffer-line)) (null cur-line))
do (error 'buffer-bounds-error :buffer buf :line line)
finally
(return (values cur-line (min pos (line-last-point cur-line)))))))

;;; These iteration constructs need a bit more thought.
;;; map-over-region in its current state may not do the right thing if
;;; the buffer is modified in the region, but what is the right thing?
Expand Down
30 changes: 29 additions & 1 deletion Goatee/goatee-command.lisp
Expand Up @@ -79,7 +79,8 @@
(print c *debug-io*)
(beep)
(return-from error-out nil)))))
(funcall command :input-gesture gesture)))
(funcall command :input-gesture gesture)
(setf (last-command area) command)))
(redisplay-area area)))))

(defun insert-character (&key input-gesture &allow-other-keys)
Expand Down Expand Up @@ -119,6 +120,24 @@
(delete-char *buffer*)
(delete-char *buffer* (- last-point pos))))))

;; Line motion

(defun up-line (&key &allow-other-keys)
(move-lines -1))

(defun down-line (&key &allow-other-keys)
(move-lines 1))

(defun move-lines (n)
(unless (goal-column-preserving-p (last-command *area*))
(setf (goal-column *area*) (pos (point *buffer*))))
(setf (point* *buffer*)
(next-line *buffer* n :pos (goal-column *area*))))

(defun goal-column-preserving-p (cmd)
(member cmd '(up-line down-line)))


(loop for i from (char-code #\space) to (char-code #\~)
do (add-gesture-command-to-table (code-char i)
'insert-character
Expand Down Expand Up @@ -163,6 +182,15 @@
(add-gesture-command-to-table '(#\u :control)
'clear-input-buffer
*simple-area-gesture-table*)

(add-gesture-command-to-table '(#\p :control)
'up-line
*simple-area-gesture-table*)

(add-gesture-command-to-table '(#\n :control)
'down-line
*simple-area-gesture-table*)

;;; Debugging fun

(defun goatee-break (&key &allow-other-keys)
Expand Down

0 comments on commit 0e42036

Please sign in to comment.