1 ;;; gds.el -- frontend for Guile development in Emacs
3 ;;;; Copyright (C) 2003 Free Software Foundation, Inc.
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 2.1 of the License, or (at your option) any later
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free
18 ;;;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
32 ;;;; Customization group setup.
35 "Customization options for Guile Emacs frontend."
39 ;;;; Communication with the (emacs gds-server) subprocess.
41 ;; The subprocess object.
42 (defvar gds-process nil
)
44 ;; Subprocess output goes into the `*GDS Process*' buffer, and
45 ;; is then read from there one form at a time. `gds-read-cursor' is
46 ;; the buffer position of the start of the next unread form.
47 (defvar gds-read-cursor nil
)
49 ;; The guile executable used by the GDS server and captive client
51 (defcustom gds-guile-program
"guile"
52 "*The guile executable used by GDS, specifically by its server and
53 captive client processes."
58 "Start (or restart, if already running) the GDS subprocess."
61 (if gds-process
(gds-shutdown))
62 (with-current-buffer (get-buffer-create "*GDS Process*")
65 (let ((process-connection-type nil
)) ; use a pipe
72 "(begin (use-modules (emacs gds-server)) (run-server))"))))
73 (setq gds-read-cursor
(point-min))
74 (set-process-filter gds-process
(function gds-filter
))
75 (set-process-sentinel gds-process
(function gds-sentinel
))
76 (set-process-coding-system gds-process
'latin-1-unix
)
77 (process-kill-without-query gds-process
))
79 ;; Shutdown the subprocess and cleanup all associated data.
80 (defun gds-shutdown ()
81 "Shut down the GDS subprocess."
84 (setq gds-buffers nil
)
85 ;; Kill the subprocess.
88 (kill-process gds-process
)
89 (accept-process-output gds-process
0 200))
91 (setq gds-process nil
))
93 ;; Subprocess output filter: inserts normally into the process buffer,
94 ;; then tries to reread the output one form at a time and delegates
95 ;; processing of each form to `gds-handle-input'.
96 (defun gds-filter (proc string
)
97 (with-current-buffer (process-buffer proc
)
99 (goto-char (process-mark proc
))
100 (insert-before-markers string
))
101 (goto-char gds-read-cursor
)
102 (while (let ((form (condition-case nil
103 (read (current-buffer))
107 (gds-handle-input form
)))
109 (setq gds-read-cursor
(point)))))
111 ;; Subprocess sentinel: do nothing. (Currently just here to avoid
112 ;; inserting un-`read'able process status messages into the process
114 (defun gds-sentinel (proc event
)
117 ;; Send input to the subprocess.
118 (defun gds-send (string client
)
119 (process-send-string gds-process
(format "(%S %s)\n" client string
))
120 (let ((buf (gds-client-ref 'gds-transcript
)))
122 (with-current-buffer buf
123 (goto-char (point-max))
124 (let ((inhibit-read-only t
))
125 (insert (format "tx (%S %s)\n" client string
)))))))
128 ;;;; Focussing in and out on interaction with a particular client.
130 ;;;; The slight possible problems here are that popping up a client's
131 ;;;; interaction windows when that client wants attention might
132 ;;;; interrupt something else that the Emacs user was working on at
133 ;;;; the time, and that if multiple clients are being debugged at the
134 ;;;; same time, their popping up of interaction windows might become
135 ;;;; confusing. For this reason, we allow GDS's behavior to be
136 ;;;; customized via the variables `gds-focus-in-function' and
137 ;;;; `gds-focus-out-function'.
139 ;;;; That said, the default policy, which is probably OK for most
140 ;;;; users most of the time, is very simple: when a client wants
141 ;;;; attention, its interaction windows are popped up immediately.
143 (defun gds-request-focus (client)
144 (funcall gds-focus-in-function client
))
146 (defcustom gds-focus-in-function
(function gds-focus-in
)
147 "Function to call when a GDS client program wants user attention.
148 The function is called with one argument, the CLIENT in question."
152 (defun gds-focus-in (client)
153 (gds-display-buffers client
))
157 (funcall gds-focus-out-function
))
159 (defcustom gds-focus-out-function
(function gds-focus-out
)
160 "Function to call when user quits interacting with a GDS client."
164 (defun gds-focus-out ()
165 (if (if (gds-client-blocked)
166 (y-or-n-p "Client is waiting for input. Quit anyway? ")
168 (bury-buffer (current-buffer))))
171 ;;;; Multiple client focus -- an alternative implementation.
173 ;;;; The following code is provided as an alternative example of how a
174 ;;;; customized GDS could schedule the display of multiple clients
175 ;;;; that are competing for user attention.
177 ;; - `gds-waiting' holds a list of clients that want attention but
178 ;; haven't yet got it. A client is added to this list for two
179 ;; reasons. (1) When it is blocked waiting for user input.
180 ;; (2) When it first connects to GDS, even if not blocked.
182 ;; - `gds-focus-client' holds the client, if any, that currently has
183 ;; the user's attention. A client can be given the focus if
184 ;; `gds-focus-client' is nil at the time that the client wants
185 ;; attention, or if another client relinquishes it. A client can
186 ;; relinquish the focus in two ways. (1) If the client application
187 ;; says that it is no longer blocked, and a small time passes without
188 ;; it becoming blocked again. (2) If the user explicitly `quits'
191 ;; (defvar gds-focus-client nil)
192 ;; (defvar gds-waiting nil)
194 ;; (defun gds-focus-in-alternative (client)
195 ;; (cond ((eq client gds-focus-client)
196 ;; ;; CLIENT already has the focus. Display its buffer.
197 ;; (gds-display-buffers client))
199 ;; ;; Another client has the focus. Add CLIENT to `gds-waiting'.
200 ;; (or (memq client gds-waiting)
201 ;; (setq gds-waiting (append gds-waiting (list client)))))
203 ;; ;; Give focus to CLIENT and display its buffer.
204 ;; (setq gds-focus-client client)
205 ;; (gds-display-buffers client))))
207 ;; (defun gds-focus-out-alternative ()
208 ;; (if (or (car gds-waiting)
209 ;; (not (gds-client-blocked))
211 ;; "Client is blocked and no others are waiting. Still quit? "))
213 ;; (bury-buffer (current-buffer))
214 ;; ;; Pass on the focus.
215 ;; (setq gds-focus-client (car gds-waiting)
216 ;; gds-waiting (cdr gds-waiting))
217 ;; ;; If this client is blocked, add it back into the waiting list.
218 ;; (if (gds-client-blocked)
219 ;; (gds-request-focus gds-client))
220 ;; ;; If there is a new focus client, request display for it.
221 ;; (if gds-focus-client
222 ;; (gds-request-focus gds-focus-client)))))
225 ;;;; GDS protocol dispatch.
227 ;; General dispatch function called by the subprocess filter.
228 (defun gds-handle-input (form)
229 (let ((client (car form
)))
231 (let* ((proc (cadr form
))
233 (buf (gds-client-buffer client proc args
)))
234 (if buf
(gds-handle-client-input buf client proc args
))))))
236 (defun gds-handle-client-input (buf client proc args
)
237 (with-current-buffer buf
238 (with-current-buffer gds-transcript
239 (goto-char (point-max))
240 (let ((inhibit-read-only t
))
241 (insert (format "rx %S" (cons client
(cons proc args
))) "\n")))
243 (cond (;; (name ...) - Client name.
245 (setq gds-pid
(cadr args
))
246 (gds-promote-view 'interaction
)
247 (gds-request-focus client
))
249 (;; (current-module ...) - Current module.
250 (eq proc
'current-module
)
251 (setq gds-current-module
(car args
)))
253 (;; (stack ...) - Stack at an error or breakpoint.
255 (setq gds-stack args
)
256 (gds-promote-view 'stack
))
258 (;; (modules ...) - Application's loaded modules.
261 (or (assoc (car args
) gds-modules
)
262 (setq gds-modules
(cons (list (car args
)) gds-modules
)))
263 (setq args
(cdr args
))))
265 (;; (output ...) - Last printed output.
267 (setq gds-output
(car args
))
268 (gds-add-view 'messages
))
270 (;; (status ...) - Application status indication.
272 (setq gds-status
(car args
))
273 (if (eq gds-status
'running
)
274 (gds-delete-view 'browser
)
275 (gds-add-view 'browser
))
276 (if (eq gds-status
'waiting-for-input
)
278 (gds-promote-view 'stack
)
280 (gds-request-focus client
))
282 (gds-delete-view 'stack
)
283 (gds-update-buffers-in-a-while)))
285 (;; (module MODULE ...) - The specified module's bindings.
287 (let ((minfo (assoc (car args
) gds-modules
)))
289 (setcdr (cdr minfo
) (cdr args
)))))
291 (;; (closed) - Client has gone away.
293 (setq gds-status
'closed
)
296 (delq (assq client gds-buffers
) gds-buffers
)))
298 (;; (eval-results ...) - Results of evaluation.
299 (eq proc
'eval-results
)
300 (gds-display-results client
(car args
) (cdr args
)))
302 (;; (completion-result ...) - Available completions.
303 (eq proc
'completion-result
)
304 (setq gds-completion-results
(or (car args
) t
)))
306 (;; (breakpoint-set FILE LINE COLUMN INFO) - Breakpoint set.
307 (eq proc
'breakpoint-set
)
308 (let ((file (nth 0 args
))
310 (column (nth 2 args
))
312 (with-current-buffer (find-file-noselect file
)
314 (goto-char (point-min))
317 (move-to-column column
)
318 (let ((os (overlays-at (point))) o
)
320 (if (and (overlay-get (car os
) 'gds-breakpoint-info
)
321 (= (overlay-start (car os
)) (point)))
323 (overlay-put (car os
)
326 (overlay-put (car os
)
328 gds-active-breakpoint-before-string
)
329 (overlay-put (car os
)
331 gds-active-breakpoint-after-string
)
333 (setq os
(cdr os
)))))))))
335 (;; (thread-status THREAD-TYPE THREAD-NUMBER STATUS [CORRELATOR])
336 (eq proc
'thread-status
)
337 (if (eq (car args
) 'eval
)
338 (let ((number (nth 1 args
))
339 (status (nth 2 args
))
340 (correlator (nth 3 args
)))
341 (if (eq status
'busy
)
343 (setq gds-evals-in-progress
344 (append gds-evals-in-progress
345 (list (cons number correlator
))))
347 (function gds-display-slow-eval
)
348 buf number correlator
)
349 (gds-promote-view 'interaction
))
350 (let ((existing (assq number gds-evals-in-progress
)))
352 (setq gds-evals-in-progress
353 (delq existing gds-evals-in-progress
)))))
354 (gds-update-buffers))))
358 (defun gds-display-slow-eval (buf number correlator
)
359 (with-current-buffer buf
360 (let ((entry (assq number gds-evals-in-progress
)))
362 (eq (cdr entry
) correlator
))
364 (gds-promote-view 'interaction
)
365 (gds-request-focus gds-client
))))))
368 ;;;; Per-client buffer state.
370 ;; This section contains code that is specific to each Guile client's
371 ;; buffer but independent of any particular `view'.
373 ;; Alist mapping each client port number to corresponding buffer.
374 (defvar gds-buffers nil
)
376 (define-derived-mode gds-mode
379 "Major mode for interacting with a Guile client application."
380 (widget-minor-mode 1))
382 (defvar gds-client nil
383 "GDS client's port number.")
384 (make-variable-buffer-local 'gds-client
)
386 (defvar gds-status nil
387 "GDS client's latest status, one of the following symbols.
388 `running' - Application is running.
389 `waiting-for-input' - Application is blocked waiting for instruction
391 `ready-for-input' - Application is not blocked but can also accept
392 asynchronous instructions from the frontend.")
393 (make-variable-buffer-local 'gds-status
)
395 (defvar gds-transcript nil
396 "Transcript buffer for this GDS client.")
397 (make-variable-buffer-local 'gds-transcript
)
399 ;; Return client buffer for specified client and protocol input.
400 (defun gds-client-buffer (client proc args
)
402 ;; Introduction from client - create a new buffer.
403 (with-current-buffer (generate-new-buffer (car args
))
405 (setq gds-client client
)
408 (expand-file-name (concat "~/.gds-transcript-" (car args
)))))
409 (with-current-buffer gds-transcript
410 (goto-char (point-max))
411 (insert "\nTranscript:\n"))
413 (cons (cons client
(current-buffer))
416 ;; Otherwise there should be an existing buffer that we can
418 (let ((existing (assq client gds-buffers
)))
419 (if (buffer-live-p (cdr existing
))
421 (setq gds-buffers
(delq existing gds-buffers
))
422 (gds-client-buffer client
'name
'("(GDS buffer killed)"))))))
424 ;; Get the current buffer's associated client's value of SYM.
425 (defun gds-client-ref (sym &optional client
)
426 (and (or client gds-client
)
427 (let ((buf (assq (or client gds-client
) gds-buffers
)))
430 (buffer-live-p (cdr buf
))
431 (with-current-buffer (cdr buf
)
432 (symbol-value sym
))))))
434 (defun gds-client-blocked ()
435 (eq (gds-client-ref 'gds-status
) 'waiting-for-input
))
437 (defvar gds-delayed-update-timer nil
)
439 (defvar gds-delayed-update-buffers nil
)
441 (defun gds-update-delayed-update-buffers ()
442 (while gds-delayed-update-buffers
443 (with-current-buffer (car gds-delayed-update-buffers
)
444 (setq gds-delayed-update-buffers
445 (cdr gds-delayed-update-buffers
))
446 (gds-update-buffers))))
448 (defun gds-update-buffers ()
449 (if (timerp gds-delayed-update-timer
)
450 (cancel-timer gds-delayed-update-timer
))
451 (setq gds-delayed-update-timer nil
)
452 (let ((view (car gds-views
))
453 (inhibit-read-only t
))
454 (cond ((eq view
'stack
)
456 ((eq view
'interaction
)
457 (gds-insert-interaction))
459 (gds-insert-modules))
461 (gds-insert-messages))
463 (error "Bad GDS view %S" view
)))
465 (force-mode-line-update t
)))
467 (defun gds-update-buffers-in-a-while ()
468 (or (memq (current-buffer) gds-delayed-update-buffers
)
469 (setq gds-delayed-update-buffers
470 (cons (current-buffer) gds-delayed-update-buffers
)))
471 (if (timerp gds-delayed-update-timer
)
473 (setq gds-delayed-update-timer
474 (run-at-time 0.5 nil
(function gds-update-delayed-update-buffers
)))))
476 (defun gds-display-buffers (client)
477 (let ((buf (cdr (assq client gds-buffers
))))
478 ;; If there's already a window showing the buffer, use it.
479 (let ((window (get-buffer-window buf t
)))
482 (make-frame-visible (window-frame window
))
483 (select-frame (window-frame window
))
484 (select-window window
))
485 ;;(select-window (display-buffer buf))
486 (display-buffer buf
)))
487 ;; If there is an associated source buffer, display it as well.
488 (if (and (eq (car gds-views
) 'stack
)
489 gds-frame-source-overlay
490 (> (overlay-end gds-frame-source-overlay
) 1))
491 (let ((window (display-buffer
492 (overlay-buffer gds-frame-source-overlay
))))
493 (set-window-point window
494 (overlay-start gds-frame-source-overlay
))))))
497 ;;;; Management of `views'.
499 ;; The idea here is to keep the buffer describing a Guile client
500 ;; relatively uncluttered by only showing one kind of information
501 ;; about that client at a time. Menu items and key sequences are
502 ;; provided to switch easily between the available views.
504 (defvar gds-views nil
505 "List of available views for a GDS client. Each element is one of
506 the following symbols.
507 `interaction' - Interaction with running client.
508 `stack' - Call stack view.
509 `browser' - Modules and bindings browser view.
510 `breakpoints' - List of set breakpoints.
511 `messages' - Non-GDS-protocol output from the debugger.")
512 (make-variable-buffer-local 'gds-views
)
514 (defun gds-promote-view (view)
515 (setq gds-views
(cons view
(delq view gds-views
))))
517 (defun gds-switch-to-view (view)
518 (or (memq view gds-views
)
519 (error "View %S is not available" view
))
520 (gds-promote-view view
)
521 (gds-update-buffers))
523 (defun gds-add-view (view)
524 (or (memq view gds-views
)
525 (setq gds-views
(append gds-views
(list view
)))))
527 (defun gds-delete-view (view)
528 (setq gds-views
(delq view gds-views
)))
531 ;;;; `Interaction' view.
533 ;; This view provides interaction with a normally running Guile
534 ;; client, in other words one that is not stopped in the debugger but
535 ;; is still available to take input from GDS (usually via a thread for
536 ;; that purpose). The view supports evaluation, help requests,
537 ;; control of `debug-on-exception' function, and methods for breaking
538 ;; into the running code.
540 (defvar gds-current-module
"()"
541 "GDS client's current module.")
542 (make-variable-buffer-local 'gds-current-module
)
545 "GDS client's process ID.")
546 (make-variable-buffer-local 'gds-pid
)
548 (defvar gds-debug-exceptions nil
549 "Whether to debug exceptions.")
550 (make-variable-buffer-local 'gds-debug-exceptions
)
552 (defvar gds-exception-keys
"signal misc-error"
553 "The exception keys for which to debug a GDS client.")
554 (make-variable-buffer-local 'gds-exception-keys
)
556 (defvar gds-evals-in-progress nil
557 "Alist describing evaluations in progress.")
558 (make-variable-buffer-local 'gds-evals-in-progress
)
560 (defvar gds-results nil
561 "Last help or evaluation results.")
562 (make-variable-buffer-local 'gds-results
)
564 (defcustom gds-heading-face
'info-menu-header
565 "*Face used for headings in Guile Interaction buffers."
569 (defun gds-insert-interaction ()
571 ;; Insert stuff for interacting with a running (non-blocked) Guile
573 (gds-heading-insert (buffer-name))
575 (cdr (assq gds-status
576 '((running .
"running (cannot accept input)")
577 (waiting-for-input .
"waiting for input")
578 (ready-for-input .
"running")
579 (closed .
"closed"))))
583 (widget-create 'push-button
584 :notify
(function gds-sigint
)
587 (widget-create 'push-button
588 :notify
(function gds-async-break
)
591 (widget-create 'checkbox
592 :notify
(function gds-toggle-debug-exceptions
)
593 gds-debug-exceptions
)
594 (widget-insert " Debug exception keys: ")
595 (widget-create 'editable-field
596 :notify
(function gds-set-exception-keys
)
598 ;; Evaluation report area.
600 (gds-heading-insert "Recent Evaluations")
601 (widget-insert " To run an evaluation, see the Guile->Evaluate menu.\n")
603 (widget-insert "\n" (cdr gds-results
)))
604 (let ((evals gds-evals-in-progress
))
606 (widget-insert "\n" (cddar evals
) " - running ")
607 (let ((w (widget-create 'push-button
608 :notify
(function gds-interrupt-eval
)
610 (widget-put w
:thread-number
(caar evals
)))
612 (setq evals
(cdr evals
)))))
614 (defun gds-heading-insert (text)
615 (let ((start (point)))
617 (let ((o (make-overlay start
(point))))
618 (overlay-put o
'face gds-heading-face
)
619 (overlay-put o
'evaporate t
))))
621 (defun gds-sigint (w &rest ignore
)
623 (signal-process gds-pid
2))
625 (defun gds-async-break (w &rest ignore
)
627 (gds-send "async-break" gds-client
))
629 (defun gds-interrupt-eval (w &rest ignore
)
631 (gds-send (format "interrupt-eval %S" (widget-get w
:thread-number
))
634 (defun gds-toggle-debug-exceptions (w &rest ignore
)
636 (setq gds-debug-exceptions
(widget-value w
))
637 (gds-eval-expression (concat "(use-modules (ice-9 debugger))"
642 (defun gds-set-exception-keys (w &rest ignore
)
644 (setq gds-exception-keys
(widget-value w
)))
646 (defun gds-view-interaction ()
648 (gds-switch-to-view 'interaction
))
653 ;; This view shows the Guile call stack after the application has hit
654 ;; an error, or when it is stopped in the debugger.
656 (defvar gds-stack nil
657 "GDS client's stack when last stopped.")
658 (make-variable-buffer-local 'gds-stack
)
660 (defun gds-insert-stack ()
662 (let ((frames (car gds-stack
))
663 (index (cadr gds-stack
))
664 (flags (caddr gds-stack
))
666 (cond ((memq 'application flags
)
667 (widget-insert "Calling procedure:\n"))
668 ((memq 'evaluation flags
)
669 (widget-insert "Evaluating expression:\n"))
670 ((memq 'return flags
)
671 (widget-insert "Return value: "
672 (cadr (memq 'return flags
))
675 (widget-insert "Stack: " (prin1-to-string flags
) "\n")))
677 (gds-show-selected-frame (caddr (nth index frames
)))
679 (setq frame
(car frames
)
682 items
(cons (list 'item
683 (let ((s (cadr frame
)))
684 (put-text-property 0 1 'index i s
)
687 (setq items
(nreverse items
))
688 (apply (function widget-create
)
690 :value
(cadr (nth index items
))
691 :notify
(function gds-select-stack-frame
)
694 (goto-char (point-min))))
696 (defun gds-select-stack-frame (widget &rest ignored
)
697 (let* ((s (widget-value widget
))
698 (ind (memq 'index
(text-properties-at 0 s
))))
699 (gds-send (format "debugger-command frame %d" (cadr ind
))
702 ;; Overlay used to highlight the source expression corresponding to
703 ;; the selected frame.
704 (defvar gds-frame-source-overlay nil
)
706 (defun gds-show-selected-frame (source)
707 ;; Highlight the frame source, if possible.
709 (file-readable-p (car source
)))
710 (with-current-buffer (find-file-noselect (car source
))
711 (if gds-frame-source-overlay
713 (setq gds-frame-source-overlay
(make-overlay 0 0))
714 (overlay-put gds-frame-source-overlay
'face
'highlight
))
715 ;; Move to source line. Note that Guile line numbering is
716 ;; 0-based, while Emacs numbering is 1-based.
719 (goto-line (+ (cadr source
) 1))
720 (move-to-column (caddr source
))
721 (move-overlay gds-frame-source-overlay
723 (if (not (looking-at ")"))
724 (save-excursion (forward-sexp 1) (point))
725 ;; It seems that the source coordinates for
726 ;; backquoted expressions are at the end of
727 ;; the sexp rather than the beginning...
728 (save-excursion (forward-char 1)
729 (backward-sexp 1) (point)))
731 (if gds-frame-source-overlay
732 (move-overlay gds-frame-source-overlay
0 0))))
734 (defun gds-view-stack ()
736 (gds-switch-to-view 'stack
))
739 ;;;; `Breakpoints' view.
741 ;; This view shows a list of breakpoints.
743 (defun gds-view-breakpoints ()
745 (gds-switch-to-view 'breakpoints
))
750 ;; This view shows a list of modules and module bindings.
752 (defcustom gds-module-filter
'(t (guile nil
) (ice-9 nil
) (oop nil
))
753 "Specification of which Guile modules the debugger should display.
754 This is a list with structure (DEFAULT EXCEPTION EXCEPTION...), where
755 DEFAULT is `t' or `nil' and each EXCEPTION has the structure (SYMBOL
756 DEFAULT EXCEPTION EXCEPTION...).
758 A Guile module name `(x y z)' is matched against this filter as
759 follows. If one of the top level EXCEPTIONs has SYMBOL `x', continue
760 by matching the rest of the module name, in this case `(y z)', against
761 that SYMBOL's DEFAULT and next level EXCEPTION list. Otherwise, if
762 the current DEFAULT is `t' display the module, and if the current
763 DEFAULT is `nil', don't display it.
765 This variable is usually set to exclude Guile system modules that are
766 not of primary interest when debugging application code."
770 (defun gds-show-module-p (name)
771 ;; Determine whether to display the NAMEd module by matching NAME
772 ;; against `gds-module-filter'.
773 (let ((default (car gds-module-filter
))
774 (exceptions (cdr gds-module-filter
)))
775 (let ((exception (assq (car name
) exceptions
)))
777 (let ((gds-module-filter (cdr exception
)))
778 (gds-show-module-p (cdr name
)))
781 (defvar gds-modules nil
782 "GDS client's module information.
783 Alist mapping module names to their symbols and related information.
786 (((guile) t sym1 sym2 ...)
788 ((ice-9 debug) nil sym3 sym4)
791 The `t' or `nil' after the module name indicates whether the module is
792 displayed in expanded form (that is, showing the bindings in that
793 module). The syms are actually all strings because some Guile symbols
794 are not readable by Emacs.")
795 (make-variable-buffer-local 'gds-modules
)
797 (defun gds-insert-modules ()
798 (let ((p (if (eq (window-buffer (selected-window)) (current-buffer))
801 (modules gds-modules
))
803 (insert "Modules:\n")
805 (let ((minfo (car modules
)))
806 (if (gds-show-module-p (car minfo
))
807 (let ((w (widget-create 'push-button
808 :notify
(function gds-module-notify
)
812 (widget-put w
:module
(cons gds-client
(car minfo
)))
813 (widget-insert " " (prin1-to-string (car minfo
)) "\n")
815 (let ((syms (cddr minfo
)))
817 (widget-insert " > " (car syms
) "\n")
818 (setq syms
(cdr syms
))))))))
819 (setq modules
(cdr modules
)))
823 (defun gds-module-notify (w &rest ignore
)
824 (let* ((module (widget-get w
:module
))
825 (client (car module
))
827 (minfo (assoc name gds-modules
)))
829 ;; Just toggle expansion state.
831 (setcar (cdr minfo
) (not (cadr minfo
)))
832 (gds-update-buffers))
833 ;; Set flag to indicate module expanded.
834 (setcdr minfo
(list t
))
835 ;; Get symlist from Guile.
836 (gds-send (format "query-module %S" name
) client
))))
838 (defun gds-query-modules ()
840 (gds-send "query-modules" gds-client
))
842 (defun gds-view-browser ()
844 (or gds-modules
(gds-query-modules))
845 (gds-switch-to-view 'browser
))
848 ;;;; `Messages' view.
850 ;; This view shows recent non-GDS-protocol messages output from the
851 ;; (ice-9 debugger) code.
853 (defvar gds-output nil
854 "GDS client's recent output (printed).")
855 (make-variable-buffer-local 'gds-output
)
857 (defun gds-insert-messages ()
859 ;; Insert recent non-protocol output from (ice-9 debugger).
861 (goto-char (point-min)))
863 (defun gds-view-messages ()
865 (gds-switch-to-view 'messages
))
868 ;;;; Debugger commands.
870 ;; Typically but not necessarily used from the `stack' view.
874 (gds-send "debugger-command continue" gds-client
))
878 (gds-send "debugger-command next 1" gds-client
))
880 (defun gds-evaluate (expr)
881 (interactive "sEvaluate (in this stack frame): ")
882 (gds-send (format "debugger-command evaluate %s" (prin1-to-string expr
))
885 (defun gds-step-in ()
887 (gds-send "debugger-command step 1" gds-client
))
889 (defun gds-step-out ()
891 (gds-send "debugger-command finish" gds-client
))
893 (defun gds-trace-finish ()
895 (gds-send "debugger-command trace-finish" gds-client
))
897 (defun gds-frame-info ()
899 (gds-send "debugger-command info-frame" gds-client
))
901 (defun gds-frame-args ()
903 (gds-send "debugger-command info-args" gds-client
))
905 (defun gds-debug-trap-hooks ()
907 (gds-send "debugger-command debug-trap-hooks" gds-client
))
911 (gds-send "debugger-command up 1" gds-client
))
915 (gds-send "debugger-command down 1" gds-client
))
918 ;;;; Setting breakpoints.
920 (defun gds-set-breakpoint ()
922 (cond ((gds-in-source-buffer)
923 (gds-set-source-breakpoint))
925 (gds-set-stack-breakpoint))
927 (gds-set-module-breakpoint))
929 (error "No way to set a breakpoint from here"))))
931 (defun gds-in-source-buffer ()
932 ;; Not yet worked out what will be available in Scheme source
936 (defun gds-in-stack ()
938 (and (re-search-backward "^\\(Stack\\|Modules\\):" nil t
)
939 (looking-at "Stack"))))
941 (defun gds-in-modules ()
943 (and (re-search-backward "^\\(Stack\\|Modules\\):" nil t
)
944 (looking-at "Modules"))))
946 (defun gds-set-module-breakpoint ()
947 (let ((sym (save-excursion
949 (and (looking-at " > \\([^ \n\t]+\\)")
951 (module (save-excursion
952 (and (re-search-backward "^\\[[+---]\\] \\(([^)]+)\\)" nil t
)
955 (error "Couldn't find procedure name on current line"))
957 (error "Couldn't find module name for current line"))
960 (format "Behaviour for breakpoint at %s:%s (default debug-here): "
970 (gds-send (format "set-breakpoint %s %s %s"
977 ;;;; Scheme source breakpoints.
979 (defcustom gds-breakpoint-face
'default
980 "*Face used to highlight the location of a source breakpoint.
981 Specifically, this face highlights the opening parenthesis of the
982 form where the breakpoint is set."
986 (defcustom gds-new-breakpoint-before-string
""
987 "*String used to show the presence of a new source breakpoint.
988 `New' means that the breakpoint has been set but isn't yet known to
989 Guile because the containing code hasn't been reevaluated yet.
990 This string appears before the opening parenthesis of the form where
991 the breakpoint is set. If you prefer a marker to appear after the
992 opening parenthesis, make this string empty and use
993 `gds-new-breakpoint-after-string'."
997 (defcustom gds-new-breakpoint-after-string
"=?= "
998 "*String used to show the presence of a new source breakpoint.
999 `New' means that the breakpoint has been set but isn't yet known to
1000 Guile because the containing code hasn't been reevaluated yet.
1001 This string appears after the opening parenthesis of the form where
1002 the breakpoint is set. If you prefer a marker to appear before the
1003 opening parenthesis, make this string empty and use
1004 `gds-new-breakpoint-before-string'."
1008 (defcustom gds-active-breakpoint-before-string
""
1009 "*String used to show the presence of a source breakpoint.
1010 `Active' means that the breakpoint is known to Guile.
1011 This string appears before the opening parenthesis of the form where
1012 the breakpoint is set. If you prefer a marker to appear after the
1013 opening parenthesis, make this string empty and use
1014 `gds-active-breakpoint-after-string'."
1018 (defcustom gds-active-breakpoint-after-string
"=|= "
1019 "*String used to show the presence of a source breakpoint.
1020 `Active' means that the breakpoint is known to Guile.
1021 This string appears after the opening parenthesis of the form where
1022 the breakpoint is set. If you prefer a marker to appear before the
1023 opening parenthesis, make this string empty and use
1024 `gds-active-breakpoint-before-string'."
1028 (defun gds-source-breakpoint-pos ()
1029 "Return the position of the starting parenthesis of the innermost
1030 Scheme pair around point."
1031 (if (eq (char-syntax (char-after)) ?\
()
1035 (while t
(forward-sexp -
1))
1038 (while (not (eq (char-syntax (char-after)) ?\
())
1042 (defun gds-source-breakpoint-overlay-at (pos)
1043 "Return the source breakpoint overlay at POS, if any."
1044 (let* (o (os (overlays-at pos
)))
1046 (if (and (overlay-get (car os
) 'gds-breakpoint-info
)
1047 (= (overlay-start (car os
)) pos
))
1053 (defun gds-set-source-breakpoint ()
1055 (let* ((pos (gds-source-breakpoint-pos))
1056 (o (gds-source-breakpoint-overlay-at pos
)))
1058 (error "There is already a breakpoint here!")
1059 (setq o
(make-overlay pos
(+ pos
1)))
1060 (overlay-put o
'evaporate t
)
1061 (overlay-put o
'face gds-breakpoint-face
)
1062 (overlay-put o
'gds-breakpoint-info
0)
1063 (overlay-put o
'before-string gds-new-breakpoint-before-string
)
1064 (overlay-put o
'after-string gds-new-breakpoint-after-string
))))
1066 (defun gds-delete-source-breakpoint ()
1068 (let* ((pos (gds-source-breakpoint-pos))
1069 (o (gds-source-breakpoint-overlay-at pos
)))
1071 (error "There is no breakpoint here to delete!"))
1072 (delete-overlay o
)))
1074 (defun gds-region-breakpoint-info (beg end
)
1075 "Return an alist of breakpoints in REGION.
1076 The car of each alist element is a cons (LINE . COLUMN) giving the
1077 source location of the breakpoint. The cdr is information describing
1078 breakpoint properties. Currently `information' is just the breakpoint
1079 index, for an existing Guile breakpoint, or 0 for a breakpoint that
1080 isn't yet known to Guile."
1082 (let ((os (overlays-in beg end
))
1087 (if (overlay-get o
'gds-breakpoint-info
)
1090 (cons (cons (save-excursion
1091 (goto-char (overlay-start o
))
1092 (cons (save-excursion
1094 (count-lines (point-min) (point)))
1096 (overlay-get o
'gds-breakpoint-info
))
1098 ;; Also now mark the breakpoint as `new'. It will become
1099 ;; `active' (again) when we receive a notification from
1100 ;; Guile that the breakpoint has been set.
1101 (overlay-put o
'gds-breakpoint-info
0)
1102 (overlay-put o
'before-string gds-new-breakpoint-before-string
)
1103 (overlay-put o
'after-string gds-new-breakpoint-after-string
))))
1107 ;;;; Evaluating code.
1109 ;; The following commands send code for evaluation through the GDS TCP
1110 ;; connection, receive the result and any output generated through the
1111 ;; same connection, and display the result and output to the user.
1113 ;; For each buffer where evaluations can be requested, GDS uses the
1114 ;; buffer-local variable `gds-client' to track which GDS client
1115 ;; program should receive and handle that buffer's evaluations. In
1116 ;; the common case where GDS is only managing one client program, a
1117 ;; buffer's value of `gds-client' is set automatically to point to
1118 ;; that program the first time that an evaluation (or help or
1119 ;; completion) is requested. If there are multiple GDS clients
1120 ;; running at that time, GDS asks the user which one is intended.
1122 (defun gds-read-client ()
1123 (let* ((def (and gds-client
(cdr (assq gds-client gds-names
))))
1125 (concat "Application for eval (default "
1128 "Application for eval: "))
1130 (completing-read prompt
1131 (mapcar (function list
)
1132 (mapcar (function cdr
) gds-names
))
1135 (let (client (names gds-names
))
1136 (while (and names
(not client
))
1137 (if (string-equal (cdar names
) name
)
1138 (setq client
(caar names
)))
1139 (setq names
(cdr names
)))
1142 (defun gds-choose-client (client)
1143 ;; Only keep the supplied client number if it is still valid.
1144 (if (integerp client
)
1145 (setq client
(gds-client-ref 'gds-client client
)))
1146 ;; Only keep the current buffer's setting of `gds-client' if it is
1149 (setq gds-client
(gds-client-ref 'gds-client
)))
1151 (or ;; If client is an integer, it is the port number of the
1153 (if (integerp client
)
1155 ;; Any other non-nil value indicates invocation with a prefix
1156 ;; arg, which forces asking the user which application is
1159 (setq gds-client
(gds-read-client)))
1160 ;; If ask not forced, and current buffer is associated with a
1161 ;; client, use that client.
1163 ;; If there are no clients at this point, and we are
1164 ;; allowed to autostart a captive Guile, do so.
1165 (and (null gds-buffers
)
1166 gds-autostart-captive
1168 (gds-start-captive t
)
1169 (while (null gds-buffers
)
1170 (accept-process-output (get-buffer-process gds-captive
)
1172 (setq gds-client
(caar gds-buffers
))))
1173 ;; If there is only one known client, use that one.
1174 (if (and (car gds-buffers
)
1175 (null (cdr gds-buffers
)))
1176 (setq gds-client
(caar gds-buffers
)))
1177 ;; Last resort - ask the user.
1178 (setq gds-client
(gds-read-client))
1180 (error "No application chosen.")))
1182 (defun gds-module-name (start end
)
1183 "Determine and return the name of the module that governs the
1184 specified region. The module name is returned as a list of symbols."
1185 (interactive "r") ; why not?
1189 (while (and (not module-name
)
1190 (beginning-of-defun-raw 1))
1191 (if (looking-at "(define-module ")
1194 (goto-char (match-end 0))
1195 (read (current-buffer))))))
1198 (defun gds-port-name (start end
)
1199 "Return port name for the specified region of the current buffer.
1200 The name will be used by Guile as the port name when evaluating that
1202 (or (buffer-file-name)
1203 (concat "Emacs buffer: " (buffer-name))))
1205 (defun gds-eval-region (start end
&optional client
)
1206 "Evaluate the current region."
1207 (interactive "r\nP")
1208 (setq client
(gds-choose-client client
))
1209 (let ((module (gds-module-name start end
))
1210 (port-name (gds-port-name start end
))
1214 (setq column
(current-column)) ; 0-based
1216 (setq line
(count-lines (point-min) (point)))) ; 0-based
1217 (let ((code (buffer-substring-no-properties start end
)))
1218 (gds-send (format "eval (region . %S) %s %S %d %d %s %S"
1219 (gds-abbreviated code
)
1220 (if module
(prin1-to-string module
) "#f")
1221 port-name line column
1222 (let ((bpinfo (gds-region-breakpoint-info start end
)))
1223 ;; Make sure that "no bpinfo" is represented
1224 ;; as "()", not "nil", as Scheme doesn't
1225 ;; understand "nil".
1226 (if bpinfo
(format "%S" bpinfo
) "()"))
1230 (defun gds-eval-expression (expr &optional client correlator
)
1231 "Evaluate the supplied EXPR (a string)."
1232 (interactive "sEvaluate expression: \nP")
1233 (setq client
(gds-choose-client client
))
1234 (set-text-properties 0 (length expr
) nil expr
)
1235 (gds-send (format "eval (%S . %S) #f \"Emacs expression\" 0 0 () %S"
1236 (or correlator
'expression
)
1237 (gds-abbreviated expr
)
1241 (defconst gds-abbreviated-length
35)
1243 (defun gds-abbreviated (code)
1244 (let ((nlpos (string-match (regexp-quote "\n") code
)))
1247 (if (= nlpos
(- (length code
) 1))
1248 (substring code
0 nlpos
)
1249 (concat (substring code
0 nlpos
)
1251 (substring code
(+ nlpos
1)))))
1252 (setq nlpos
(string-match (regexp-quote "\n") code
))))
1253 (if (> (length code
) gds-abbreviated-length
)
1254 (concat (substring code
0 (- gds-abbreviated-length
3)) "...")
1257 (defun gds-eval-defun (&optional client
)
1258 "Evaluate the defun (top-level form) at point."
1262 (let ((end (point)))
1263 (beginning-of-defun)
1264 (gds-eval-region (point) end client
))))
1266 (defun gds-eval-last-sexp (&optional client
)
1267 "Evaluate the sexp before point."
1269 (gds-eval-region (save-excursion (backward-sexp) (point)) (point) client
))
1274 ;; Help is implemented as a special case of evaluation, identified by
1275 ;; the evaluation correlator 'help.
1277 (defun gds-help-symbol (sym &optional client
)
1278 "Get help for SYM (a Scheme symbol)."
1280 (let ((sym (thing-at-point 'symbol
))
1281 (enable-recursive-minibuffers t
)
1283 (setq val
(read-from-minibuffer
1285 (format "Describe Guile symbol (default %s): " sym
)
1286 "Describe Guile symbol: ")))
1287 (list (if (zerop (length val
)) sym val
)
1288 current-prefix-arg
)))
1289 (gds-eval-expression (format "(help %s)" sym
) client
'help
))
1291 (defun gds-apropos (regex &optional client
)
1292 "List Guile symbols matching REGEX."
1294 (let ((sym (thing-at-point 'symbol
))
1295 (enable-recursive-minibuffers t
)
1297 (setq val
(read-from-minibuffer
1299 (format "Guile apropos (regexp, default \"%s\"): " sym
)
1300 "Guile apropos (regexp): ")))
1301 (list (if (zerop (length val
)) sym val
)
1302 current-prefix-arg
)))
1303 (set-text-properties 0 (length regex
) nil regex
)
1304 (gds-eval-expression (format "(apropos %S)" regex
) client
'help
))
1306 (defvar gds-completion-results nil
)
1308 (defun gds-complete-symbol (&optional client
)
1309 "Complete the Guile symbol before point. Returns `t' if anything
1310 interesting happened, `nil' if not."
1312 (let* ((chars (- (point) (save-excursion
1313 (while (let ((syntax (char-syntax (char-before (point)))))
1314 (or (eq syntax ?w
) (eq syntax ?_
)))
1319 (setq client
(gds-choose-client client
))
1320 (setq gds-completion-results nil
)
1321 (gds-send (format "complete %s"
1323 (buffer-substring-no-properties (- (point) chars
)
1326 (while (null gds-completion-results
)
1327 (accept-process-output gds-process
0 200))
1328 (cond ((eq gds-completion-results t
)
1330 ((stringp gds-completion-results
)
1331 (if (<= (length gds-completion-results
) chars
)
1333 (insert (substring gds-completion-results chars
))
1334 (message "Sole completion")
1336 ((= (length gds-completion-results
) 1)
1337 (if (<= (length (car gds-completion-results
)) chars
)
1339 (insert (substring (car gds-completion-results
) chars
))
1342 (with-output-to-temp-buffer "*Completions*"
1343 (display-completion-list gds-completion-results
))
1347 ;;;; Display of evaluation and help results.
1349 (defun gds-display-results (client correlator results
)
1350 (let ((helpp (eq (car correlator
) 'help
)))
1351 (let ((buf (get-buffer-create (if helpp
1353 "*Guile Results*"))))
1359 (insert (cdr correlator
) "\n\n")
1361 (insert (car results
))
1362 (or (bolp) (insert "\\\n"))
1366 (mapcar (function (lambda (value)
1367 (insert " => " value
"\n")))
1369 (insert " => no (or unspecified) value\n"))
1371 (setq results
(cddr results
)))
1372 (goto-char (point-min))
1373 (if (and helpp
(looking-at "Evaluating in "))
1374 (delete-region (point) (progn (forward-line 1) (point))))
1375 (cons correlator
(buffer-string))))
1376 ;;(pop-to-buffer buf)
1377 ;;(run-hooks 'temp-buffer-show-hook)
1380 (gds-promote-view 'interaction
)
1381 (gds-request-focus client
))
1384 ;;;; Loading (evaluating) a whole Scheme file.
1386 (defcustom gds-source-modes
'(scheme-mode)
1387 "*Used to determine if a buffer contains Scheme source code.
1388 If it's loaded into a buffer that is in one of these major modes, it's
1389 considered a scheme source file by `gds-load-file'."
1390 :type
'(repeat function
)
1393 (defvar gds-prev-load-dir
/file nil
1394 "Holds the last (directory . file) pair passed to `gds-load-file'.
1395 Used for determining the default for the next `gds-load-file'.")
1397 (defun gds-load-file (file-name &optional client
)
1398 "Load a Scheme file into the inferior Scheme process."
1399 (interactive (list (car (comint-get-source "Load Scheme file: "
1400 gds-prev-load-dir
/file
1401 gds-source-modes t
))
1402 ; T because LOAD needs an
1404 current-prefix-arg
))
1405 (comint-check-source file-name
) ; Check to see if buffer needs saved.
1406 (setq gds-prev-load-dir
/file
(cons (file-name-directory file-name
)
1407 (file-name-nondirectory file-name
)))
1408 (setq client
(gds-choose-client client
))
1409 (gds-send (format "load %S" file-name
) client
))
1412 ;;;; Scheme mode keymap items.
1414 (define-key scheme-mode-map
"\M-\C-x" 'gds-eval-defun
);gnu convention
1415 (define-key scheme-mode-map
"\C-x\C-e" 'gds-eval-last-sexp
);gnu convention
1416 (define-key scheme-mode-map
"\C-c\C-e" 'gds-eval-expression
)
1417 (define-key scheme-mode-map
"\C-c\C-r" 'gds-eval-region
)
1418 (define-key scheme-mode-map
"\C-c\C-l" 'gds-load-file
)
1419 (define-key scheme-mode-map
"\C-hg" 'gds-help-symbol
)
1420 (define-key scheme-mode-map
"\C-h\C-g" 'gds-apropos
)
1421 (define-key scheme-mode-map
"\e\t" 'gds-complete-symbol
)
1422 (define-key scheme-mode-map
"\C-x " 'gds-set-source-breakpoint
)
1423 (define-key scheme-mode-map
"\C-x\e " 'gds-delete-source-breakpoint
)
1426 ;;;; Guile Interaction mode keymap and menu items.
1428 (define-key gds-mode-map
"M" (function gds-query-modules
))
1430 (define-key gds-mode-map
"g" (function gds-go
))
1431 (define-key gds-mode-map
"q" (function gds-quit
))
1432 (define-key gds-mode-map
" " (function gds-next
))
1433 (define-key gds-mode-map
"e" (function gds-evaluate
))
1434 (define-key gds-mode-map
"i" (function gds-step-in
))
1435 (define-key gds-mode-map
"o" (function gds-step-out
))
1436 (define-key gds-mode-map
"t" (function gds-trace-finish
))
1437 (define-key gds-mode-map
"I" (function gds-frame-info
))
1438 (define-key gds-mode-map
"A" (function gds-frame-args
))
1439 (define-key gds-mode-map
"H" (function gds-debug-trap-hooks
))
1440 (define-key gds-mode-map
"u" (function gds-up
))
1441 (define-key gds-mode-map
"d" (function gds-down
))
1442 (define-key gds-mode-map
"b" (function gds-set-breakpoint
))
1444 (define-key gds-mode-map
"vi" (function gds-view-interaction
))
1445 (define-key gds-mode-map
"vs" (function gds-view-stack
))
1446 (define-key gds-mode-map
"vb" (function gds-view-breakpoints
))
1447 (define-key gds-mode-map
"vB" (function gds-view-browser
))
1448 (define-key gds-mode-map
"vm" (function gds-view-messages
))
1450 (defvar gds-view-menu nil
1454 (setq gds-view-menu
(make-sparse-keymap "View"))
1455 (define-key gds-view-menu
[messages]
1456 '(menu-item "Messages" gds-view-messages
1457 :enable (memq 'messages gds-views)))
1458 (define-key gds-view-menu [browser]
1459 '(menu-item "Browser" gds-view-browser
1460 :enable (memq 'browser gds-views)))
1461 (define-key gds-view-menu [breakpoints]
1462 '(menu-item "Breakpoints" gds-view-breakpoints
1463 :enable (memq 'breakpoints gds-views)))
1464 (define-key gds-view-menu [stack]
1465 '(menu-item "Stack" gds-view-stack
1466 :enable (memq 'stack gds-views)))
1467 (define-key gds-view-menu [interaction]
1468 '(menu-item "Interaction" gds-view-interaction
1469 :enable (memq 'interaction gds-views))))
1471 (defvar gds-debug-menu nil
1472 "GDS debugging menu.")
1475 (setq gds-debug-menu (make-sparse-keymap "Debug"))
1476 (define-key gds-debug-menu [go]
1477 '(menu-item "Go" gds-go))
1478 (define-key gds-debug-menu [down]
1479 '(menu-item "Move Down 1 Frame" gds-down))
1480 (define-key gds-debug-menu [up]
1481 '(menu-item "Move Up 1 Frame" gds-up))
1482 (define-key gds-debug-menu [trace-finish]
1483 '(menu-item "Trace This Frame" gds-trace-finish))
1484 (define-key gds-debug-menu [step-out]
1485 '(menu-item "Finish This Frame" gds-step-out))
1486 (define-key gds-debug-menu [next]
1487 '(menu-item "Next" gds-next))
1488 (define-key gds-debug-menu [step-in]
1489 '(menu-item "Single Step" gds-step-in))
1490 (define-key gds-debug-menu [eval]
1491 '(menu-item "Eval In This Frame..." gds-evaluate)))
1493 (defvar gds-breakpoint-menu nil
1494 "GDS breakpoint menu.")
1495 (if gds-breakpoint-menu
1497 (setq gds-breakpoint-menu (make-sparse-keymap "Breakpoint"))
1498 (define-key gds-breakpoint-menu [last-sexp]
1499 '(menu-item "Delete Breakpoint" gds-delete-source-breakpoint))
1500 (define-key gds-breakpoint-menu [set]
1501 '(menu-item "Set Breakpoint" gds-set-source-breakpoint)))
1503 (defvar gds-eval-menu nil
1504 "GDS evaluation menu.")
1507 (setq gds-eval-menu (make-sparse-keymap "Evaluate"))
1508 (define-key gds-eval-menu [load-file]
1509 '(menu-item "Load Scheme File" gds-load-file))
1510 (define-key gds-eval-menu [defun]
1511 '(menu-item "Defun At Point" gds-eval-defun))
1512 (define-key gds-eval-menu [region]
1513 '(menu-item "Region" gds-eval-region))
1514 (define-key gds-eval-menu [last-sexp]
1515 '(menu-item "Sexp Before Point" gds-eval-last-sexp))
1516 (define-key gds-eval-menu [expr]
1517 '(menu-item "Expression..." gds-eval-expression)))
1519 (defvar gds-help-menu nil
1523 (setq gds-help-menu (make-sparse-keymap "Help"))
1524 (define-key gds-help-menu [apropos]
1525 '(menu-item "Apropos..." gds-apropos))
1526 (define-key gds-help-menu [sym]
1527 '(menu-item "Symbol..." gds-help-symbol)))
1529 (defvar gds-advanced-menu nil
1530 "Menu of rarely needed GDS operations.")
1531 (if gds-advanced-menu
1533 (setq gds-advanced-menu (make-sparse-keymap "Advanced"))
1534 (define-key gds-advanced-menu [run-captive]
1535 '(menu-item "Run Captive Guile" gds-start-captive
1536 :enable (not (comint-check-proc gds-captive))))
1537 (define-key gds-advanced-menu [restart-gds]
1538 '(menu-item "Restart IDE" gds-start :enable gds-process))
1539 (define-key gds-advanced-menu [kill-gds]
1540 '(menu-item "Shutdown IDE" gds-shutdown :enable gds-process))
1541 (define-key gds-advanced-menu [start-gds]
1542 '(menu-item "Start IDE" gds-start :enable (not gds-process))))
1544 (defvar gds-menu nil
1545 "Global menu for GDS commands.")
1548 (setq gds-menu (make-sparse-keymap "Guile"))
1549 (define-key gds-menu [advanced]
1550 (cons "Advanced" gds-advanced-menu))
1551 (define-key gds-menu [separator-1]
1553 (define-key gds-menu [view]
1554 `(menu-item "View" ,gds-view-menu :enable gds-views))
1555 (define-key gds-menu [debug]
1556 `(menu-item "Debug" ,gds-debug-menu :enable (and gds-client
1557 (gds-client-blocked))))
1558 (define-key gds-menu [breakpoint]
1559 `(menu-item "Breakpoints" ,gds-breakpoint-menu :enable t))
1560 (define-key gds-menu [eval]
1561 `(menu-item "Evaluate" ,gds-eval-menu :enable (or gds-buffers
1562 gds-autostart-captive)))
1563 (define-key gds-menu [help]
1564 `(menu-item "Help" ,gds-help-menu :enable (or gds-buffers
1565 gds-autostart-captive)))
1566 (setq menu-bar-final-items
1567 (cons 'guile menu-bar-final-items))
1568 (define-key scheme-mode-map [menu-bar guile]
1569 (cons "Guile" gds-menu)))
1572 ;;;; Autostarting the GDS server.
1574 (defcustom gds-autostart-server t
1575 "Whether to automatically start the GDS server when `gds.el' is loaded."
1580 ;;;; `Captive' Guile - a Guile process that is started when needed to
1581 ;;;; provide help, completion, evaluations etc.
1583 (defcustom gds-autostart-captive t
1584 "Whether to automatically start a `captive' Guile process when needed."
1588 (defvar gds-captive nil
1589 "Buffer of captive Guile.")
1591 (defun gds-start-captive (&optional restart)
1594 (comint-check-proc gds-captive))
1596 (if (comint-check-proc gds-captive)
1598 (let ((process-connection-type nil))
1599 (setq gds-captive (make-comint "captive-guile"
1603 (let ((proc (get-buffer-process gds-captive)))
1604 (process-kill-without-query proc)
1605 (comint-send-string proc "(set! %load-path (cons \"/home/neil/Guile/cvs/guile-core\" %load-path))\n")
1606 (comint-send-string proc "(debug-enable 'backtrace)\n")
1607 (comint-send-string proc "(use-modules (emacs gds-client))\n")
1608 (comint-send-string proc "(gds-connect \"Captive Guile\" #f)\n"))))
1610 (defun gds-kill-captive ()
1614 (kill-process (get-buffer-process gds-captive))
1615 (accept-process-output gds-process 0 200))
1619 ;;;; If requested, autostart the server after loading.
1621 (if (and gds-autostart-server
1630 ;;; gds.el ends here.