annotate lisp/ilisp/ilisp-utl.el @ 119:d101af7320b8

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