annotate lisp/ilisp/ilisp-low.el @ 205:92f8ad5d0d3f r20-4b1

Import from CVS: tag r20-4b1
author cvs
date Mon, 13 Aug 2007 10:02:46 +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-low.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 low level interface functions Lisp <-> Emacs
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;;%Lisp mode extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;;%%Sexps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun lisp-previous-sexp (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Return the previous sexp. If PREFIX is T, then prefix like ' or #'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 are allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (if (and (memq major-mode ilisp-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (= (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (process-mark (get-buffer-process (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (if (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (or (eobp) (memq (char-after (point)) '(? ?\) ?\n ?\t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (forward-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (let ((point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (skip-chars-backward "^ \t\n(\",")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (if (not prefix) (skip-chars-forward "#'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (buffer-substring (point) point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defun lisp-def-name (&optional namep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "Return the name of a definition assuming that you are at the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 of the sexp. If the form starts with DEF, the form start and the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 symbol will be returned. Optional NAMEP will return only the name without the defining symbol."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (if (looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; (( \( (def*) (( \( (setf)) | \(?)) | \(?) (symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; 12 3 3 45 6 65 42 1 7 7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;0011\(22 def* 22 32 43\(54 setf54 43 \(?32 11 00 60 60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "\\(\\((\\(def[^ \t\n]*\\)[ \t\n]+\\(\\((\\(setf\\)[ \t\n]+\\)\\|(?\\)\\)\\|(?\\)\\([^ \t\n)]*\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (let ((symbol (buffer-substring (match-beginning 7) (match-end 7))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if (match-end 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (concat (if (not namep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (buffer-substring (match-beginning 3) (match-end 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (buffer-substring (match-beginning 6) (match-end 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 " " symbol ")")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (if (match-end 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (concat (if (not namep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (buffer-substring (match-beginning 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (match-end 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 symbol))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun lisp-minus-prefix ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "Set current-prefix-arg to its absolute value if numeric and return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 T if it is a negative."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (if (symbolp current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (progn (setq current-prefix-arg nil) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if (< (setq current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (prefix-numeric-value current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (setq current-prefix-arg (- current-prefix-arg)) t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;;%%Defuns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun lisp-defun-region-and-name ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Return the region of the current defun and the name starting it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (let ((end (lisp-defun-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (begin (lisp-defun-begin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (list begin end (lisp-def-name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (defun lisp-region-name (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 "Return a name for the region from START to END."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if (re-search-forward "^[ \t]*[^;\n]" end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (re-search-backward "^[ \t]*[^;\n]" start 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq end (min (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (let ((from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (if (= (char-after (point)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (lisp-def-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (progn (forward-sexp) (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if (= (char-after (1- (point))) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (if (= (point) start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (concat "from " from " to " (lisp-def-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (concat "from " from " to "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (buffer-substring (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (1- (point))))))))