home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gofer230.zip / Progs / Gofer / gofer.el < prev    next >
Lisp/Scheme  |  1994-06-23  |  4KB  |  135 lines

  1. ;;; Gofer mode for GNU Emacs
  2. ;;;
  3. ;;; Last update: 6/12/91
  4. ;;;
  5. ;;; Author: Stuart Clayman,
  6. ;;;        Dept. Computer Science,
  7. ;;;        University College London
  8. ;;;
  9. ;;; Email: sclayman@uk.ac.ucl.cs
  10. ;;;
  11. ;;; Use:
  12. ;;; In .emacs put
  13. ;;;
  14. ;;;   (autoload 'gofer-mode "gofer" "Go into gofer mode" t)
  15. ;;;   (autoload 'run-gofer "gofer" "Run gofer as inferior process" t)
  16. ;;;   (autoload 'gofer-project "gofer" "Go into a gofer project" t)
  17. ;;;
  18. ;;;   (set-variable 'auto-mode-alist
  19. ;;;        (append '(
  20. ;;;           ("\\.gs$" . gofer-mode)   ;; gofer source
  21. ;;;        ("\\.gp$" . gofer-project) ;; gofer project files
  22. ;;;        ) auto-mode-alist))
  23. ;;;
  24. ;;;  All gofer source files should end in .gs
  25. ;;;  All gofer project files should end in .gp
  26. ;;;
  27. ;;;  In gofer source files
  28. ;;;    ESC \C-x
  29. ;;;    \C-c \C-c
  30. ;;;    \C-c l        loads the current file
  31. ;;;
  32. ;;;    \C-u ESC \C-x
  33. ;;;    \C-u \C-c \C-c
  34. ;;;    \C-u \C-c l    loads the current file and does a cd first
  35. ;;;
  36. ;;;    \C-c a        adds the current file
  37. ;;;    \C-u \C-c a    adds the current file and does a cd first
  38. ;;;    \C-c r        reloads the current file
  39. ;;;
  40. ;;;
  41. ;;;  In gofer project files
  42. ;;;    ESC \C-x
  43. ;;;    \C-c \C-c
  44. ;;;    \C-c p        loads the project file
  45. ;;;    \C-u ESC \C-x
  46. ;;;    \C-u \C-c \C-c
  47. ;;;    \C-u \C-c p    loads the project file and does a cd first
  48. ;;;
  49. ;;;  The duplication of ESC \C-x, \C-c \C-c, and \C-c l is for
  50. ;;;  historical reasons.
  51.  
  52. (require 'shell)
  53.  
  54. (defvar gofer-mode-hook nil "Gofer mode hook")
  55.  
  56. (defun run-gofer()
  57.   "Run an inferior Gofer process."
  58.   (interactive)
  59.   (switch-to-buffer (make-shell "gofer" "gofer"))
  60.   (make-variable-buffer-local 'shell-cd-pattern)
  61.   (make-variable-buffer-local 'shell-prompt-pattern)
  62.   (setq shell-cd-pattern ":cd")
  63.   (setq shell-prompt-pattern "^[? ]*? \\|^"))
  64.  
  65. (defun save-buffer-and-go-outline(which arg)
  66.   "Save current Gofer file buffer.
  67. Goto inferior Gofer buffer and load file.
  68. WHICH operation is required.
  69. With ARG for additional operation"
  70.   (save-buffer)
  71.   (if (or (null (get-buffer "*gofer*")) (null (process-status "gofer")))  ; if gofer not running
  72.       (save-excursion (run-gofer)))    ; run gofer
  73.  
  74.   (if (equal which "r")            ; reload a file
  75.       (progn
  76.     (send-string "gofer" (concat ":reload" "\n")))
  77.     (if (equal which "l")        ; load a file
  78.     (progn
  79.       (if arg
  80.           (send-string "gofer" (concat ":cd " default-directory "\n")))
  81.       (send-string "gofer" (concat ":l " (buffer-name) "\n")))
  82.       (if (equal which "a")        ; add a file
  83.       (progn
  84.         (if arg
  85.         (send-string "gofer" (concat ":cd " default-directory "\n")))
  86.           (send-string "gofer" (concat ":a " (buffer-name) "\n")))
  87.     (if (equal which "p")        ; a project file
  88.         (progn
  89.           (if arg
  90.           (send-string "gofer" (concat ":cd " default-directory "\n")))
  91.           (send-string "gofer" (concat ":p " (buffer-name) "\n")))
  92.     (message "Bad programming in gofer.el")))))
  93.  
  94.   (switch-to-buffer-other-window "*gofer*"))
  95.  
  96. (defun save-gofer-buffer-and-load(arg)
  97.   "Save a gofer source file and load it"
  98.   (interactive "P")
  99.   (save-buffer-and-go-outline "l" arg))
  100.  
  101. (defun save-gofer-buffer-and-add(arg)
  102.   "Save a gofer source file and add it to the file list"
  103.   (interactive "P")
  104.   (save-buffer-and-go-outline "a" arg))
  105.  
  106. (defun save-gofer-buffer-and-reload(arg)
  107.   "Save a gofer source file and reload it"
  108.   (interactive "P")
  109.   (save-buffer-and-go-outline "r" arg))
  110.  
  111. (defun save-gofer-project-buffer-and-go(arg)
  112.   "Save a gofer project file and run"
  113.   (interactive "P")
  114.   (save-buffer-and-go-outline "p" arg))
  115.  
  116. (defun gofer-mode()
  117.   "Gofer mode."
  118.   (interactive)
  119.   (setq mode-name "Gofer")
  120.   (make-variable-buffer-local 'indent-line-function)
  121.   (setq indent-line-function 'indent-relative)
  122.   (run-hooks 'gofer-mode-hook)
  123.   (local-set-key "\e\C-x" 'save-gofer-buffer-and-load)
  124.   (local-set-key "\C-c\C-c" 'save-gofer-buffer-and-load)
  125.   (local-set-key "\C-cl" 'save-gofer-buffer-and-load)
  126.   (local-set-key "\C-cr" 'save-gofer-buffer-and-reload)
  127.   (local-set-key "\C-ca" 'save-gofer-buffer-and-add)
  128.   (local-set-key "\eg" 'goto-line))
  129.  
  130. (defun gofer-project()
  131.   "For Gofer project files"
  132.   (local-set-key "\e\C-x" 'save-gofer-project-buffer-and-go)
  133.   (local-set-key "\C-c\C-c" 'save-gofer-project-buffer-and-go)
  134.   (local-set-key "\C-cp" 'save-gofer-project-buffer-and-go))
  135.