0
|
1 ;;; -*- Mode: Emacs-Lisp -*-
|
|
2
|
|
3 ;;; ilisp-low.el --
|
|
4
|
|
5 ;;; This file is part of ILISP.
|
4
|
6 ;;; Version: 5.8
|
0
|
7 ;;;
|
|
8 ;;; Copyright (C) 1990, 1991, 1992, 1993 Chris McConnell
|
|
9 ;;; 1993, 1994 Ivan Vasquez
|
4
|
10 ;;; 1994, 1995, 1996 Marco Antoniotti and Rick Busdiecker
|
|
11 ;;; 1996 Marco Antoniotti and Rick Campbell
|
0
|
12 ;;;
|
|
13 ;;; Other authors' names for which this Copyright notice also holds
|
|
14 ;;; may appear later in this file.
|
|
15 ;;;
|
4
|
16 ;;; Send mail to 'ilisp-request@naggum.no' to be included in the
|
|
17 ;;; ILISP mailing list. 'ilisp@naggum.no' is the general ILISP
|
0
|
18 ;;; mailing list were bugs and improvements are discussed.
|
|
19 ;;;
|
|
20 ;;; ILISP is freely redistributable under the terms found in the file
|
|
21 ;;; COPYING.
|
|
22
|
|
23
|
|
24
|
|
25 ;;;
|
|
26 ;;; ILISP low level interface functions Lisp <-> Emacs
|
|
27 ;;;
|
|
28 ;;;
|
|
29
|
|
30
|
|
31
|
|
32 ;;;%Lisp mode extensions
|
|
33 ;;;%%Sexps
|
|
34 (defun lisp-previous-sexp (&optional prefix)
|
|
35 "Return the previous sexp. If PREFIX is T, then prefix like ' or #'
|
|
36 are allowed."
|
|
37 (save-excursion
|
|
38 (condition-case ()
|
|
39 (progn
|
|
40 (if (and (memq major-mode ilisp-modes)
|
|
41 (= (point)
|
|
42 (process-mark (get-buffer-process (current-buffer)))))
|
|
43 nil
|
|
44 (if (not
|
|
45 (or (eobp) (memq (char-after (point)) '(? ?\) ?\n ?\t))))
|
|
46 (forward-sexp))
|
|
47 (skip-chars-backward " \t\n")
|
|
48 (let ((point (point)))
|
|
49 (backward-sexp)
|
|
50 (skip-chars-backward "^ \t\n(\",")
|
|
51 (if (not prefix) (skip-chars-forward "#'"))
|
|
52 (buffer-substring (point) point))))
|
|
53 (error nil))))
|
|
54
|
|
55 ;;;
|
|
56 (defun lisp-def-name (&optional namep)
|
|
57 "Return the name of a definition assuming that you are at the start
|
|
58 of the sexp. If the form starts with DEF, the form start and the next
|
|
59 symbol will be returned. Optional NAMEP will return only the name without the defining symbol."
|
|
60 (let ((case-fold-search t))
|
|
61 (if (looking-at
|
|
62 ;; (( \( (def*) (( \( (setf)) | \(?)) | \(?) (symbol)
|
|
63 ;; 12 3 3 45 6 65 42 1 7 7
|
|
64 ;;0011\(22 def* 22 32 43\(54 setf54 43 \(?32 11 00 60 60
|
|
65 "\\(\\((\\(def[^ \t\n]*\\)[ \t\n]+\\(\\((\\(setf\\)[ \t\n]+\\)\\|(?\\)\\)\\|(?\\)\\([^ \t\n)]*\\)")
|
|
66 (let ((symbol (buffer-substring (match-beginning 7) (match-end 7))))
|
|
67 (if (match-end 6)
|
|
68 (concat (if (not namep)
|
|
69 (concat
|
|
70 (buffer-substring (match-beginning 3) (match-end 3))
|
|
71 " "))
|
|
72 "("
|
|
73 (buffer-substring (match-beginning 6) (match-end 6))
|
|
74 " " symbol ")")
|
|
75 (if (match-end 3)
|
|
76 (concat (if (not namep)
|
|
77 (concat
|
|
78 (buffer-substring (match-beginning 3)
|
|
79 (match-end 3))
|
|
80 " "))
|
|
81 symbol)
|
|
82 symbol))))))
|
|
83
|
|
84
|
|
85 ;;;
|
|
86 (defun lisp-minus-prefix ()
|
|
87 "Set current-prefix-arg to its absolute value if numeric and return
|
|
88 T if it is a negative."
|
|
89 (if current-prefix-arg
|
|
90 (if (symbolp current-prefix-arg)
|
|
91 (progn (setq current-prefix-arg nil) t)
|
|
92 (if (< (setq current-prefix-arg
|
|
93 (prefix-numeric-value current-prefix-arg))
|
|
94 0)
|
|
95 (progn
|
|
96 (setq current-prefix-arg (- current-prefix-arg)) t)))))
|
|
97
|
|
98
|
|
99
|
|
100 ;;;%%Defuns
|
|
101 (defun lisp-defun-region-and-name ()
|
|
102 "Return the region of the current defun and the name starting it."
|
|
103 (save-excursion
|
|
104 (let ((end (lisp-defun-end))
|
|
105 (begin (lisp-defun-begin)))
|
|
106 (list begin end (lisp-def-name)))))
|
|
107
|
|
108 ;;;
|
|
109 (defun lisp-region-name (start end)
|
|
110 "Return a name for the region from START to END."
|
|
111 (save-excursion
|
|
112 (goto-char start)
|
|
113 (if (re-search-forward "^[ \t]*[^;\n]" end t)
|
|
114 (forward-char -1))
|
|
115 (setq start (point))
|
|
116 (goto-char end)
|
|
117 (re-search-backward "^[ \t]*[^;\n]" start 'move)
|
|
118 (end-of-line)
|
|
119 (skip-chars-backward " \t")
|
|
120 (setq end (min (point) end))
|
|
121 (goto-char start)
|
|
122 (let ((from
|
|
123 (if (= (char-after (point)) ?\()
|
|
124 (lisp-def-name)
|
|
125 (buffer-substring (point)
|
|
126 (progn (forward-sexp) (point))))))
|
|
127 (goto-char end)
|
|
128 (if (= (char-after (1- (point))) ?\))
|
|
129 (progn
|
|
130 (backward-sexp)
|
|
131 (if (= (point) start)
|
|
132 from
|
|
133 (concat "from " from " to " (lisp-def-name))))
|
|
134 (concat "from " from " to "
|
|
135 (buffer-substring (save-excursion
|
|
136 (backward-sexp)
|
|
137 (point))
|
|
138 (1- (point))))))))
|