home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xl21hos2.zip / EDIT.LSP < prev    next >
Lisp/Scheme  |  1995-12-27  |  2KB  |  58 lines

  1. #+:packages
  2. (unless (find-package "TOOLS")
  3.     (make-package "TOOLS" :use '("XLISP")))
  4.  
  5. (in-package "TOOLS")
  6.  
  7. (export '(edit))
  8.  
  9. ;;;
  10. ;;; This variable is the default file to edit
  11. ;;;
  12.  
  13. (defvar *edit-file* "")
  14.  
  15. (defvar *editor* "epsilon")
  16.  
  17. ;;;
  18. ;;; edit a file using the specified editor
  19. ;;; if the file editted was a lisp file (.lsp) load it
  20. ;;;
  21.  
  22. ;; Two versions, the first works when position-if exists and does a better
  23. ;; job   
  24.  
  25. #+:posfcns (defmacro edit (&optional file &aux rfile)
  26.   (read-char)
  27.   (when file (setq *edit-file* (string file)))
  28.   (setq rfile (reverse *edit-file*))
  29.   (when (null (position-if #'(lambda (x) (eq x #\.))
  30.                rfile
  31.                :end 
  32.                (position-if #'(lambda (x) 
  33.                           (or (eq x #\\) (eq x #\/)))
  34.                     rfile)))
  35.     (setq *edit-file* (strcat *edit-file* ".lsp")))
  36.   (unless (system (strcat *editor* " " *edit-file*))
  37.       (error "Unable to execute: ~a ~a" *editor* *edit-file*))
  38.   (let ((len (length *edit-file*)))
  39.        (when (and (> len 4)
  40.           (string= (string-downcase (subseq *edit-file* (- len 4)))
  41.                ".lsp"))
  42.          (list 'load *edit-file*))))
  43.  
  44. #-:posfcns (defmacro edit (&optional file)
  45.     (read-char)
  46.     (when file (setq *edit-file* (string file)))
  47.     (when (not (member #\.
  48.                (get-output-stream-list
  49.               (make-string-input-stream *edit-file*))))
  50.       (setq *edit-file* (strcat *edit-file* ".lsp")))
  51.     (unless (system (strcat *editor* " " *edit-file*))
  52.           (error "Unable to execute: ~a ~a" *editor* *edit-file*))
  53.     (let ((len (length *edit-file*)))
  54.       (when (and (> len 4)
  55.          (string= (string-downcase (subseq *edit-file* (- len 4)))
  56.               ".lsp"))
  57.         (list 'load *edit-file*))))
  58.