home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / may94 / util / edit / jade.lha / Jade / lisp / lisp-mode.jl < prev    next >
Lisp/Scheme  |  1994-04-16  |  3KB  |  104 lines

  1. ;;;; lisp-mode.jl -- Simple mode for editing Lisp files
  2. ;;;  Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. ;;; This file is part of Jade.
  5.  
  6. ;;; Jade is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;; any later version.
  10.  
  11. ;;; Jade is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;;; GNU General Public License for more details.
  15.  
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Jade; see the file COPYING.  If not, write to
  18. ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. (provide 'lisp-mode)
  21.  
  22. (defvar lisp-mode-tab 3)
  23. (defvar lisp-mode-auto-indent nil)
  24.  
  25. (setq symbol-word-regexps ["[^][()?'\"#; ]" "[][()?'\"#; ]|$"]) 
  26.  
  27. (setq
  28.   lisp-mode-keymap (make-keylist)
  29.   lisp-mode-esc-keymap (make-keylist))
  30. (bind-keys lisp-mode-keymap
  31.   "return" 'lisp-return
  32.   "shift-return" 'split-line
  33.   "ctrl-return" 'eval-insert-paragraph
  34.   "tab" 'lisp-tab
  35.   "meta-tab" 'goto-next-tab
  36.   "esc" '(setq next-keymap-path '(lisp-mode-esc-keymap esc-keymap)))
  37. (bind-keys lisp-mode-esc-keymap
  38.   "ctrl-x" 'eval-print-paragraph)
  39.  
  40. (defun lisp-mode ()
  41.   (eval-hook 'lisp-mode-hook)
  42.   (setq
  43.     mode-name "lisp-mode"
  44.     keymap-path (cons lisp-mode-keymap keymap-path)
  45.     major-mode-kill 'lisp-mode-kill
  46.     screen-tab lisp-mode-tab))
  47.  
  48. (defun lisp-mode-kill ()
  49.   (setq
  50.     keymap-path (delq lisp-mode-keymap keymap-path)
  51.     mode-name nil))
  52.  
  53. (defun eval-paragraph ()
  54.   (goto (prev-paragraph))
  55.   (eval (read (current-buffer))))
  56.  
  57. (defun eval-insert-paragraph ()
  58.   (format (current-buffer) "\n%S\n\n" (eval-paragraph)))
  59.  
  60. (defun eval-print-paragraph ()
  61.   (prin1 (eval-paragraph) t))
  62.  
  63. (defun lisp-return ()
  64.   (split-line)
  65.   (when lisp-mode-auto-indent
  66.     (if (empty-line-p)
  67.     (goto (lisp-indent-pos-empty))
  68.       (set-indent-pos (lisp-indent-pos)))))
  69.  
  70. (defun lisp-tab ()
  71.   (if (empty-line-p)
  72.       (goto (lisp-indent-pos-empty (cursor-pos)))
  73.     (setq tmp (set-indent-pos (lisp-indent-pos (cursor-pos))))
  74.     (cond
  75.       ((> tmp (cursor-pos))
  76.     (goto tmp))
  77.       ((> (cursor-pos) (line-end))
  78.     (goto (line-end))))))
  79.  
  80. (defun lisp-indent-pos (&optional line-pos)
  81.   (setq line-pos (line-start line-pos))
  82.   (let
  83.       ((ind-pos (lisp-indent-pos-empty line-pos)))
  84.     (unless (empty-line-p line-pos)
  85.       (when (regexp-match-line "^ *;;;" line-pos)
  86.     (set-pos-col ind-pos 1)))
  87.     ind-pos))
  88.  
  89. (defun lisp-indent-pos-empty (&optional line-pos)
  90.   (setq line-pos (line-start line-pos))
  91.   (let*
  92.       ((anchor-pos (prev-line 1 (dup-pos line-pos))))
  93.     (while (regexp-match-line "^ *($|;)" anchor-pos)
  94.       (unless (prev-line 1 anchor-pos)
  95.     (return)))
  96.     (let
  97.     ((ind-pos (indent-pos anchor-pos)))
  98.       (set-pos-line ind-pos (pos-line line-pos))
  99.       (next-tab (balance-brackets "(" ")" (copy-area anchor-pos (line-end anchor-pos))) ind-pos))))
  100.  
  101. ;;; ::jade-code::
  102. ;;; (setq mode-name "generic")
  103. ;;; ::end::
  104.