home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / emacs / sources / 551 < prev    next >
Encoding:
Text File  |  1992-07-25  |  4.1 KB  |  125 lines

  1. Newsgroups: gnu.emacs.sources
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!traffic.den.mmc.com!kevin
  3. From: kevin@traffic.den.mmc.com (Kevin Rodgers)
  4. Subject: gdb-completion.el
  5. Message-ID: <9207242119.AA26868@traffic>
  6. Sender: daemon@cis.ohio-state.edu
  7. Reply-To: kevin@traffic.den.mmc.com
  8. Organization: Source only  Discussion and requests in gnu.emacs.help.
  9. Distribution: gnu
  10. Date: Fri, 24 Jul 1992 21:19:54 GMT
  11. Lines: 112
  12.  
  13.  
  14. After posting gdb-completion.el yesterday, I've made some fixes to
  15. gdb-filter:
  16.  
  17. 1. (set-buffer (process-buffer PROC)) before modifying the current
  18.    buffer :-), and restore the current buffer on exit.
  19.  
  20. 2. Correctly delete all unprintable characters (not just ^M and \a),
  21.    emulate \f as well as \a, and restore point to the end of the buffer.
  22.  
  23. 3. Make use of the process marker.
  24.  
  25. 4. Add comments and a documentation string.
  26.  
  27. So here's the new and improved version:
  28.  
  29. ;;;; gdb-completion.el
  30.  
  31. ;;;; Enable TAB, TAB-TAB, and ESC-? Gdb command completion.
  32.  
  33. ;;; Notes:
  34.  
  35. ;; 1. This depends upon comint-gdb.el by Mike Williams
  36. ;;    <mike-w@cs.aukuni.ac.nz>, which in turn depends upon comint.el by
  37. ;;    Olin Shivers <Olin.Shivers@cs.cmu.edu>.  Both of these are
  38. ;;    available via anonymous ftp from
  39. ;;    cs.cmu.edu:/afs/cs.cmu.edu/user/shivers/lib/emacs/.
  40.  
  41. ;; 2. To use gdb-completion, add these to your ~/.emacs file:
  42. ;;    (autoload (function gdb) "comint-gdb"
  43. ;;          "Major mode for interacting with an inferior Gdb process..." t)
  44. ;;    (setq gdb-load-hook
  45. ;;          (function (lambda ()
  46. ;;              (require 'gdb-completion))))
  47.  
  48. ;;; Bugs:
  49.  
  50. ;; 1. After a single TAB has been sent to the inferior Gdb process, the
  51. ;;    process may ring the bell by writing \a (i.e. C-g) on its standard
  52. ;;    error.  However, process filters only read from the standard
  53. ;;    output, so gdb-filter never detects the \a.
  54.  
  55. ;; 2. After two TABs or ESC ? have been sent to the inferior Gdb
  56. ;;    process, the process filter reads the completions, but doesn't see
  57. ;;    the echoed incomplete command line which should follow as a
  58. ;;    prompt.  I don't know why this is, since it doesn't seem to be
  59. ;;    written on the standard error.
  60.  
  61.  
  62. ;;; Gdb completion commands:
  63.  
  64. (defun gdb-complete ()
  65.   "*Complete Gdb command if unique, or display all possible completions
  66. when typed twice in a row."
  67.   (interactive)
  68.   (gdb-send-incomplete "\t"))
  69.  
  70. (defun gdb-display-completions ()
  71.   "*Display all possible Gdb command completions."
  72.   (interactive)
  73.   (gdb-send-incomplete "\e?"))
  74.  
  75. (defun gdb-send-incomplete (completion)
  76.   "Send input to inferior Gdb process, with COMPLETION string appended
  77. instead of newline."
  78.   (let ((comint-input-sender (function
  79.                   (lambda (proc string)
  80.                 ;; delete newline from buffer:
  81.                 (backward-delete-char 1)
  82.                 ;; send input to Gdb:
  83.                 (comint-send-string proc string)
  84.                 (comint-send-string proc completion)))))
  85.     (comint-send-input)))
  86.  
  87.  
  88. ;;; Bind the Gdb completion commands:
  89.  
  90. (define-key gdb-mode-map "\t" (function gdb-complete))
  91. (define-key gdb-mode-map "\M-?" (function gdb-display-completions))
  92.  
  93.  
  94. ;;; Modify the process output filter:
  95.  
  96. (fset 'comint-gdb-filter (symbol-function 'gdb-filter))
  97.  
  98. (defun gdb-filter (proc string)
  99.   "Call comint-gdb-filter with PROC and STRING, then delete the unprintable
  100. characters that were inserted into the process buffer."
  101.   (let ((buffer (current-buffer))
  102.     (match-data (match-data)))
  103.     (unwind-protect ; restore buffer and match data
  104.     (let ((position (marker-position (process-mark proc))))
  105.       (funcall (function comint-gdb-filter) proc string)
  106.       (set-buffer (process-buffer proc))
  107.       (goto-char position)
  108.       (while (and (re-search-forward "[^\t\n -~]" (point-max) t)
  109.               (let ((unprintable-char (char-after (match-beginning 0))))
  110.             ;; primitive terminal emulation:
  111.             (cond ((char-equal unprintable-char ?\a) (beep t))
  112.                   ((char-equal unprintable-char ?\f) (recenter 0)))
  113.             ;; always true:
  114.             t))
  115.         (replace-match ""))
  116.       ;; restore point:
  117.       (goto-char (point-max)))
  118.       (set-buffer buffer)
  119.       (store-match-data match-data))))
  120.  
  121.  
  122. ;;; Advertise the provided feature:
  123.  
  124. (provide 'gdb-completion)
  125.