Changeset 597


Ignore:
Timestamp:
Mar 1, 2004, 9:01:42 AM (21 years ago)
Author:
Gary Byers
Message:

More changes. Every day, more changes. (Listeners kind of work now.)

Location:
trunk/ccl
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/examples/cocoa-editor.lisp

    r592 r597  
    171171                     hemlock-buffer-string)
    172172  (let* ((cache (hemlock-buffer-string-cache self)))
    173       (or (buffer-cache-buflen cache)
    174           (setf (buffer-cache-buflen cache)
    175                 (hemlock-buffer-length (buffer-cache-buffer cache))))))
     173    (force-output)
     174    (or (buffer-cache-buflen cache)
     175        (setf (buffer-cache-buflen cache)
     176              (hemlock-buffer-length (buffer-cache-buffer cache))))))
    176177
    177178
     
    489490;;; Hook things up so that the modeline is updated whenever certain buffer
    490491;;; attributes change.
    491 (hi::%init-redisplay)
     492(hi::%init-mode-redisplay)
    492493
    493494
     
    869870
    870871(defun hi::document-end-editing (document)
    871   (send (slot-value document 'textstorage) 'end-editing))
     872  (let* ((textstorage (slot-value document 'textstorage)))
     873    (send textstorage 'end-editing)
     874    (for-each-textview-using-storage
     875     textstorage
     876     #'(lambda (tv)
     877         (send tv :scroll-range-to-visible (send tv 'selected-range))))))
    872878
    873879(defun hi::document-set-point-position (document)
     
    881887     #'(lambda (tv)
    882888         (slet ((selection (ns-make-range pos 0)))
    883           (send tv :set-selected-range selection)
    884           (send tv :scroll-range-to-visible selection))))))
     889          (send tv :set-selected-range selection))))))
    885890
    886891
     
    903908          (unless (eq (hi::mark-%kind mark) :right-inserting)
    904909            (decf pos n))
    905           #+debug 0
     910          #+debug
    906911          (format t "~&pos = ~d, n = ~d" pos n)
    907912          (let* ((display (hemlock-buffer-string-cache (send textstorage 'string))))
     
    919924        (let* ((pos (mark-absolute-position mark)))
    920925          (setq n (abs n))
     926          #+debug
     927          (format t "~& pos = ~d, n = ~d" pos n)
     928          (force-output)
     929          (send textstorage
     930                :edited #$NSTextStorageEditedCharacters
     931                :range (ns-make-range pos n)
     932                :change-in-length (- n))
    921933          (let* ((cache (hemlock-buffer-string-cache (send textstorage 'string))))
    922934            (reset-buffer-cache cache)
    923             (update-line-cache-for-index cache pos))
    924 
    925           (send textstorage
    926                 :edited #$NSTextStorageEditedAttributes
    927                 :range (ns-make-range pos n)
    928                 :change-in-length (- n)))))))
     935            (update-line-cache-for-index cache pos)))))))
    929936
    930937(defun hi::set-document-modified (document flag)
  • trunk/ccl/examples/cocoa-listener.lisp

    r592 r597  
    100100      (declare (dynamic-extent string))
    101101      (%copy-ptr-to-ivector (send data 'bytes) 0 string 0 data-length)
    102       (hi::insert-string (hi::buffer-point buffer) string)
     102      (let* ((input-mark (hi::variable-value 'hemlock::buffer-input-mark :buffer buffer)))
     103        (hi:with-mark ((mark input-mark :left-inserting))
     104          (hi::insert-string mark string)
     105          (hi::move-mark input-mark mark)))
    103106      (send fh 'read-in-background-and-notify))))
    104107             
     
    122125|#
    123126
    124 ;;; Action methods implemented by the controller (in its role as the
    125 ;;; textview's delegate).
    126 
    127 
    128 (define-objc-method ((:void :send-string string)
    129                      lisp-listener-window-controller)
    130   (send (slot-value self 'filehandle)
    131         :write-data (send string
    132                           :data-using-encoding #$NSASCIIStringEncoding
    133                           :allow-lossy-conversion t)))
     127
     128
     129
     130
    134131
    135132
     
    176173  (:metaclass ns:+ns-object))
    177174
     175(defun hemlock::listener-document-send-string (document string)
     176  (let* ((controller (send (send document 'window-controllers)
     177                          :object-at-index 0))
     178         (filehandle (slot-value controller 'filehandle))
     179         (len (length string))
     180         (data (send (make-objc-instance 'ns-mutable-data
     181                                         :with-length len) 'autorelease))
     182         (bytes (send data 'mutable-bytes)))
     183    (%copy-ivector-to-ptr string 0 bytes 0 len)
     184    (send filehandle :write-data data)
     185    (send filehandle 'synchronize-file)))
     186
    178187
    179188(define-objc-class-method ((:id top-listener) lisp-listener-document)
     
    211220        (setf (hi::buffer-pathname buffer) nil
    212221              (hi::buffer-minor-mode buffer "Listener") t
    213               (hi::buffer-name buffer) listener-name)))
     222              (hi::buffer-name buffer) listener-name)
     223        (hi::sub-set-buffer-modeline-fields buffer hemlock::*listener-modeline-fields*)))
    214224    doc))
    215225
     
    244254|#
    245255
    246 
    247 
     256(defun cocoa-ide-note-package (package)
     257  (process-interrupt *cocoa-event-process*
     258                       #'(lambda (proc name)
     259                           (dolist (buf hi::*buffer-list*)
     260                             (when (eq proc (hi::buffer-process buf))
     261                               (setf (hi::variable-value 'hemlock::current-package :buffer buf) name))))
     262                       *current-process*
     263                       (package-name package)))
     264
     265(defmethod ui-object-do-operation ((o cocoa-ide-ui-object)
     266                                   operation &rest args)
     267  (case operation
     268    (:note-package (cocoa-ide-note-package (car args)))))
     269
     270       
     271 
  • trunk/ccl/examples/cocoa-window.lisp

    r569 r597  
    353353      (send dict :set-object color :for-key #@"NSColor"))
    354354    dict))
     355
  • trunk/ccl/examples/cocoa.lisp

    r430 r597  
    1111(fake-cfbundle-path "ccl:OpenMCL.app;Contents;MacOS;dppccl"))
    1212
     13(defclass cocoa-ide-ui-object (ui-object)
     14    ())
    1315
     16(setf (application-ui-object *application*) (make-instance 'cocoa-ide-ui-object))
    1417
    1518(require "OBJC-SUPPORT")
  • trunk/ccl/examples/compile-hemlock.lisp

    r591 r597  
    158158                    (mapcar #'hemlock-binary-pathname *hemlock-files*)
    159159                    :if-exists :supersede)
     160  (provide "HEMLOCK")
    160161  )
  • trunk/ccl/hemlock/src/buffer.lisp

    r569 r597  
    460460(defun defmode (name &key (setup-function #'identity)
    461461                     (cleanup-function #'identity) major-p transparent-p
    462                      precedence documentation)
     462                     precedence documentation hidden)
    463463  "Define a new mode, specifying whether it is a major mode, and what the
    464464   setup and cleanup functions are.  Precedence, which defaults to 0.0, and is
     
    491491                  :variables (make-string-table)
    492492                  :bindings (make-hash-table)
    493                   :hook-name (getstring hook-str *global-variable-names*)))
     493                  :hook-name (getstring hook-str *global-variable-names*)
     494                  :hidden hidden))
    494495      (setf (getstring name *mode-names*) mode)))
    495496
  • trunk/ccl/hemlock/src/listener.lisp

    r595 r597  
    4242       (t
    4343        (message
    44          "Ignoring \"package\" file option -- cannot convert to a string."))))))
     44         "Ignoring \"package\" file option -- cannot convert to a string."))))
     45))
    4546
    4647
     
    8384(defmode "Listener" :major-p nil :setup-function #'setup-listener-mode)
    8485
     86(defparameter *listener-modeline-fields*
     87  (list (modeline-field :package)
     88        (modeline-field :modes)
     89        (modeline-field :process-info)))
     90 
    8591(defun listener-mode-lisp-mode-hook (buffer on)
    8692  "Turn on Lisp mode when we go into Listener Mode."
     
    141147  :mode "Listener")
    142148
     149(defun balanced-expressions-in-region (region)
     150  "Return true if there's at least one syntactically well-formed S-expression
     151between the region's start and end, and if there are no ill-formed expressions in that region."
     152  ;; It helps to know that END-MARK immediately follows a #\newline.
     153  (let* ((start-mark (region-start region))
     154         (end-mark (region-end region))
     155         (end-line (mark-line end-mark))
     156         (end-charpos (mark-charpos end-mark)))
     157    (with-mark ((m start-mark))
     158      (pre-command-parse-check m)
     159      (when (form-offset m 1)
     160        (let* ((skip-whitespace t))
     161          (loop
     162            (let* ((current-line (mark-line m))
     163                   (current-charpos (mark-charpos m)))
     164              (when (and (eq current-line end-line)
     165                         (eql current-charpos end-charpos))
     166                (return t))
     167              (if skip-whitespace
     168                (progn
     169                  (scan-char m :whitespace nil)
     170                  (setq skip-whitespace nil))
     171                (progn
     172                  (pre-command-parse-check m)
     173                  (unless (form-offset m 1)
     174                    (return nil))
     175                  (setq skip-whitespace t))))))))))
     176               
     177           
     178 
    143179(defcommand "Confirm Listener Input" (p)
    144180  "Evaluate Listener Mode input between point and last prompt."
     
    147183  (let ((input-region (get-interactive-input)))
    148184    (when input-region
    149       (let* ((output (value eval-output-stream))
    150              (*standard-output* output)
    151              (*error-output* output)
    152              (*trace-output* output))
    153         (fresh-line)
    154         (in-lisp
    155          ;; Copy the region to keep the output and input streams from interacting
    156          ;; since input-region is made of permanent marks into the buffer.
    157          (with-input-from-region (stream (copy-region input-region))
    158            (loop
    159              (let ((form (read stream nil lispbuf-eof)))
    160                (when (eq form lispbuf-eof)
    161                  ;; Move the buffer's input mark to the end of the buffer.
    162                  (move-mark (region-start input-region)
    163                             (region-end input-region))
    164                  (return))
    165                (setq +++ ++ ++ + + - - form)
    166                (let ((this-eval (multiple-value-list (eval form))))
    167                  (fresh-line)
    168                  (dolist (x this-eval) (prin1 x) (terpri))
    169                  (show-prompt)
    170                  (setq /// // // / / this-eval)
    171                  (setq *** ** ** * * (car this-eval)))))))))))
     185      (insert-character (current-point) #\NewLine)
     186      (when (balanced-expressions-in-region input-region)
     187        (let* ((string (region-to-string input-region)))
     188          (move-mark (value buffer-input-mark) (current-point))
     189          (listener-document-send-string (hi::buffer-document (current-buffer)) string))))))
     190
     191(defvar *control-d-string* (make-string 1 :initial-element (code-char (logand (char-code #\d) #x1f))))
     192
     193(defcommand "EOF or Delete Forward" (p)
     194  "Send an EOF if input-mark is at buffer's end, else delete forward character."
     195  "Send an EOF if input-mark is at buffer's end, else delete forward character."
     196  (let* ((input-mark (value buffer-input-mark))
     197         (point (current-point)))
     198    (if (and (null (next-character point))
     199             (null (next-character input-mark)))
     200      (listener-document-send-string (hi::buffer-document (current-buffer)) *control-d-string*)
     201      (delete-next-character-command p))))
     202
     203             
    172204
    173205(defcommand "Abort Listener Input" (p)
     
    363395;;; Other stuff.
    364396
    365 (defmode "Editor")
     397(defmode "Editor" :hidden t)
    366398
    367399(defcommand "Editor Mode" (p)
  • trunk/ccl/hemlock/src/modeline.lisp

    r593 r597  
    132132               "Returns buffer's modes followed by one space."
    133133               (declare (ignore window))
    134                (format nil "~A  " (buffer-modes buffer))))
     134               (let* ((m ()))
     135                 (dolist (mode (buffer-mode-objects buffer))
     136                   (unless (hi::mode-object-hidden mode)
     137                     (push (mode-object-name mode) m)))
     138               (format nil "~A  " (nreverse m)))))
    135139
    136140(make-modeline-field
     
    209213 :function 'buffer-pathname-ml-field-fun)
    210214
     215(make-modeline-field
     216 :name :process-info
     217 :function #'(lambda (buffer window)
     218               (declare (ignore window))
     219               (let* ((proc (buffer-process buffer)))
     220                 (when proc
     221                   (format nil "~a(~d) [~a]"
     222                           (ccl::process-name proc)
     223                           (ccl::process-serial-number proc)
     224                           (ccl::process-whostate proc))))))
    211225
    212226(defvar *default-modeline-fields*
     
    219233  "This is the default value for \"Default Modeline Fields\".")
    220234
    221 (defun %init-redisplay ()
     235(defun %init-mode-redisplay ()
    222236  (add-hook hemlock::buffer-major-mode-hook 'queue-buffer-change)
    223237  (add-hook hemlock::buffer-minor-mode-hook 'queue-buffer-change)
     
    225239  (add-hook hemlock::buffer-pathname-hook 'queue-buffer-change)
    226240  (add-hook hemlock::buffer-modified-hook 'queue-buffer-change)
     241  (add-hook hemlock::
    227242  (add-hook hemlock::window-buffer-hook 'queue-window-change))
    228243
  • trunk/ccl/hemlock/src/struct.lisp

    r587 r597  
    163163  variables              ; String-table of mode variables
    164164  var-values             ; Alist for saving mode variables
    165   documentation)         ; Introductory comments for mode describing commands.
     165  documentation          ; Introductory comments for mode describing commands.
     166  hidden                 ; Not listed in modeline fields
     167)
    166168
    167169(defun %print-hemlock-mode (object stream depth)
Note: See TracChangeset for help on using the changeset viewer.