[net.emacs] Emacs in background and "Re: Executing a function on restarting"

israel@umcp-cs (08/11/84)

[ This line is a imagment of your figination]

	From: softech@othervax.UUCP
	
	We need to do things of miscellaneous
	nature just before pausing (or exiting) and also just upon
	starting (or restarting) Emacs.  The pausing part is easy:
	simply write the Mlisp code and bind it to the normal exiting
	or pausing keys.  The restarting is a bit more difficult:  when
	you restart a paused emacs, all it does is redraw the screen
	and put the cursor in the last used position.  We would like to
	be able to execute a function every time emacs is restarted.
	My feeling is that there should be a variable (say
	"restart-function") that you could set to a string value, and
	that every time Emacs is restarted, it would do an
	(execute-string restart-function).  This would allow more
	flexibility in doing things like re-configuring keyboards, etc.

You can do it the same way as the pause stuff!  There is nothing to
stop you from having stuff after a pause-emacs.  For example, the
following set of functions can be very useful:

(defun
    (my-pause-emacs
	( ... initialize programmable keys for C-shell commands ...)
	(pause-emacs)
	( ... initialize programmable keys for emacs functions ...)))

(defun
    (my-exit-emacs
	( ... initialize programmable keys for C-shell commands ...)
	(exit-emacs)))

(defun
    (my-write-file-exit
	(write-modified-files)
	(my-exit-emacs)))

(bind-to-key "my-pause-emacs" "\e\\")
(bind-to-key "my-exit-emacs" "\^C")
(bind-to-key "my-write-file-exit" "\^X\^F")

and also put a
	( ... initialize programmable keys for emacs functions ...)
in your .emacs_pro.

In fact, Since Unipress fixed emacs so that it didn't change the stty
modes on the terminal until it was ready to redraw the screen, you can
use the above method to run Emacs in background.  Below is a handy
function I wrote, called "bg", which runs mlisp code in background.
You can call it with either "^U ESC-x bg function-name" which will
run the named function in background without parameters, or if you
have more functions to do, or functions with parameters, then you
would do a "ESC-x bg" and type the statements to be done into the
buffer, and exit-emacs when done.  The function will pause out
of emacs automatically, but you have to type 'bg' to the shell after
you are out.  Your function(s) will run in emacs in background while
you go about your business.

(defun
    (bg stmts
	(if prefix-argument-provided
	    (setq stmts (concat "(" (get-tty-command ": bg ") ")"))
	    (> (nargs) 0) (setq stmts (arg 1))
	    (save-window-excursion
		(pop-to-buffer "Back Ground")
		(erase-buffer)
		(electric-mlisp-mode)
		(message "Enter statements to do in background.")
		(recursive-edit)
		(beginning-of-file)
		(set-mark)
		(end-of-file)
		(setq stmts (region-to-string))
		(delete-buffer "Back Ground")))
	(if (!= stmts "")
	    (progn
	       (save-excursion
		   (temp-use-buffer "copy-&")
		   (erase-buffer)
		   (insert-string stmts))
	       (execute-mlisp-line (concat "(progn (pause-emacs) "
					   stmts "(novalue))")))
	    (novalue))))

-- 

Bruce Israel

University of Maryland, Computer Science
{rlgvax,seismo}!umcp-cs!israel (Usenet)    israel@Maryland (Arpanet)