home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mutt
/
builtin
/
modeline.mut
< prev
next >
Wrap
Text File
|
1995-01-14
|
7KB
|
255 lines
;; modeline.mut : Modeline central. Control what the mode line looks
;; like and other mode related stuff.
;; Modeline format:
;; Change_flag Buffer-name (major-mode : minor-mode) File: File-name
;; Change_flag : -- or **
;; major_mode : "", C, Mutt, Picture, etc
;; minor_mode : comment, etc
;; Routines:
;; (local-modeline-hook
;; name-of-the-routine-to-call-instead-of-modeline-hook)
;; If the buffer has a local modeline-hook, it is called instead of the
;; global (modeline-hook).
;; (major-mode name-of-major-mode) : (major-mode "foo") sets the major
;; mode name to foo (displayed on the modeline) and (major-mode)
;; returns the current major mode name.
;; (minor-mode name-of-minor-mode)
;; (clear-modes) : Remove all the local key bindings, mode names and
;; reset the buffer local sysvars.
;; Uses:
;; Buffer variables:
;; major-mode
;; minor-mode
;; local-modeline-hook
;; C Durland 10/89 Public Domain
(include me.mh)
(defun
local-modeline-hook (string hook-name)
{ (buffer-var "local-modeline-hook" hook-name) }
major-mode (string name) { (mode-name "major-mode" (push-args 0)) }
minor-mode (string name) { (mode-name "minor-mode" (push-args 0)) }
clear-modes
{
; (install-keymap NULL-KEYMAP LOCAL-KEYMAP)
(major-mode "")(minor-mode "")
(tab-stops 0)(word-wrap 0)
}
biff-all-modelines
{
(int j)
(for (j 0) (< j (windows)) (+= j 1)
(buffer-flags (attached-buffer j) BFMode)) ;; force update of modeline
}
)
(string ml-message ml-time)
(defun
modeline-time (string time)
{
(if (== (nargs) 1) ;; got time
(if (== "" time)
(modeline-show-time "")
(if (!= ml-time (concat time " "))
(modeline-show-time (concat time " ")))))
ml-time ;; return the current time
}
modeline-show-time (time) HIDDEN
{
(ml-time time) (biff-all-modelines) (update)
}
modeline-message (string text)
{
(if (== (nargs) 1) ;; got text
{
(ml-message text)
(biff-all-modelines)
})
ml-message ;; return the message
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;; System Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Since these are global (and apply to all buffers), only have to do
;; anything when they change state - otherwise the message is the same
;; for all buffers.
(string SV-message)
(bool McState)
(defun
McModeline (bool on) ;; Called when keyboard macro changes state
{ (McState on)(make-SV-message) }
overstrike-toggle-hook { (make-SV-message) }
make-SV-message HIDDEN
{
(SV-message "")
(sv-pack (!= 0 (overstrike)) "Ovwrt") ;; over strike
(sv-pack McState "McDef") ;; keyboard macro
(if (!= "" SV-message) (SV-message (concat " [" SV-message "]")))
(biff-all-modelines)
}
sv-pack (bool yes)(string text) HIDDEN
{
(if yes
(SV-message (concat SV-message (if (== "" SV-message) "" " ") text)))
}
)
(string modeline-who-am-i modeline-name)
(defun
modeline-title (string name)
{
(if (== 1 (nargs)) ;; got name
{
(modeline-who-am-i name)
(modeline-name
(if (!= "" name)
(concat " " name " -- ")
" "))
(biff-all-modelines)
})
(modeline-who-am-i)
})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;; Modeline Hook ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Global routine to format a modeline for the current buffer.
;; If the buffer has its own modeline hook, that is called instead.
;; Returns: A string to be used as the modeline.
(defun
modeline-hook
{
(if (!= "" (buffer-var "local-modeline-hook"))
{
(floc (buffer-var "local-modeline-hook")())
(done)
})
(concat
ml-message
(cond
(!= 0 (bit-and BFNoCare (buffer-flags -1))) " "
(buffer-modified -1) "**"
(!= 0 (bit-and BFRead_only (buffer-flags -1))) "%%"
TRUE "--")
modeline-name ;; Something like " ME -- "
(buffer-name -1) " "
ml-time ;; "" or "12:34 "
(modes) ;; "(modes)" or "--"
SV-message ;; "" or " [text]"
(if (!= "" (file-name -1))
(concat " File:" (sub~ (file-name -1)) " ")
"")
"-") ;; repeat this to the end of the modeline
}
modes HIDDEN ;; spit out the major and minor mode names
{
(concat
(if (!= "" (buffer-var "major-mode"))
{
(concat
"("
(buffer-var "major-mode")
(if (!= "" (buffer-var "minor-mode"))
(concat " : " (buffer-var "minor-mode"))
"")
")" )
}
"--"))
}
toads HIDDEN ;; spit out the sys var states
{
;;!!! this should be done ONLY when one of these changes!
(string text)
(text
(concat
(if (!= 0 (overstrike)) "Ovwrt" "") ;; over strike
(kbd-macro-msg))) ;; keyboard macro
(if (!= "" text)
(concat " [" text "]")
"")
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; Gory details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun
init-mline-bvars
{
(create-buffer-var STRING "local-modeline-hook" "major-mode" "minor-mode")
}
!1 MAIN HIDDEN ;; do this WAY early, before mode-line-hook is called
{
(init-mline-bvars) ;; make sure *scratch* is updated
(register-hook BUFFER-CREATED-HOOK "init-mline-bvars")
}
mode-name (string mode-var mode-name) HIDDEN
{
(if (== (nargs) 2) ;; got mode-name
{
(buffer-var mode-var mode-name)
(buffer-flags -1 BFMode) ;; force update of modeline
})
(buffer-var mode-var) ;; return the mode name
}
)
;; Convert a file name to ~ format. For example, "/users/craig/..."
;; is converted to "~/..." if $HOME is "/users/craig".
;; Notes:
;; OS dependent.
;; If $HOME ends with a "/" (eg root on Unix or "C:/" on MS-DOS),
;; don't convert "/etc/passwd" to "~etc/passwd". Should it be
;; "/etc/passwd" or "~/etc/passwd"? The latter would be nice if
;; $HOME is "C:/foo/bar/". (cannonize-file-name) strips off the
;; trailing "/".
;; $HOME can't change while ME is running (even on MS-DOS) - unless
;; ME does an putenv() (which it doesn't).
;; On MS-DOS, $HOME may contain "\"s but none of the ME generated
;; filenames will. (cannonize-file-name) converts the "\"s to "/"s.
(bool sub~-able)
(int length-of-$HOME)
(string sub~:$HOME)
(defun
MAIN
{
(sub~:$HOME (getenv "HOME"))
(sub~-able
(and
(cannonize-file-name sub~:$HOME)
(!= "/" (extract-elements sub~:$HOME -1 1))))
(length-of-$HOME (length-of sub~:$HOME))
}
sub~ (string dir-name)
{
(if (and
sub~-able
(== sub~:$HOME (extract-elements dir-name 0 length-of-$HOME)))
(concat "~" (extract-elements dir-name length-of-$HOME 1000))
dir-name
)
}
)