Xref: utzoo comp.unix.wizards:5708 comp.emacs:2396 Path: utzoo!mnetor!uunet!mcvax!enea!ttds!draken!zap From: zap@draken.nada.kth.se (Svante Lindahl) Newsgroups: comp.unix.wizards,comp.emacs Subject: Re: Emacs csh alias Message-ID: <235@draken.nada.kth.se> Date: 6 Dec 87 07:00:31 GMT References: <10672@brl-adm.ARPA> Reply-To: zap@nada.kth.se (Svante Lindahl) Followup-To: comp.emacs Organization: The Royal Inst. of Techn., Stockholm Lines: 49 [Warning: Extensive inclusion, but I have included a new newsgroup in the newsgroups-line, and directed followups to it (comp.emacs)] In article <10672@brl-adm.ARPA> dsill@NSWC-OAS.arpa (Dave Sill) writes: >I've been trying to set up a C-Shell (4.2 BSD) alias for Emacs (GNU >17.64, not that it matters) which, when run the first time will >actually run Emacs, but after suspending Emacs with C-z, will bring >the background Emacs job to the foreground. The catch is that I'd >also like the alias to re-load emacs if I exit with C-x C-c. Simply >stated, I want an alias named "emacs" which will load Emacs if it >isn't already loaded, but will foreground a background Emacs if one >exists. > >I know I could do this with a script (if I assume the Emacs job is >always job %1), but I'd prefer an alias since they're faster. It >would be especially nice to determine which background job was the >Emacs job and foreground *it*, instead of just assuming job %1. > >Any ideas or alternate approaches? Should I just put up with the >occasional "fg: No such job." message? Here is something which should do part of what you want. It doesn't accomplish to start a new emacs process if you exited the last one with C-x C-c - unless the first one had never been suspended! Whenever you get "fg: No such job" just type ``i!!'', reinvoking the commandline prefixed with an "i", "iemacs" standing for "init emacs". alias emacs iemacs alias iemacs 'alias emacs remacs; "emacs" \!* ; alias emacs iemacs' alias remacs fg %emacs Here we use a special version of suspend-emacs, that will look for a file ".emacs_pause" in the user's home directory when emacs is resumed. In this file suspend-emacs expects to find the current working directory and an optional "command line" that is parsed like the initial command line. Very useful! This could be done using "suspend-resume-hook", but the hook wasn't available in 17.?? when this was first implemented here. These are the aliases I use together with the special version of suspend-emacs. alias emacs iemacs alias remacs 'echo `pwd` \!* >\! ~/.emacs_pause ; %emacs' alias iemacs 'alias emacs remacs; "emacs" \!* ; alias emacs iemacs' alias kemacs 'alias emacs iemacs; remacs -kill' Svante Lindahl zap@nada.kth.se uunet!nada.kth.se!zap