; ; GNU EMACS Functions for talking to MM-32. ; ; BDF - Cloned from David's mm.ml file for Gosling's Emacs. ; ; ; Assume we have "mlsupport" loaded ; (require 'mlsupport) ; ; Declare global variables ; (defvar mm-edit-buffer-name "MM Send Edit" "Name of buffer editing messge") (defvar MM-Read-Only nil "True if a read only buffer") (defvar global-mode-string "Edit" "Mode string used to describe mm service") ;;;(load "emacs-extras" t t) ; ; Argv-last is like argv, but takes no argument. ; (defun argv-last () "Gets the last element from the argument list passed to emacs." (setq inhibit-command-line t) (nth (1- (length command-line-args)) command-line-args)) ; ; The main "mm" function ; (defun mm (&optional state) "The main entry function to the mm edit interface. Optional argument STATE is a symbol describing the current state." (define-key global-map "\^c" 'mm-suspend-emacs) (define-key ctl-x-map "\^c" 'mm-kill-emacs) (define-key ctl-x-map "\^z" 'mm-suspend-emacs) (define-key ctl-z-map "\^z" 'mm-suspend-emacs) (aset esc-map 26 'mm-suspend-emacs) (let (command) (message "") (setq MM-Read-Only nil) (delete-other-windows) ; Arg list cold be either: ; emacs -f mm ! More probable. ; emacs -l mm -f mm ! Not likely. (find-file (argv-last)) (setq mm-edit-buffer-name (buffer-name)) (goto-char (dot-min)) (push-mark (point) t) ; Changed from: (push-mark-quietly) (end-of-line) (setq command (intern (region-to-string))) (forward-char 1) (if (not (and (symbolp command) (fboundp command))) ; If not an MM funtion, do nothing but report it. (error (concat "Undefined MM command: " command)) ; Otherwise, legal command, so we can delete this text. (delete-region (dot-min) (dot)) (goto-char (dot-max)) ; And call the MM command. (funcall command)) )) ; ; Start up a "send" edit session ; (defun mm-send-edit() "Starts a send edit session for mm" (setq global-mode-string "MM Send Edit") (setq mode-line-format "%M %[(%m)%] --%p-- %*") (goto-char (dot-max))) ; ; Start up a "reply" edit session ; (defun mm-reply-edit() "Starts a reply edit session for mm" (let ((start (dot-min)) (finish)) (setq global-mode-string "MM Reply Edit") (setq mode-line-format "%M %[(%m)%] --%p-- %*") (goto-char (dot-min)) (search-forward (concat (char-to-string 3) "***END-OF-MESSAGE***" (char-to-string 3))) (beginning-of-line) (setq finish (dot)) (kill-line) (delete-char 1) (kill-region start finish) (split-window-vertically nil) (switch-to-buffer "MM Reply Message") (erase-buffer) (setq mode-line-format "MM Message You Are Replying To %[(%m)%] --%p-- %*") (yank) ; Get rid of message id lines. (goto-char (dot-min)) (kill-line) (kill-line) (goto-char (dot-min)) (setq finish (search-forward "Message-ID:" (dot-max) t)) (if finish (progn (beginning-of-line) (kill-line) (delete-char 1) (goto-char (dot-min)))) ; Now position the reply message so one can read it. (mm-position-reply) (other-window 1) (mm-send-edit) )) (defun mm-position-reply () (let ((finish (progn (goto-char (dot-min)) (end-of-line) (dot)))) (goto-char (dot-min)) (while (search-forward ":" finish t) (next-line 1) (end-of-line) (setq finish (dot)) (beginning-of-line) )) (recenter 0)) ; ; Start a forward message section. Forward message should look ; much like reply, but MM only gives us the send portion of text. ; (defun mm-forward-edit () "Starts a forward message edit session." (setq global-mode-string "MM Forward Edit") (setq mode-line-format "%M %[(%m)%] --%p-- %*") (goto-char (dot-max))) ; ; Start up a "read" only edit session ; (defun mm-read-message() "Starts a read only edit session for mm" (setq MM-Read-Only t) (setq buffer-read-only t) (set-buffer-modified-p nil) (setq global-mode-string "MM Read Message") (setq mode-line-format "%M %[(%m)%] --%p-- %*") (goto-char (dot-min))) ; ; Rebind the pause-emacs and exit-emacs function keys. ; ;;; (copyd "%pause-emacs" "suspend-emacs") ;;; (copyd "%exit-emacs" "kill-emacs") ; ; Define an exit function for mm-edit. ; (defun mm-kill-emacs () "A function used to clean up before returning to mm." (interactive) (save-mm-buffer) (kill-emacs)) (defun mm-suspend-emacs () "A function used to clean up before returning to mm." (interactive) (save-mm-buffer) (message "") (if (fboundp 'resume-wrapped-suspend-emacs) (resume-wrapped-suspend-emacs) (suspend-emacs)) (kill-buffer mm-edit-buffer-name) (mm)) ; ; Save the MM buffer before exiting emacs. ; (defun save-mm-buffer () "Save the message buffer if needed before returning to mm." (switch-to-buffer mm-edit-buffer-name) (if MM-Read-Only (set-buffer-modified-p nil) (save-buffer)))