File: edit.lsp

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (57 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#+:packages
(unless (find-package "TOOLS")
	(make-package "TOOLS" :use '("XLISP")))

(in-package "TOOLS")

(export '(edit))

;;;
;;; This variable is the default file to edit
;;;

(defvar *edit-file* "")

(defvar *editor* "epsilon")

;;;
;;; edit a file using the specified editor
;;; if the file editted was a lisp file (.lsp) load it
;;;

;; Two versions, the first works when position-if exists and does a better
;; job   

#+:posfcns (defmacro edit (&optional file &aux rfile)
  (read-char)
  (when file (setq *edit-file* (string file)))
  (setq rfile (reverse *edit-file*))
  (when (null (position-if #'(lambda (x) (eq x #\.))
			   rfile
			   :end 
			   (position-if #'(lambda (x) 
						  (or (eq x #\\) (eq x #\/)))
					rfile)))
	(setq *edit-file* (strcat *edit-file* ".lsp")))
  (unless (system (strcat *editor* " " *edit-file*))
	  (error "Unable to execute: ~a ~a" *editor* *edit-file*))
  (let ((len (length *edit-file*)))
       (when (and (> len 4)
		  (string= (string-downcase (subseq *edit-file* (- len 4)))
			   ".lsp"))
	     (list 'load *edit-file*))))

#-:posfcns (defmacro edit (&optional file)
    (read-char)
    (when file (setq *edit-file* (string file)))
    (when (not (member #\.
		       (get-output-stream-list
			  (make-string-input-stream *edit-file*))))
	  (setq *edit-file* (strcat *edit-file* ".lsp")))
    (unless (system (strcat *editor* " " *edit-file*))
          (error "Unable to execute: ~a ~a" *editor* *edit-file*))
    (let ((len (length *edit-file*)))
      (when (and (> len 4)
		 (string= (string-downcase (subseq *edit-file* (- len 4)))
			  ".lsp"))
	    (list 'load *edit-file*))))