home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnusmalltalk / bison.el < prev    next >
Lisp/Scheme  |  1991-11-09  |  3KB  |  88 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;
  3. ;;; Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.
  4. ;;; Written by Steve Byrne.
  5. ;;; 
  6. ;;; This file is part of GNU Smalltalk.
  7. ;;;  
  8. ;;; GNU Smalltalk is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by the Free
  10. ;;; Software Foundation; either version 1, or (at your option) any later 
  11. ;;; version.
  12. ;;;
  13. ;;; GNU Smalltalk is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. ;;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. ;;; for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License along
  19. ;;; with GNU Smalltalk; see the file COPYING.  If not, write to the Free
  20. ;;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21. ;;;
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23.  
  24. (autoload 'my-compile "my-c-mode")
  25.  
  26. (defvar bison-mode-syntax-table nil
  27.   "Syntax table used while in text mode.")
  28.  
  29. (if bison-mode-syntax-table
  30.     ()
  31.   (setq bison-mode-syntax-table (copy-syntax-table text-mode-syntax-table))
  32.   (modify-syntax-entry ?\" ".   " bison-mode-syntax-table)
  33.   (modify-syntax-entry ?\\ ".   " bison-mode-syntax-table)
  34.   (modify-syntax-entry ?' "w   " bison-mode-syntax-table))
  35.  
  36. (defvar bison-mode-map nil "")
  37. (if bison-mode-map
  38.     ()
  39.   (setq bison-mode-map (make-sparse-keymap))
  40.   (define-key bison-mode-map "\t" 'tab-to-tab-stop)
  41.   (define-key bison-mode-map "\e." 'find-nonterminal)
  42.   (define-key bison-mode-map "\C-xg" 'goto-state)
  43.   (define-key bison-mode-map "\C-cm" 'my-compile)
  44.   )
  45.  
  46.  
  47.  
  48. (defun bison-mode ()
  49.   "Major mode for editing Bison code intended for humans to read.\\{bison-mode-map}
  50. Turning on bison-mode calls the value of the variable bison-mode-hook,
  51. if that value is non-nil."
  52.   (interactive)
  53.   (kill-all-local-variables)
  54.   (use-local-map bison-mode-map)
  55.   (setq mode-name "Bison")
  56.   (setq major-mode 'Bison-mode)
  57.   (setq local-abbrev-table text-mode-abbrev-table)
  58.   (set-syntax-table bison-mode-syntax-table)
  59.   (run-hooks 'bison-mode-hook))
  60.  
  61. (defun goto-state (n)
  62.   (interactive "NState: ")
  63.   (goto-char (point-min))
  64.   (re-search-forward (concat "^state " (int-to-string n) "\n\n"))
  65.   (forward-line -2)
  66.   (recenter 0)
  67.   )
  68.  
  69. (defun find-nonterminal ()
  70.   (interactive)
  71.   (let (word)
  72.     (setq word (select-current-word))
  73.     (goto-char (point-min))
  74.     (re-search-forward (concat "^[ \t]*" word "[ \t]*:"))
  75.     (recenter 0)
  76.     ))
  77.  
  78. (defun select-current-word ()
  79.   "Returns a string that's the entire word that the point is in."
  80.   (let (start end)
  81.     (if (= (char-syntax (char-after (point))) ?w)
  82.     (forward-sexp))
  83.     (setq end (point))
  84.     (backward-sexp)
  85.     (setq start (point))
  86.     (buffer-substring start end))
  87.   )
  88.