Changeset 14816


Ignore:
Timestamp:
Jun 7, 2011, 6:26:18 PM (8 years ago)
Author:
svspire
Message:

Ron Garret's patches.
Fix copy-region-to-input to work like FRED did --
"When you're typing at the Listener and you want to grab another sexpr
in the listener by putting the cursor on it and pressing RETURN, the
base Hemlock behavior is to replace what you're typing with the new
input. FRED (and this patch) appends the new input to what you've
already typed, and also leaves the cursor in the same relative
position as where you placed it."

Fix "Editor Execute Expression" and "Editor Execute Defun" to make the
result visible in listener. New variable *echo-expression-to-listener*
if true will also echo evaluated expression itself to listener,
otherwise only its evaluated result is echoed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/hemlock/src/listener.lisp

    r14721 r14816  
    267267          (insert-character (current-point-for-insertion) #\NewLine))))))
    268268
     269(defun mark-in-region-p (mark region)
     270 (and (mark<= (region-start region) mark) (mark<= mark (region-end region))))
     271
     272(defun input-offset ()
     273 (if (hi::region-active-p)
     274   0
     275   (let* ((mark (current-point))
     276          (history (value input-regions))
     277          (region (find mark history :key 'car :test 'mark-in-region-p)))
     278     (and region (count-characters (region mark (region-end (car region))))))))
     279
    269280(defun copy-region-to-input (region)
    270   (let* ((region-string (when region (region-to-string region)))
    271          (input-mark (value buffer-input-mark))
    272          (end-mark (region-end (buffer-region (current-buffer))))
    273          (input-region (region input-mark end-mark)))
    274     (with-mark ((input-mark (value buffer-input-mark)))
    275       (move-mark (current-point) input-mark)
    276       (delete-region input-region)
    277       (insert-string (current-point) region-string)
    278       (buffer-end (current-point)))))
     281 (when region
     282   (let* ((region-string (region-to-string region))
     283          (end-mark (region-end (buffer-region (current-buffer))))
     284          (offset (or (input-offset) 0)))
     285     (move-mark (current-point) end-mark)
     286     (insert-string (current-point) region-string)
     287     (buffer-end (current-point))
     288     (character-offset (current-point) (- offset)))))
    279289
    280290(defun find-backward-form (mark)
     
    588598                                       (mark-absolute-position (region-start region)))))
    589599
     600(defvar *echo-expression-to-listener* nil "True if you want evaluated forms in an editor window to echo in listener, in addition to their evaluated result.")
    590601
    591602(defcommand "Editor Execute Defun" (p)
    592   "Executes the current or next top-level form in the editor Lisp."
    593   (declare (ignore p))
    594   (if (region-active-p)
    595     (eval-region (current-region))
    596     (eval-region (defun-region (current-point)))))
     603  "Executes the current or next top-level form in the editor Lisp. Ensures the result is visible."
     604  (declare (ignore p))
     605  (let* ((region (copy-region
     606                  (if (region-active-p)
     607                    (current-region)
     608                    (defun-region (current-point)))))
     609         (form (when *echo-expression-to-listener* (region-to-string region)))
     610         (buf (gui::hemlock-buffer (#/topListener gui::hemlock-listener-document))))
     611    (when buf
     612      (let ((HI::*CURRENT-BUFFER* buf))
     613        (move-mark (current-point) (region-end (buffer-region buf)))))
     614    (when form (format (HEMLOCK-EXT:TOP-LISTENER-OUTPUT-STREAM) "~A~&" form))
     615    (eval-region region)))
    597616
    598617(defcommand "Editor Execute Expression" (p)
    599   "Executes the current region in the editor Lisp."
    600   (declare (ignore p))
    601   (eval-region (current-form-region)))
     618  "Executes the current region in the editor Lisp. Ensures the result is visible."
     619  (declare (ignore p))
     620  (let* ((region (copy-region (current-form-region)))
     621         (form (when *echo-expression-to-listener* (region-to-string region)))
     622         (buf (gui::hemlock-buffer (#/topListener gui::hemlock-listener-document))))
     623    (when buf
     624      (let ((HI::*CURRENT-BUFFER* buf))
     625        (move-mark (current-point) (region-end (buffer-region buf)))))
     626    (when form (format (HEMLOCK-EXT:TOP-LISTENER-OUTPUT-STREAM) "~A~&" form))
     627    (eval-region region)))
    602628
    603629(defcommand "Editor Re-evaluate Defvar" (p)
Note: See TracChangeset for help on using the changeset viewer.