home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mutt
/
builtin
/
alamode.mut
next >
Wrap
Lisp/Scheme
|
1995-01-14
|
4KB
|
147 lines
;; alamode.mut - set buffer modes.
;; This stuff is called when a buffer is created or file read in.
;; C Durland Public Domain
;; Routines:
;; (default-major-mode mode-name)
;; Default is none. Call change to whatever you like.
;; (none-mode)
;; A do nothing mode
;; (auto-mode-list (bool append)(string mode-re mode-name ...)
;; Append or Prepend to the list of modes.
(include me.mh)
(defun MAIN
{
(register-hook IBUFFER-CREATED-HOOK "set-buffer-mode")
(register-hook IREAD-FILE-HOOK "context-mode")
(default-major-mode "none")
(auto-mode-list TRUE
'.*\.c$' "c"
'.*\.h$' "c"
'.*\.mut$' "mutt"
'.*\.mh$' "mutt"
'.*\.doc$' "text"
'.*\.txt$' "text"
)
})
;; Set a mode for a buffer based on the buffer name.
;; Notes:
;; Call this from interactive-buffer-created-hook. That way
;; switch-to-buffer can have modes.
;; I use buffer name because the file name doesn't exist when the
;; buffer is created.
;; It might be a better idea to just wait til a file is read, look
;; for a context mode and if none, use the file name to set a mode.
;; Remember to remove "<n>" from the end of the buffer name.
(defun set-buffer-mode
{
(set-mode
(if (re-string '\(.+\)<[0-9]+>$' (buffer-name -1))
(get-matched '\1')
(buffer-name -1)))
})
;; Set the buffer mode.
;; If the environment variable "MEMODE" is set (eg to "mail"), append
;; "-mode" to it and set that mode. This is very handy where I want
;; be in mail mode when ME runs (eg when answering my mail).
;; Otherwise, look at the name and try to figure out a mode from that.
(defun set-mode (string filename) HIDDEN
{
(if (!= "" (getenv "MEMODE"))
{
(run-mode (getenv "MEMODE"))
(done)
})
(look-up-mode-in-list filename)
})
;; look for string that sets mode. May override (set-mode)
;; "-*-text-*-" => (text-mode)
;; Notes:
;; Look at GNU Emacs Manual pg 108 for more to do.
;; A problem with this is when you edit a X11 resource database
;; (xrdb) file. If the first line is something like
;; *Font: -*-prestige-medium-r-normal-*-120-*
;; this will try to run prestige-medium-r-normal-mode. Not likely.
;; GnuEmacs also has this problem. run-mode has a check for this
;; case.
(defun context-mode
{
(if (looking-at '.*-\*-\(.+\)-\*-')
(run-mode (get-matched '\1')))
})
(list mode-list) ;; (mode-RE mode-name) pairs
(string the-default-major-mode)
(defun
none-mode { (clear-modes) } ;; a do-nothing mode
default-major-mode (string mode-name)
{ (the-default-major-mode mode-name) }
auto-mode-list (bool append) ;; (string mode-re mode-name ...)
{
(int n z)
(z (if append 10000 -1))
(n 1)
(while (< n (nargs))
{
(insert-object mode-list z (arg n))
(insert-object mode-list (+ 1 z) (arg (+ 1 n)))
(+= n 2)
})
}
)
(defun
run-mode (string mode) HIDDEN
{
(if (pgm-exists (concat mode "-mode"))
(floc (concat mode "-mode")())
(msg "Unknown mode: " mode))
}
look-up-mode-in-list (string name) HIDDEN
{
(int len n)
(len (length-of mode-list))
(n 0)
(while (< n len)
{
(if (re-string (extract-element mode-list n) name)
{
(run-mode (extract-element mode-list (+ 1 n)))
(done)
})
(+= n 2)
})
(run-mode the-default-major-mode)
}
)
;(defun
; dump-list
; {
; (int n z)
;
; (n (length-of mode-list))
; (z 0)
; (while (< z n)
; {
; (msg (extract-element mode-list z) " "
; (extract-element mode-list (+ 1 z)))
; (get-key)
; (+= z 2)
; })
; (msg "done " n)
; })