home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mutt
/
builtin
/
register.mut
< prev
next >
Wrap
Lisp/Scheme
|
1995-01-14
|
5KB
|
175 lines
;; register.mut
;; Implements [possibly a subset of] GNU Emacs's register commands.
;; Diffs:
;; In insert register, I use the opposite behavior for dot and mark (of
;; GNU) to be consistant with yank. See comments in insert-register if
;; you want to change it back.
;; C Durland 8/92 4/93 Public Domain
(include me.mh)
(const ;; register types
REGISTER-UNUSED 0 ;; What global arrays are initialized to
REGISTER-TEXT 1 ;; Region or rectangle, register is a bag
REGISTER-POSITION 2 ;; Register is a buffer and mark
)
(array byte register-type 36)
(array small-int registers 36 register-postion-marks 36)
(defun
get-register-num (string prompt) HIDDEN
{
(int n)
; (n { (msg prompt " (0-9, a-z): ")(get-key) })
(if (not (key-waiting 1)) (msg prompt " (0-9, a-z): "))
(n (get-key))
(if (== n 0x147) (abort)) ;; ^G
(if (not (or ;; !((0 <= x <= 9) || (a <= x <= z))
(and (<= 0x30 n) (<= n 0x39)) ;; 0-9
(and (<= 0x61 n) (<= n 0x7A)))) ;; a-z
{ (msg "Out of bounds (0-9, a-z)!")(halt) })
;; convert key to 0 - 35
;; '0' - '9' => 0-9, 'a'-'z' => 10-35
(if (<= n 0x39) (- n 0x30) (- n 0x57))
}
;; Insert the contents of a register at the dot.
;; Normally, the dot is left before the register text, the mark after
;; (oppsite of yank). With arg, behaves like yank.
;; Uggg. I can't stand it - for consistancy, I going with the way
;; yank works. You can change it back by easily (uncomment some
;; lines and comment one).
insert-register
{
; (byte type)(small-int width height)(int size) ;; struct BagInfo
(int n)
(n (get-register-num "Insert register"))
(if (!= REGISTER-TEXT (register-type n))
{
(msg "Register doesn't contain a region or rectangle.")
(done)
})
(set-mark THE-MARK)
(n (registers n))
(insert-bag n)
;; GNU Emacs like behaivor:
;; if rectangle: need-to-swap-marks == arg-flag
;; if !rectangle: need-to-swap-marks == !arg-flag
; (bag-stats n (loc type))
; (if (if (== type BAG-IS-RECTANGLE) (arg-flag) (not (arg-flag)))
; (swap-marks THE-DOT THE-MARK))
;; yank like:
(if (arg-flag) (swap-marks THE-DOT THE-MARK))
(arg-flag FALSE 1) ;; reset arg count
}
copy-to-register
{
(int n bag)
(n (get-register-num "Copy to register"))
(if (== 0 (bag (clear-register n REGISTER-TEXT))) (bag (create-bag TRUE)))
(clear-bag bag)(append-to-bag bag APPEND-REGION)
(if (arg-flag) (delete-region))
(set-register n REGISTER-TEXT bag 0)
(arg-flag FALSE 1) ;; reset arg count
}
copy-region-to-rectangle
{
(int n bag)
(n (get-register-num "Copy rectangle to register"))
(if (== 0 (bag (clear-register n REGISTER-TEXT))) (bag (create-bag TRUE)))
(clear-bag bag)(append-to-bag bag APPEND-RECTANGLE)
(if (arg-flag) (erase-rectangle TRUE))
(set-register n REGISTER-TEXT bag 0)
(arg-flag FALSE 1) ;; reset arg count
}
point-to-register
{
(int n mark)
(n (get-register-num "Point to register"))
(clear-register n REGISTER-POSITION)
(set-mark (mark (create-mark TRUE)))
(set-register n REGISTER-POSITION (current-buffer) mark)
}
register-to-point
{
(int n mark cb the-buffer the-mark)
(n (get-register-num "Register to point"))
(if (!= REGISTER-POSITION (register-type n))
{
(msg "Register doesn't contain a buffer position.")
(done)
})
(cb (current-buffer))
(the-buffer (registers n))(the-mark (register-postion-marks n))
(if (buffer-exists the-buffer)
{
(current-buffer the-buffer)
(if (mark-valid the-mark)
{
(if (and
(!= cb the-buffer)
(!= -2 (n (buffer-displayed the-buffer))))
(current-window n)
(current-buffer the-buffer TRUE))
(goto-mark the-mark)
}
{ ;; else the mark is invalid, position is also
(current-buffer cb)
(msg "Register contains an invalid position (point).")
})
}
(msg "Register contains an invalid position (buffer)."))
}
set-register (int n type x y) HIDDEN
{
(register-type n type)
(registers n x)
(register-postion-marks n y)
}
clear-register (int n type-to-be) HIDDEN
{
(int bid cb)
(if (== REGISTER-TEXT type-to-be (register-type n))
{
(registers n)
(done)
})
(switch (register-type n)
REGISTER-TEXT (free-bag (registers n))
REGISTER-POSITION
{
(bid (registers n))
(if (buffer-exists bid)
{
(cb (current-buffer))
(current-buffer bid)
(free-mark (register-postion-marks n))
(current-buffer cb)
})
})
(register-type n REGISTER-UNUSED)
0 ;; no bag that can be reused
}
)