[Openmcl-devel] Contrib: restore some old fred behavior
Ron Garret
ron at flownet.com
Sun Feb 7 18:00:11 PST 2010
The following code changes the way Hemlock listeners handle copying prior input so that it works more like FRED used to. By default, when you select some prior input in a Hemlock listener and press return, the new input replaces whatever you may have been typing, so whatever you had been typing is now lost. Hemlock also doesn't preserve the point position relative to the form that you are selecting. FRED would append the prior input to whatever you had already typed and would also maintain the point position relative to the copied input, that is, if your cursor was in the middle of the form before the copy, it would still be in the middle of the form after the copy. These changes make it a lot easier to assemble a new input from prior inputs as components. I would normally put this in a file somewhere, but it's so short I decided to just cut-n-paste.
Enjoy!
rg
---
(in-package :hemlock)
(defun mark-in-region-p (mark region)
(and (mark<= (region-start region) mark) (mark<= mark (region-end region))))
(defun input-offset ()
(let* ((mark (current-point))
(history (value input-regions))
(region (find mark history :key 'car :test 'mark-in-region-p)))
(and region (count-characters (region mark (region-end (car region)))))))
(defun copy-region-to-input (region)
(let* ((region-string (when region (region-to-string region)))
(end-mark (region-end (buffer-region (current-buffer))))
(offset (or (input-offset) 0)))
(move-mark (current-point) end-mark)
(insert-string (current-point) region-string)
(buffer-end (current-point))
(character-offset (current-point) (- offset))))
More information about the Openmcl-devel
mailing list