home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mutt
/
builtin
/
window.mut
< prev
next >
Wrap
Text File
|
1995-01-14
|
6KB
|
242 lines
;; window.mut : The window routines for ME.
;; This file is part of ME.
;; C Durland Public Domain
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Windows ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun
next-window
{
(current-window (+ (arg-prefix) (current-window)))
(arg-flag FALSE 1) ;; reset arg count
}
previous-window { (arg-prefix (- 0 (arg-prefix))) (next-window) }
)
(defun
grow-window { (window-height -1 (+ (window-height -1) (arg-prefix))) }
shrink-window { (window-height -1 (- (window-height -1) (arg-prefix))) }
shrink-window-to-dot { (window-height -1 (window-row -1)) }
)
(defun
delete-current-window
{ (if (not (free-window -1)) (msg "Could not delete window.")) }
delete-other-windows
{
(int n)
(n 0)
(while (!= 1 (windows))
{
(if (== n (current-window))
(n 1)
(free-window n))
})
}
)
(defun
scroll-up
{
(scroll-window -1 (arg-prefix))
(arg-flag FALSE 1) ;; reset arg count
TRUE
}
scroll-down
{
(scroll-window -1 (- 0 (arg-prefix)))
(arg-flag FALSE 1) ;; reset arg count
TRUE
}
scroll-other-window
{
(bool f)
(if (== 1 (windows)) (done))
; (n (arg-prefix))
(f (arg-flag))
(arg-prefix 1)(next-window)
(page-window FALSE 0 (not f))
(arg-prefix 1)(previous-window)
; (scroll-window (+ 1 (current-window)) (- 0 (arg-prefix)))
(arg-flag FALSE 1) ;; reset arg count
TRUE
}
)
;; Scroll the current window forward (or backwards if n is negative) by n
;; lines, or by a full page if no argument. The dot is left at the top
;; of the window (if n is positive) or at the end if negative - if the
;; top line of the window ends up at the last line of the buffer, the dot
;; is centered.
;; Notes:
;; If n == 1, this acts just like scroll-up (except at the end of the
;; buffer).
;; NEXT-SCREEN-CONTEXT-LINES in the arithmetic on the window size
;; is the overlap; 2 is the default overlap value in ITS and
;; GNU Emacs.
(const NEXT-SCREEN-CONTEXT-LINES 2)
(defun
page-window (bool f)(int n)(bool forward) HIDDEN
{
(int z)
(if (not f) ;; Default scroll
{
(z (- (window-length) NEXT-SCREEN-CONTEXT-LINES))
(if (<= z 0) (z 1)) ;; Forget overlap if tiny window
}
(z n))
(if forward (z (- 0 z)))
(scroll-window -1 z)
(if (EoB) (scroll-window -1 0 0)) ;; Center dot
(arg-flag FALSE 1) ;; reset arg count
TRUE
}
next-page { (page-window (arg-flag)(arg-prefix) TRUE) }
previous-page { (page-window (arg-flag)(arg-prefix) FALSE) }
)
;; Horzontal window scrolling
;; Manually scroll the current window horizontally.
;; Trys to keep the cursor on screen to prevent the update routines
;; from undoing the scroll.
(defun
center-screen-around-cursor-horizontally
{ (window-ledge -1 (- (current-column) (/ (screen-width) 2))) }
scroll-current-window-horizontally (int n)
{
(int left-edge right-edge)
;;!!!??? what does GNU do?
(if (== 0 n) { (center-screen-around-cursor-horizontally) (done) })
(right-edge
(+ (screen-width)
(left-edge (window-ledge -1 (+ (window-ledge -1) n)))))
(if (< right-edge (current-column))
(current-column right-edge)
(if (and (<= (current-column) left-edge)
(<= (current-column (+ left-edge 1)) left-edge))
(window-ledge -1 (- (current-column) 1))))
}
scroll-right ;; move text in window right
{
(scroll-current-window-horizontally
(- 0 (if (arg-flag) (arg-prefix) (- (screen-width) 3))))
(arg-flag FALSE 1) ;; reset arg count
}
scroll-left ;; move text in window left
{
(scroll-current-window-horizontally
(if (arg-flag) (arg-prefix) (- (screen-width) 3)))
(arg-flag FALSE 1) ;; reset arg count
}
)
;; Reposition window dot to the nth line from the top (or bottom if n is
;; negative) of the current window. If n is 0 the window is centered
;; (this is what the standard redisplay code does). With no argument it
;; defaults to 1. Because of the default, it works like Gosling Emacs.
;; Bound to "M-!"
(defun
reposition-window
{
(scroll-window -1 0 (arg-prefix))
(arg-flag FALSE 1) ;; reset arg count
TRUE
}
)
;; Refresh the screen. With no argument, it just does the refresh. With an
;; argument it [re]centers dot in the current window.
;; Notes:
;; The screen is NOT changed in this call - it will be when (update) is
;; called in the main loop.
;; Bound to "C-l"
(defun
refresh-screen
{
(if (arg-flag)
(scroll-window -1 0 0) ;; Center dot
(update FALSE TRUE))
(arg-flag FALSE 1) ;; reset arg count
TRUE
}
)
;; Split the current window. A window smaller than 3 lines cannot be split.
;; The only other error possible is a malloc() failure allocating the
;; structure for the new window.
;; Bound to "C-x 2"
(defun
split-window-vertically
{
(bool resize-window)
(int rows)
(resize-window (arg-flag))
(rows (arg-prefix))
(arg-flag FALSE 1) ;; reset arg count
(if (not (split-window))
{
(msg "Cannot split a " (window-length) " line window.")
FALSE
(done)
})
(if resize-window
(window-length -1 rows)
TRUE)
}
)
(defun MAIN
{
(bind-key GLOBAL-KEYMAP
"next-window" "C-xo"
"previous-window" "C-xp" ;; !!!Not GNU
"delete-current-window" "C-x0"
"delete-other-windows" "C-x1"
"grow-window" 'C-x^'
"shrink-window" "C-xC-z" ;; !!!GNU doesn't bind
"scroll-up" "C-xC-p" ;; !!!Not GNU
"scroll-down" "C-xC-n" ;; !!!GNU doesn't bind
"scroll-other-window" "M-C-v"
"scroll-right" "C-x>"
"scroll-left" "C-x<"
"next-page" "C-v"
"previous-page" "M-v"
"reposition-window" "M-!"
"refresh-screen" "C-l"
"split-window-vertically" "C-x2")
})