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