diff options
| author | Richard M. Stallman | 1990-08-25 20:34:32 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1990-08-25 20:34:32 +0000 |
| commit | d543cc8e4ad6be1a282ba0a8b0f1fdc9199df112 (patch) | |
| tree | 577fe0a5fd206756fb26ad053fca0567d38d7c3c | |
| parent | 5859cd333cac7d01b75304b6be8996e227088f47 (diff) | |
| download | emacs-d543cc8e4ad6be1a282ba0a8b0f1fdc9199df112.tar.gz emacs-d543cc8e4ad6be1a282ba0a8b0f1fdc9199df112.zip | |
*** empty log message ***
| -rw-r--r-- | lisp/resume.el | 179 |
1 files changed, 106 insertions, 73 deletions
diff --git a/lisp/resume.el b/lisp/resume.el index c116a840db5..86866c12763 100644 --- a/lisp/resume.el +++ b/lisp/resume.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;; process command line arguments from within a suspended emacs job | 1 | ;; Process command line arguments from within a suspended Emacs job |
| 2 | ;; Copyright (C) 1988 Free Software Foundation, Inc. | 2 | ;; Copyright (C) 1988 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | ;; This file is not yet part of GNU Emacs, but soon will be. | 4 | ;; This file is not yet part of GNU Emacs, but soon will be. |
| @@ -17,111 +17,144 @@ | |||
| 17 | ;; can know your rights and responsibilities. It should be in a | 17 | ;; can know your rights and responsibilities. It should be in a |
| 18 | ;; file named COPYING. Among other things, the copyright notice | 18 | ;; file named COPYING. Among other things, the copyright notice |
| 19 | ;; and this notice must be preserved on all copies. | 19 | ;; and this notice must be preserved on all copies. |
| 20 | ;; | ||
| 21 | ;; by Joe Wells | ||
| 22 | ;; jbw@bucsf.bu.edu | ||
| 23 | ;; joew@uswat.uswest.com (maybe, ... the mailer there sucks) | ||
| 24 | 20 | ||
| 25 | ;; Stephan Gildea suggested bug fix (gildea@bbn.com). | 21 | ;; Created by: Joe Wells, jbw@bucsf.bu.edu |
| 22 | ;; Created on: 1988? | ||
| 23 | ;; Last modified by: Joe Wells, jbw@dodge | ||
| 24 | ;; Last modified on: Thu Jun 14 15:20:41 1990 | ||
| 25 | ;; Filename: resume.el | ||
| 26 | ;; Purpose: handle command line arguments when resuming suspended job | ||
| 27 | |||
| 28 | ;; Stephen Gildea suggested bug fix (gildea@bbn.com). | ||
| 26 | ;; Ideas from Michael DeCorte and other people. | 29 | ;; Ideas from Michael DeCorte and other people. |
| 27 | 30 | ||
| 28 | ;; For csh users, insert the following alias in your .cshrc file | 31 | ;; For csh users, insert the following alias in your .cshrc file |
| 29 | ;; (after removing the leading double semicolons): | 32 | ;; (after removing the leading double semicolons, of course): |
| 30 | ;; | 33 | ;; |
| 31 | ;;# The following line could be just EMACS=emacs, but this depends on | 34 | ;;# The following line could be just EMACS_CMD=emacs, but this depends on |
| 32 | ;;# your site. | 35 | ;;# your site. |
| 33 | ;;set EMACS=emacs | 36 | ;;if (! $?EMACS_CMD) set EMACS_CMD=emacs |
| 34 | ;;set EMACS_PATTERN="^\[[0-9]\] . Stopped ............ $EMACS" | 37 | ;;set JOBS_FILE=/tmp/jobs.$USER.$$ |
| 38 | ;;set ARGS_FILE=~/.emacs_args | ||
| 39 | ;;set STOP_PATT='^\[[0-9]*\] *[ +-] Stopped ............ ' | ||
| 40 | ;;set SUNVIEW_CMD='emacstool -nw -f emacstool-init -f server-start' | ||
| 41 | ;;set X_CMD=\'\''$EMACS_CMD -i -f server-start' | ||
| 35 | ;;alias emacs \ | 42 | ;;alias emacs \ |
| 36 | ;;' \\ | 43 | ;;' \\ |
| 37 | ;; jobs >! /tmp/jobs$$ \\ | 44 | ;; jobs >! "$JOBS_FILE" \\ |
| 38 | ;; && grep "$EMACS_PATTERN" /tmp/jobs$$ >& /dev/null \\ | 45 | ;; && grep "$STOP_PATT$EMACS_CMD" "$JOBS_FILE" >& /dev/null \\ |
| 39 | ;; && echo `pwd` \!* >! ~/.emacs_args && eval "%$EMACS" \\ | 46 | ;; && echo `pwd` \!* >! "$ARGS_FILE" && ""fg %$EMACS_CMD \\ |
| 40 | ;;|| test -S ~/.emacs_server && emacsclient \!* \\ | 47 | ;;|| if (! -e ~/.emacs_server || -f ~/.emacs_server) set status=1 \\ |
| 41 | ;;|| test "$?DISPLAY" = 1 && eval "\$EMACS -i \!* &" \\ | 48 | ;; && emacsclient \!* \\ |
| 42 | ;;|| test "$?WINDOW_PARENT" = 1 && eval "emacstool -f emacstool-init \!* &" \\ | 49 | ;;|| @ status=1 - $?DISPLAY && eval "$X_CMD -i \!* &" \\ |
| 43 | ;;|| eval "\$EMACS -nw \!*"' | 50 | ;;|| @ status=1 - $?WINDOW_PARENT && eval "$SUNVIEW_CMD \!* &" \\ |
| 51 | ;;|| ""$EMACS_CMD -nw \!* \\ | ||
| 52 | ;;' | ||
| 44 | ;; | 53 | ;; |
| 45 | ;; The alias works as follows: | 54 | ;; The alias works as follows: |
| 46 | ;; 1. If there is a suspended emacs jobs that is a child of the | 55 | ;; 1. If there is a suspended Emacs job that is a child of the |
| 47 | ;; current shell, place its arguments in the ~/.emacs_args file and | 56 | ;; current shell, place its arguments in the ~/.emacs_args file and |
| 48 | ;; resume it. | 57 | ;; resume it. |
| 49 | ;; 2. Else if the ~/.emacs_server socket has been created, presume an | 58 | ;; 2. Else if the ~/.emacs_server socket has been created, presume an |
| 50 | ;; emacs server is running and attempt to connect to it. If no emacs | 59 | ;; Emacs server is running and attempt to connect to it. If no Emacs |
| 51 | ;; server is listening on the socket, this will fail. | 60 | ;; server is listening on the socket, this will fail. |
| 52 | ;; 3. Else if the DISPLAY environment variable is set, presume we are | 61 | ;; 3. Else if the DISPLAY environment variable is set, presume we are |
| 53 | ;; running under X Windows and start a new X Gnu Emacs process in the | 62 | ;; running under X Windows and start a new GNU Emacs process in the |
| 54 | ;; background. | 63 | ;; background as an X client. |
| 55 | ;; 4. Else if the WINDOW_PARENT environment variable is set, presume we | 64 | ;; 4. Else if the WINDOW_PARENT environment variable is set, presume we |
| 56 | ;; are running under Sunview and Suntools and start an emacstool | 65 | ;; are running under SunView and start an emacstool process in the |
| 57 | ;; process in the background. | 66 | ;; background. |
| 58 | ;; 5. Else start a regular emacs process. | 67 | ;; 5. Else start a regular Emacs process. |
| 59 | ;; | 68 | ;; |
| 60 | ;; Notes: | 69 | ;; Notes: |
| 61 | ;; "test -S" checks if a unix domain socket by that name exists. | ||
| 62 | ;; The output of the "jobs" command is not piped directly into "grep" | 70 | ;; The output of the "jobs" command is not piped directly into "grep" |
| 63 | ;; because that would run the "jobs" command in a subshell. | 71 | ;; because that would run the "jobs" command in a subshell. |
| 64 | ;; Before resuming a suspended emacs, the current directory and all | 72 | ;; Before resuming a suspended emacs, the current directory and all |
| 65 | ;; command line arguments are placed in a file. | 73 | ;; command line arguments are placed in a file name ~/.emacs_args. |
| 66 | ;; The command to run emacs is always preceded by a \ to prevent | 74 | ;; The "-nw" switch to Emacs means no windowing system. |
| 67 | ;; possible alias loops. | ||
| 68 | ;; The "-nw" switch in the last line is is undocumented, and it means | ||
| 69 | ;; no windowing system. | ||
| 70 | |||
| 71 | (setq suspend-resume-hook 'resume-process-args) | ||
| 72 | (setq suspend-hook 'resume-preparation) | ||
| 73 | 75 | ||
| 74 | (defvar emacs-args-file "~/.emacs_args" | 76 | ;; Insert this in your .emacs file: |
| 77 | ;;(setq suspend-resume-hook 'resume-process-args) | ||
| 78 | ;;(setq suspend-hook 'empty-args-file) | ||
| 79 | ;;(autoload 'empty-args-file "resume") | ||
| 80 | ;;(autoload 'resume-process-args "resume") | ||
| 81 | |||
| 82 | ;; Finally, put the rest in a file named "resume.el" in a lisp library | ||
| 83 | ;; directory. | ||
| 84 | |||
| 85 | (defvar emacs-args-file (expand-file-name "~/.emacs_args") | ||
| 75 | "*This file is where arguments are placed for a suspended emacs job.") | 86 | "*This file is where arguments are placed for a suspended emacs job.") |
| 76 | 87 | ||
| 77 | (defun resume-preparation () | 88 | (defvar emacs-args-buffer " *Command Line Args*" |
| 78 | (condition-case () | 89 | "Buffer that is used by resume-process-args.") |
| 79 | (delete-file emacs-args-file) | ||
| 80 | (error nil))) | ||
| 81 | 90 | ||
| 82 | (defun resume-process-args () | 91 | (defun resume-process-args () |
| 83 | "This should be called from inside of suspend-resume-hook. | 92 | "This should be called from inside of suspend-resume-hook. This |
| 84 | Grabs the contents of the file whose name is stored in | 93 | grabs the contents of the file whose name is stored in |
| 85 | emacs-args-file, and processes these arguments like command line options." | 94 | emacs-args-file, and processes these arguments like command line |
| 86 | (let ((resume-start-buffer (current-buffer)) | 95 | options." |
| 87 | (resume-args-buffer (get-buffer-create " *Command Line Args*")) | 96 | (let ((start-buffer (current-buffer)) |
| 88 | resume-args) | 97 | (args-buffer (get-buffer-create emacs-args-buffer)) |
| 98 | length args) | ||
| 89 | (unwind-protect | 99 | (unwind-protect |
| 90 | (progn | 100 | (progn |
| 91 | (set-buffer resume-args-buffer) | 101 | (set-buffer args-buffer) |
| 92 | (erase-buffer) | 102 | (erase-buffer) |
| 93 | ;; Get the contents of emacs-args-file, then delete the file. | 103 | ;; get the contents of emacs-args-file |
| 94 | (condition-case () | 104 | (condition-case () |
| 95 | (progn | 105 | (let ((result (insert-file-contents emacs-args-file))) |
| 96 | (insert-file-contents emacs-args-file) | 106 | (setq length (car (cdr result)))) |
| 97 | (delete-file emacs-args-file)) | 107 | ;; the file doesn't exist, ergo no arguments |
| 98 | ;; The file doesn't exist or we can't delete it, ergo no arguments. | 108 | (file-error |
| 99 | ;; (If we can't delete it now, we probably couldn't delete it | 109 | (erase-buffer) |
| 100 | ;; before suspending, and that implies it may be vestigial.) | 110 | (setq length 0))) |
| 101 | (file-error (erase-buffer))) | 111 | (if (<= length 0) |
| 102 | ;; Get the arguments from the buffer. | 112 | (setq args nil) |
| 103 | (goto-char (point-min)) | 113 | ;; get the arguments from the buffer |
| 104 | (while (progn (skip-chars-forward " \t\n") (not (eobp))) | 114 | (goto-char (point-min)) |
| 105 | (setq resume-args | 115 | (while (not (eobp)) |
| 106 | (cons (buffer-substring (point) | 116 | (skip-chars-forward " \t\n") |
| 107 | (progn | 117 | (let ((begin (point))) |
| 108 | (skip-chars-forward "^ \t\n") | 118 | (skip-chars-forward "^ \t\n") |
| 109 | (point))) | 119 | (setq args (cons (buffer-substring begin (point)) args))) |
| 110 | resume-args))) | 120 | (skip-chars-forward " \t\n")) |
| 111 | (cond (resume-args | 121 | ;; arguments are now in reverse order |
| 112 | ;; Arguments are now in reverse order. | 122 | (setq args (nreverse args)) |
| 113 | (setq resume-args (nreverse resume-args)) | 123 | ;; make sure they're not read again |
| 114 | ;; The "first argument" is really a default directory to use | 124 | (erase-buffer)) |
| 115 | ;; while processing the rest of the arguments. | 125 | (write-buffer-to-file (current-buffer) emacs-args-file) |
| 116 | (setq default-directory (concat (car resume-args) "/")) | 126 | ;; if nothing was in buffer, args will be null |
| 117 | ;; Actually process the arguments. | 127 | (or (null args) |
| 118 | (command-line-1 (cdr resume-args))))) | 128 | (setq default-directory (file-name-as-directory (car args)) |
| 129 | args (cdr args))) | ||
| 130 | ;; actually process the arguments | ||
| 131 | (command-line-1 args)) | ||
| 119 | ;; If the command line args don't result in a find-file, the | 132 | ;; If the command line args don't result in a find-file, the |
| 120 | ;; buffer will be left in resume-args-buffer. So we change back to the | 133 | ;; buffer will be left in args-buffer. So we change back to the |
| 121 | ;; original buffer. The reason I don't just use | 134 | ;; original buffer. The reason I don't just use |
| 122 | ;; (let ((default-directory foo)) | 135 | ;; (let ((default-directory foo)) |
| 123 | ;; (command-line-1 args)) | 136 | ;; (command-line-1 args)) |
| 124 | ;; in the context of the original buffer is because let does not | 137 | ;; in the context of the original buffer is because let does not |
| 125 | ;; work properly with buffer-local variables. | 138 | ;; work properly with buffer-local variables. |
| 126 | (if (eq (current-buffer) resume-args-buffer) | 139 | (if (eq (current-buffer) args-buffer) |
| 127 | (set-buffer resume-start-buffer))))) | 140 | (set-buffer start-buffer))))) |
| 141 | |||
| 142 | (defun empty-args-file () | ||
| 143 | "This empties the contents of the file whose name is specified by | ||
| 144 | emacs-args-file." | ||
| 145 | (save-excursion | ||
| 146 | (set-buffer (get-buffer-create emacs-args-buffer)) | ||
| 147 | (erase-buffer) | ||
| 148 | (write-buffer-to-file (current-buffer) emacs-args-file))) | ||
| 149 | |||
| 150 | (defun write-buffer-to-file (buffer file) | ||
| 151 | "Writes the contents of BUFFER into FILE, if permissions allow." | ||
| 152 | (if (not (file-writable-p file)) | ||
| 153 | (error "No permission to write file %s" file)) | ||
| 154 | (save-excursion | ||
| 155 | (set-buffer buffer) | ||
| 156 | (clear-visited-file-modtime) | ||
| 157 | (save-restriction | ||
| 158 | (widen) | ||
| 159 | (write-region (point-min) (point-max) file nil 'quiet)) | ||
| 160 | (set-buffer-modified-p nil))) | ||