Changeset 804


Ignore:
Timestamp:
Apr 30, 2004, 7:32:04 PM (21 years ago)
Author:
Gary Byers
Message:

New history, font-region stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/hemlock/src/listener.lisp

    r780 r804  
    8484        "Pointer into \"Interactive History\"."
    8585        :buffer buffer
    86         :value 0))
    87     (move-mark (variable-value 'buffer-input-mark :buffer buffer) point)))
     86        :value 0)
     87      (defhvar "Input Regions"
     88        "Input region history list."
     89        :buffer buffer
     90        :value nil)
     91      (defhvar "Current Input Font Region"
     92          "Current font region, for listener input"
     93        :buffer buffer
     94        :value nil)
     95      (defhvar "Current Output Font Region"
     96          "Current font region, for listener output"
     97        :buffer buffer
     98        :value nil)
     99      )
     100    (let* ((input-mark (variable-value 'buffer-input-mark :buffer buffer)))
     101      (setf (hi::buffer-protected-region buffer)
     102            (region (buffer-start-mark buffer) input-mark))
     103      (move-mark input-mark point)
     104      (append-font-regions buffer))))
    88105
    89106(defmode "Listener" :major-p nil :setup-function #'setup-listener-mode)
     107
     108(declaim (special hi::*listener-input-style* hi::*listener-output-style*))
     109
     110(defun append-font-regions (buffer)
     111  (let* ((end (region-end (buffer-region buffer))))
     112    (setf (variable-value 'current-output-font-region :buffer buffer)
     113          (hi::new-font-region buffer end end hi::*listener-output-style*))
     114    (let* ((input (hi::new-font-region buffer end end hi::*listener-input-style*)))
     115      (hi::activate-buffer-font-region buffer input)
     116      (setf (variable-value 'current-input-font-region :buffer buffer) input))))
     117
     118(defun append-buffer-output (buffer string)
     119  (let* ((output-region (variable-value 'current-output-font-region
     120                                        :buffer buffer))
     121         (output-end (region-end output-region)))
     122    (hi::with-active-font-region (buffer output-region)
     123      (insert-string output-end string)
     124      (move-mark (variable-value 'buffer-input-mark :buffer buffer)
     125                 output-end))))
     126
     127
    90128
    91129(defparameter *listener-modeline-fields*
     
    129167
    130168(defvar lispbuf-eof '(nil))
    131 
    132 (defhvar "Unwedge Interactive Input Confirm"
    133   "When set (the default), trying to confirm interactive input when the
    134    point is not after the input mark causes Hemlock to ask the user if he
    135    needs to be unwedged.  When not set, an editor error is signaled
    136    informing the user that the point is before the input mark."
    137   :value t)
    138 
    139 (defun unwedge-eval-buffer ()
    140   (abort-eval-input-command nil))
    141 
    142 (defhvar "Unwedge Interactive Input Fun"
    143   "Function to call when input is confirmed, but the point is not past the
    144    input mark."
    145   :value #'unwedge-eval-buffer
    146   :mode "Listener")
    147 
    148 (defhvar "Unwedge Interactive Input String"
    149   "String to add to \"Point not past input mark.  \" explaining what will
    150    happen if the the user chooses to be unwedged."
    151   :value "Prompt again at the end of the buffer? "
    152   :mode "Listener")
    153169
    154170(defun balanced-expressions-in-region (region)
     
    186202  "Evaluate Listener Mode input between point and last prompt."
    187203  (declare (ignore p))
    188   (let ((input-region (get-interactive-input)))
     204  (let* ((input-region (get-interactive-input))
     205         (r (if input-region
     206              (region (copy-mark (region-start input-region))
     207                      (copy-mark (region-end input-region) :right-inserting)))))
     208
    189209    (when input-region
    190210      (insert-character (current-point) #\NewLine)
    191211      (when (balanced-expressions-in-region input-region)
    192         (let* ((string (region-to-string input-region)))
     212        (let* ((string (region-to-string input-region))               )
     213          (push (cons r nil) (value input-regions))
    193214          (move-mark (value buffer-input-mark) (current-point))
     215          (append-font-regions (current-buffer))
    194216          (hi::send-string-to-listener-process (hi::buffer-process (current-buffer))
    195217                                           string))))))
     
    226248
    227249;;;; General interactive commands used in eval and typescript buffers.
     250
     251(defhvar "Interactive History Length"
     252  "This is the length used for the history ring in interactive buffers.
     253   It must be set before turning on the mode."
     254  :value 10)
     255
     256(defun input-region-containing-mark (m history-list)
     257  (dolist (pair history-list)
     258    (let* ((actual (car pair))
     259           (start (region-start actual))
     260           (end (region-end actual)))
     261      (when (and (mark>= m start)
     262                 (mark<= m end))        ; sic: inclusive
     263        (return (or (cdr pair) (setf (cdr pair) (copy-region actual))))))))
     264
    228265
    229266(defun get-interactive-input ()
     
    246283          (ring-push (copy-region input-region) ring))
    247284        input-region))
    248      ((value unwedge-interactive-input-confirm)
    249       (beep)
    250       (when (prompt-for-y-or-n
    251              :prompt (concatenate 'simple-string
    252                                   "Point not past input mark.  "
    253                                   (value unwedge-interactive-input-string))
    254              :must-exist t :default t :default-string "yes")
    255         (funcall (value unwedge-interactive-input-fun))
    256         (message "Unwedged."))
    257       nil)
    258285     (t
    259       (editor-error "Point not past input mark.")))))
    260 
    261 (defhvar "Interactive History Length"
    262   "This is the length used for the history ring in interactive buffers.
    263    It must be set before turning on the mode."
    264   :value 10)
     286      (let* ((region (input-region-containing-mark point (value input-regions ))))
     287        (buffer-end point)
     288        (if region
     289          (progn
     290            (delete-region (region mark point))
     291            (insert-region point region))
     292          (beep))
     293        nil)))))
     294
    265295
    266296(defhvar "Minimum Interactive Input Length"
Note: See TracChangeset for help on using the changeset viewer.