[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [h-e-w] Need help with lisp function and comint interaction
From: |
Stephen Leake |
Subject: |
Re: [h-e-w] Need help with lisp function and comint interaction |
Date: |
05 Feb 2002 11:34:38 -0500 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
Robert Mecklenburg <address@hidden> writes:
> I've got this function which will execute a cvs query to determine the
> tags on a cvs controlled file and build a for loop to remove the cvs
> tags on the file. The function is very useful when renaming cvs
> files. Unfortunately, it "fails" for files with long tags lists
> (precisely those where it would be most useful). The failure, I
> believe, is that it doesn't properly wait for the cvs process output
> to complete before searching for tags. I'm having trouble getting that
> part right. Any suggestions?
I've also written some elisp to interface with cvs. I don't use
comint; I use start-process directly, and use a "sentinel" to process
the output when cvs is done. Emacs ensures the wait is done properly.
Here's a snippet:
(defun cvs-run-process (global-args command command-args files &optional
post-process run-directory)
"Change to 'run-directory', run \"cvs global-args command
command-args files\", output to current buffer. command is a string;
global-args, command-args, files are lists of strings."
(interactive) ; for testing
;; check for a pre-existing process
(when cvs-process
(when (memq (process-status cvs-process) '(run stop))
(error "Can not run two cvs processes simultaneously.")))
;; don't let user modify user buffer until the sentinal runs
(use-local-map cvs-running-mode-map)
; setup process buffer
(save-excursion
(set-buffer cvs-process-buffer)
(setq cvs-post-process post-process)
(erase-buffer))
(let* ((args (append cvs-global-flags
(if cvs-cvsroot (list "-d" cvs-cvsroot))
global-args
(list command)
command-args
files))
(process-connection-type nil) ; Tell start-process to use a pipe, not
a pty.
(default-directory (or run-directory default-directory)))
(save-excursion
(set-buffer cvs-process-buffer)
(goto-char (point-min))
(insert cvs-program " " (mapconcat 'concat args " ") "\n"))
(let ((process (apply 'start-process "cvs" cvs-process-buffer cvs-program
args)))
(set-process-sentinel process 'cvs-sentinel)
(setq cvs-process process)
(setq mode-line-process ": run")
(force-mode-line-update)) ) )
(defun cvs-sentinel (proc msg)
"Sentinel for the cvs command process."
(when (memq (process-status proc) '(signal exit))
(set-buffer (process-buffer proc))
;; cvs-user-buffer now has the right buffer-local value
(set-buffer cvs-user-buffer)
(use-local-map cvs-mode-map)
(if (eq (process-exit-status proc) 1) ; error
(progn
(setq mode-line-process ": error")
(cvs-show-output)
;; if post process is one of the following, run it even for
;; error status, because conflicts (sometimes !) report
;; error status
(set-buffer cvs-process-buffer) ; cvs-post-process is only defined in
that buffer
(if (or
(eq cvs-post-process 'cvs-post-refresh)
(eq cvs-post-process 'cvs-post-update-diff-commit)
)
(funcall cvs-post-process)))
;; not error
(setq mode-line-process ": ready")
(set-buffer cvs-process-buffer) ; cvs-post-process is only defined in
that buffer
(if cvs-post-process
(funcall cvs-post-process)))
;; Since the buffer and mode line will show that the
;; process is dead, we can delete it now.
(delete-process proc)) )
See http://users.erols.com/leakstan/Stephe/emacs/index.html for the
full source code; sal-cvs-mode.zip
--
-- Stephe