App-Chart
view release on metacpan or search on metacpan
emacs/chartprog.el view on Meta::CPAN
(let ((inhibit-read-only t))
(erase-buffer)
(insert (format "Chart program doesn't match this chartprog.el.
chartprog.el protocol: %s
chart program protocol: %s
Check your installation.
" chartprog-protocol-version protocol-version)))))
(chartprog-process-kill)
(error "Chart subprocess protocol version mismatch, got %s want %s"
chartprog-protocol-version protocol-version)))
(defun chartprog-process-filter (proc str)
"An internal part of chartprog.el.
The filter function for the chart subprocess per
`set-process-filter'.
STR is more text from the subprocess.
An incoming message is a Lisp form like (FOO (\"ABC\")).
When a complete form has arrived the corresponding
`chart-incoming-FOO' function is called."
(with-current-buffer (process-buffer proc)
(goto-char (point-max))
(insert str)
(while (progn
;; form begins with "(", ignore other diagnostics or whatever
(goto-char (point-min))
(skip-chars-forward "^(")
(delete-region (point-min) (point))
;; see if a complete form has arrived
(let ((form (condition-case nil
(read (process-buffer proc))
(error nil))))
(when form
(delete-region (point-min) (point))
(chartprog-debug-message "incoming " form)
(apply (intern (concat "chartprog-incoming-"
(symbol-name (car form))))
(cdr form)))
;; no more processing after `synchronous', let the result get
;; back to the caller before further asynch stuff is
;; processed (that further stuff deferred under a timer)
(when (eq (car form) 'synchronous)
(run-at-time 0.0000001 nil
(lambda ()
(chartprog-process-filter chartprog-process "")))
(setq form nil))
;; process another form, perhaps
form)))))
(defun chartprog-process-sentinel (proc event)
"An internal part of chartprog.el.
The sentinel for the chart subprocess per `set-process-sentinel'.
The subprocess should stay alive forever, until we ask it to stop
by the `chartprog-process-timer, so any termination is
unexpected."
(when (get-buffer "*chartprog-watchlist*")
(with-current-buffer "*chartprog-watchlist*"
(let ((inhibit-read-only t))
(save-excursion
(goto-char (point-min))
(when (looking-at "\\s-*Starting")
(erase-buffer))
(insert (format "\nSubprocess died: %s\n\n" event))))))
(chartprog-process-kill)
(message "Chart subprocess died: %s" event))
(defun chartprog-process-kill ()
"An internal part of chartprog.el.
Kill chart subprocess."
(when chartprog-process-timer
(cancel-timer chartprog-process-timer)
(setq chartprog-process-timer nil))
(when chartprog-process
;; clear chartprog-process variable immediately, xemacs recurses to here
(let ((p chartprog-process))
(setq chartprog-process nil)
(set-process-sentinel p nil)
(set-process-filter p nil)
(delete-process p)
(kill-buffer (process-buffer p)))
;; go back to uninitialized to force a re-read on the contents if the
;; subprocess is restarted, that way any additions while we were away
;; will appear
(setq chartprog-completion-symbols-alist 'uninitialized)
(setq chartprog-symlist-alist 'uninitialized)
(setq chartprog-latest-cache (make-hash-table :test 'equal))))
;;-----------------------------------------------------------------------------
;; synchronous commands
(defvar chartprog-exec-synchronous-seq 0)
(defvar chartprog-exec-synchronous-got 0)
(defvar chartprog-exec-synchronous-result nil)
(defun chartprog-incoming-synchronous (got result)
"An internal part of chartprog.el.
Receive synchronize number GOT from Chart subprocess."
(setq chartprog-exec-synchronous-got got)
(setq chartprog-exec-synchronous-result result))
(defun chartprog-exec-synchronous (proc &rest args)
"An internal part of chartprog.el.
Call chart PROC (a symbol) with ARGS (lists, strings, etc).
Return the return value from that call, when it completes."
(setq chartprog-exec-synchronous-seq (1+ chartprog-exec-synchronous-seq))
(apply 'chartprog-exec 'synchronous chartprog-exec-synchronous-seq proc args)
(while (not (= chartprog-exec-synchronous-seq
chartprog-exec-synchronous-got)) ;; ignore old abandoned calls
(if (not (eq 'run (process-status chartprog-process)))
(error "Chart subprocess died"))
( run in 0.829 second using v1.01-cache-2.11-cpan-df04353d9ac )