annotate lisp/ilisp/ilisp-utl.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*- Mode: Emacs-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; ilisp-utl.el --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; This file is part of ILISP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Version: 5.7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Copyright (C) 1990, 1991, 1992, 1993 Chris McConnell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; 1993, 1994 Ivan Vasquez
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; 1994, 1995 Marco Antoniotti and Rick Busdiecker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; Other authors' names for which this Copyright notice also holds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; may appear later in this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; Send mail to 'ilisp-request@lehman.com' to be included in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; ILISP mailing list. 'ilisp@lehman.com' is the general ILISP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; mailing list were bugs and improvements are discussed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; ILISP is freely redistributable under the terms found in the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; COPYING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; ILISP misc tools.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defun lisp-show-send (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 "Show STRING in the *ilisp-send* buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (if (ilisp-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (set-buffer "*ilisp-send*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (error "You must start an inferior LISP with run-ilisp."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defun lisp-slashify (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "Put string in the *ilisp-send* buffer, put backslashes before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 quotes and backslashes and return the resulting string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (lisp-show-send string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (set-buffer "*ilisp-send*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (while (search-forward "\\" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (insert "\\\\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (while (search-forward "\"" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (insert ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (buffer-substring (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;;%%String
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defun lisp-prefix-p (s1 s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "Returns t if S1 is a prefix of S2 considering all non alphanumerics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 as word delimiters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (let ((len1 (length s1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (and (<= len1 (length s2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (let ((start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (start2 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (match t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if (setq end (string-match "[^a-zA-Z0-9]" s1 start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; Found delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (if (string= (substring s1 start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (substring s2 start2 (+ start2 (- end start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; Words are the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (progn (setq start (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (if (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (regexp-quote (substring s1 end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 s2 start2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (setq start2 (match-end 0)) ;OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (setq match nil))) ;Can't find delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq match nil)) ;Words don't match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 nil)) ;Ran out of delimiters in s1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (and match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (string= (substring s1 start len1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (substring s2 start2 (+ start2 (- len1 start)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun lisp-last-line (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Return the last line of STRING with everything else."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (let* ((position 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (while (string-match "\\(\n+\\)[^\n]" string position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (setq position (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (cons (substring string position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (substring string 0 position))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;;%%File
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defun lisp-file-extension (file extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "Return FILE with new EXTENSION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (concat (substring file 0 (string-match ".[^.]*$" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "." extension))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defun ilisp-directory (file &optional dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "Return the directory of DIRS that FILE is found in. By default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 load-path is used for the directories."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (let* ((dirs (or dirs (cons "" load-path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (dir (car dirs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (while (and dir (not (file-exists-p (expand-file-name file dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq dirs (cdr dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 dir (car dirs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; ilisp-update-status --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; Note: changed in order to propagate the status change in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; underlying process to the menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defun ilisp-update-status (status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "Update process STATUS of the whole Ilisp system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 It updates the STATUS of the current buffer and let all lisp mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 buffers know as well. Also, do some 'exterior' things like make sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 that the menubar is in a consistent state."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq ilisp-status (if lisp-show-status (format " :%s" status)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if (not (member +ilisp-emacs-version-id+ '(xemacs lucid-19 lucid-19-new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (ilisp-update-menu status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (comint-update-status status))