scheme.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. ;; Scheme mode, and its idiosyncratic commands.
  2. ;; Copyright (C) 1986 Free Software Foundation, Inc.
  3. ;; Adapted from Lisp mode by Bill Rozas, jinx@prep.
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is distributed in the hope that it will be useful,
  6. ;; but WITHOUT ANY WARRANTY. No author or distributor
  7. ;; accepts responsibility to anyone for the consequences of using it
  8. ;; or for whether it serves any particular purpose or works at all,
  9. ;; unless he says so in writing. Refer to the GNU Emacs General Public
  10. ;; License for full details.
  11. ;; Everyone is granted permission to copy, modify and redistribute
  12. ;; GNU Emacs, but only under the conditions described in the
  13. ;; GNU Emacs General Public License. A copy of this license is
  14. ;; supposed to have been given to you along with GNU Emacs so you
  15. ;; can know your rights and responsibilities. It should be in a
  16. ;; file named COPYING. Among other things, the copyright notice
  17. ;; and this notice must be preserved on all copies.
  18. ;; Initially a query replace of Lisp mode, except for the indentation
  19. ;; of special forms. Probably the code should be merged at some point
  20. ;; so that there is sharing between both libraries.
  21. (provide 'scheme)
  22. (defvar scheme-mode-abbrev-table nil "")
  23. (define-abbrev-table 'scheme-mode-abbrev-table ())
  24. (defvar scheme-mode-syntax-table nil "")
  25. (if scheme-mode-syntax-table
  26. ()
  27. (let ((i 0))
  28. (setq scheme-mode-syntax-table (make-syntax-table))
  29. (set-syntax-table scheme-mode-syntax-table)
  30. (while (< i ?0)
  31. (modify-syntax-entry i "_ " scheme-mode-syntax-table)
  32. (setq i (1+ i)))
  33. (setq i (1+ ?9))
  34. (while (< i ?A)
  35. (modify-syntax-entry i "_ " scheme-mode-syntax-table)
  36. (setq i (1+ i)))
  37. (setq i (1+ ?Z))
  38. (while (< i ?a)
  39. (modify-syntax-entry i "_ " scheme-mode-syntax-table)
  40. (setq i (1+ i)))
  41. (setq i (1+ ?z))
  42. (while (< i 128)
  43. (modify-syntax-entry i "_ " scheme-mode-syntax-table)
  44. (setq i (1+ i)))
  45. (modify-syntax-entry ? " " scheme-mode-syntax-table)
  46. (modify-syntax-entry ?\t " " scheme-mode-syntax-table)
  47. (modify-syntax-entry ?\n "> " scheme-mode-syntax-table)
  48. (modify-syntax-entry ?\f "> " scheme-mode-syntax-table)
  49. (modify-syntax-entry ?\; "< " scheme-mode-syntax-table)
  50. (modify-syntax-entry ?` "' " scheme-mode-syntax-table)
  51. (modify-syntax-entry ?' "' " scheme-mode-syntax-table)
  52. (modify-syntax-entry ?, "' " scheme-mode-syntax-table)
  53. (modify-syntax-entry ?. "' " scheme-mode-syntax-table)
  54. (modify-syntax-entry ?# "' " scheme-mode-syntax-table)
  55. (modify-syntax-entry ?\" "\" " scheme-mode-syntax-table)
  56. (modify-syntax-entry ?\\ "\\ " scheme-mode-syntax-table)
  57. (modify-syntax-entry ?\( "() " scheme-mode-syntax-table)
  58. (modify-syntax-entry ?\) ")( " scheme-mode-syntax-table)))
  59. (defun scheme-mode-variables ()
  60. (set-syntax-table scheme-mode-syntax-table)
  61. (setq local-abbrev-table scheme-mode-abbrev-table)
  62. (make-local-variable 'paragraph-start)
  63. (setq paragraph-start (concat "^$\\|" page-delimiter))
  64. (make-local-variable 'paragraph-separate)
  65. (setq paragraph-separate paragraph-start)
  66. (make-local-variable 'indent-line-function)
  67. (setq indent-line-function 'scheme-indent-line)
  68. (make-local-variable 'comment-start)
  69. (setq comment-start ";")
  70. (make-local-variable 'comment-start-skip)
  71. (setq comment-start-skip ";+ *")
  72. (make-local-variable 'comment-column)
  73. (setq comment-column 40)
  74. (make-local-variable 'comment-indent-hook)
  75. (setq comment-indent-hook 'scheme-comment-indent))
  76. (defun scheme-mode-commands (map)
  77. (define-key map "\t" 'scheme-indent-line)
  78. (define-key map "\177" 'backward-delete-char-untabify)
  79. (define-key map "\eo" 'scheme-send-buffer)
  80. (define-key map "\ez" 'scheme-zap-define)
  81. (define-key map "\e\C-q" 'scheme-indent-sexp)
  82. (define-key map "\e\C-s" 'find-scheme-definition)
  83. (define-key map "\e\C-y" 'scheme-zap-define-and-resume)
  84. (define-key map "\e\C-z" 'resume-scheme))
  85. (defvar scheme-mode-map ())
  86. (if scheme-mode-map
  87. ()
  88. (setq scheme-mode-map (make-sparse-keymap))
  89. ;; (define-key scheme-mode-map "\e\C-x" 'scheme-send-definition)
  90. (scheme-mode-commands scheme-mode-map))
  91. (defun scheme-mode ()
  92. "Major mode for editing Scheme code.
  93. Commands:
  94. Delete converts tabs to spaces as it moves back.
  95. Blank lines separate paragraphs. Semicolons start comments.
  96. \\{scheme-mode-map}
  97. Entry to this mode calls the value of scheme-mode-hook
  98. if that value is non-nil."
  99. (interactive)
  100. (kill-all-local-variables)
  101. (use-local-map scheme-mode-map)
  102. (setq major-mode 'scheme-mode)
  103. (setq mode-name "Scheme")
  104. (scheme-mode-variables)
  105. (run-hooks 'scheme-mode-hook))
  106. ;; This will do unless shell.el is loaded.
  107. (defun scheme-send-definition ()
  108. "Send the current definition to the Scheme process made by M-x run-scheme."
  109. (interactive)
  110. (error "Process scheme does not exist"))
  111. (defun scheme-comment-indent (&optional pos)
  112. (save-excursion
  113. (if pos (goto-char pos))
  114. (if (looking-at ";;;")
  115. (current-column)
  116. (if (looking-at ";;")
  117. (let ((tem (calculate-scheme-indent)))
  118. (if (listp tem) (car tem) tem))
  119. comment-column))))
  120. (defvar scheme-indent-offset nil "")
  121. (defvar scheme-indent-hook 'scheme-indent-hook "")
  122. (defun scheme-indent-line (&optional whole-exp)
  123. "Indent current line as Scheme code.
  124. With argument, indent any additional lines of the same expression
  125. rigidly along with this one."
  126. (interactive "P")
  127. (let ((indent (calculate-scheme-indent)) shift-amt beg end
  128. (pos (- (point-max) (point))))
  129. (beginning-of-line)
  130. (setq beg (point))
  131. (skip-chars-forward " \t")
  132. (if (looking-at "[ \t]*;;;")
  133. ;; Don't alter indentation of a ;;; comment line.
  134. nil
  135. (if (listp indent) (setq indent (car indent)))
  136. (setq shift-amt (- indent (current-column)))
  137. (if (zerop shift-amt)
  138. nil
  139. (delete-region beg (point))
  140. (indent-to indent))
  141. ;; If initial point was within line's indentation,
  142. ;; position after the indentation. Else stay at same point in text.
  143. (if (> (- (point-max) pos) (point))
  144. (goto-char (- (point-max) pos)))
  145. ;; If desired, shift remaining lines of expression the same amount.
  146. (and whole-exp (not (zerop shift-amt))
  147. (save-excursion
  148. (goto-char beg)
  149. (forward-sexp 1)
  150. (setq end (point))
  151. (goto-char beg)
  152. (forward-line 1)
  153. (setq beg (point))
  154. (> end beg))
  155. (indent-code-rigidly beg end shift-amt)))))
  156. (defun calculate-scheme-indent (&optional parse-start)
  157. "Return appropriate indentation for current line as scheme code.
  158. In usual case returns an integer: the column to indent to.
  159. Can instead return a list, whose car is the column to indent to.
  160. This means that following lines at the same level of indentation
  161. should not necessarily be indented the same way.
  162. The second element of the list is the buffer position
  163. of the start of the containing expression."
  164. (save-excursion
  165. (beginning-of-line)
  166. (let ((indent-point (point)) state paren-depth desired-indent (retry t)
  167. last-sexp containing-sexp)
  168. (if parse-start
  169. (goto-char parse-start)
  170. (beginning-of-defun))
  171. ;; Find outermost containing sexp
  172. (while (< (point) indent-point)
  173. (setq state (parse-partial-sexp (point) indent-point 0)))
  174. ;; Find innermost containing sexp
  175. (while (and retry (setq paren-depth (car state)) (> paren-depth 0))
  176. (setq retry nil)
  177. (setq last-sexp (nth 2 state))
  178. (setq containing-sexp (car (cdr state)))
  179. ;; Position following last unclosed open.
  180. (goto-char (1+ containing-sexp))
  181. ;; Is there a complete sexp since then?
  182. (if (and last-sexp (> last-sexp (point)))
  183. ;; Yes, but is there a containing sexp after that?
  184. (let ((peek (parse-partial-sexp last-sexp indent-point 0)))
  185. (if (setq retry (car (cdr peek))) (setq state peek))))
  186. (if (not retry)
  187. ;; Innermost containing sexp found
  188. (progn
  189. (goto-char (1+ containing-sexp))
  190. (if (not last-sexp)
  191. ;; indent-point immediately follows open paren.
  192. ;; Don't call hook.
  193. (setq desired-indent (current-column))
  194. ;; Move to first sexp after containing open paren
  195. (parse-partial-sexp (point) last-sexp 0 t)
  196. (cond
  197. ((looking-at "\\s(")
  198. ;; Looking at a list. Don't call hook.
  199. (if (not (> (save-excursion (forward-line 1) (point)) last-sexp))
  200. (progn (goto-char last-sexp)
  201. (beginning-of-line)
  202. (parse-partial-sexp (point) last-sexp 0 t)))
  203. ;; Indent under the list or under the first sexp on the
  204. ;; same line as last-sexp. Note that first thing on that
  205. ;; line has to be complete sexp since we are inside the
  206. ;; innermost containing sexp.
  207. (backward-prefix-chars)
  208. (setq desired-indent (current-column)))
  209. ((> (save-excursion (forward-line 1) (point))
  210. last-sexp)
  211. ;; Last sexp is on same line as containing sexp.
  212. ;; It's almost certainly a function call.
  213. (parse-partial-sexp (point) last-sexp 0 t)
  214. (if (/= (point) last-sexp)
  215. ;; Indent beneath first argument or, if only one sexp
  216. ;; on line, indent beneath that.
  217. (progn (forward-sexp 1)
  218. (parse-partial-sexp (point) last-sexp 0 t)))
  219. (backward-prefix-chars))
  220. (t
  221. ;; Indent beneath first sexp on same line as last-sexp.
  222. ;; Again, it's almost certainly a function call.
  223. (goto-char last-sexp)
  224. (beginning-of-line)
  225. (parse-partial-sexp (point) last-sexp 0 t)
  226. (backward-prefix-chars)))))))
  227. ;; Point is at the point to indent under unless we are inside a string.
  228. ;; Call indentation hook except when overriden by scheme-indent-offset
  229. ;; or if the desired indentation has already been computed.
  230. (cond ((car (nthcdr 3 state))
  231. ;; Inside a string, don't change indentation.
  232. (goto-char indent-point)
  233. (skip-chars-forward " \t")
  234. (setq desired-indent (current-column)))
  235. ((and (integerp scheme-indent-offset) containing-sexp)
  236. ;; Indent by constant offset
  237. (goto-char containing-sexp)
  238. (setq desired-indent (+ scheme-indent-offset (current-column))))
  239. ((not (or desired-indent
  240. (and (boundp 'scheme-indent-hook)
  241. scheme-indent-hook
  242. (not retry)
  243. (setq desired-indent
  244. (funcall scheme-indent-hook
  245. indent-point state)))))
  246. ;; Use default indentation if not computed yet
  247. (setq desired-indent (current-column))))
  248. desired-indent)))
  249. (defun scheme-indent-hook (indent-point state)
  250. (let ((normal-indent (current-column)))
  251. (save-excursion
  252. (goto-char (1+ (car (cdr state))))
  253. (re-search-forward "\\sw\\|\\s_")
  254. (if (/= (point) (car (cdr state)))
  255. (let ((function (buffer-substring (progn (forward-char -1) (point))
  256. (progn (forward-sexp 1) (point))))
  257. method)
  258. ;; Who cares about this, really?
  259. ;(if (not (string-match "\\\\\\||" function)))
  260. (setq function (downcase function))
  261. (setq method (get (intern-soft function) 'scheme-indent-hook))
  262. (cond ((integerp method)
  263. (scheme-indent-specform method state indent-point))
  264. (method
  265. (funcall method state indent-point))
  266. ((and (> (length function) 3)
  267. (string-equal (substring function 0 3) "def"))
  268. (scheme-indent-defform state indent-point))))))))
  269. (defvar scheme-body-indent 2 "")
  270. (defun scheme-indent-specform (count state indent-point)
  271. (let ((containing-form-start (car (cdr state))) (i count)
  272. body-indent containing-form-column)
  273. ;; Move to the start of containing form, calculate indentation
  274. ;; to use for non-distinguished forms (> count), and move past the
  275. ;; function symbol. scheme-indent-hook guarantees that there is at
  276. ;; least one word or symbol character following open paren of containing
  277. ;; form.
  278. (goto-char containing-form-start)
  279. (setq containing-form-column (current-column))
  280. (setq body-indent (+ scheme-body-indent containing-form-column))
  281. (forward-char 1)
  282. (forward-sexp 1)
  283. ;; Now find the start of the last form.
  284. (parse-partial-sexp (point) indent-point 1 t)
  285. (while (and (< (point) indent-point)
  286. (condition-case nil
  287. (progn
  288. (setq count (1- count))
  289. (forward-sexp 1)
  290. (parse-partial-sexp (point) indent-point 1 t))
  291. (error nil))))
  292. ;; Point is sitting on first character of last (or count) sexp.
  293. (if (> count 0)
  294. ;; A distinguished form. If it is the first or second form
  295. ;; use double scheme-body-indent, else normal indent. With
  296. ;; scheme-body-indent bound to 2 (the default), this just
  297. ;; happens to work the same with if as the older code, but it
  298. ;; makes unwind-protect, condition-case,
  299. ;; with-output-to-temp-buffer, et. al. much more tasteful.
  300. ;; The older, less hacked, behavior can be obtained by
  301. ;; replacing below with (list normal-indent containing-form-start).
  302. (if (<= (- i count) 1)
  303. (list (+ containing-form-column (* 2 scheme-body-indent))
  304. containing-form-start)
  305. (list normal-indent containing-form-start))
  306. ;; A non-distinguished form. Use body-indent if there are no
  307. ;; distinguished forms and this is the first undistinguished
  308. ;; form, or if this is the first undistinguished form and
  309. ;; the preceding distinguished form has indentation at
  310. ;; least as great as body-indent.
  311. (if (or (and (= i 0) (= count 0))
  312. (and (= count 0) (<= body-indent normal-indent)))
  313. body-indent
  314. normal-indent))))
  315. (defun scheme-indent-defform (state indent-point)
  316. (goto-char (car (cdr state)))
  317. (forward-line 1)
  318. (if (> (point) (car (cdr (cdr state))))
  319. (progn
  320. (goto-char (car (cdr state)))
  321. (+ scheme-body-indent (current-column)))))
  322. ;;; Let is different in Scheme
  323. (defun would-be-symbol (string)
  324. (not (char-equal (aref string 0) ?\()))
  325. (defun next-sexp-as-string ()
  326. ;; Assumes that protected by a save-excursion
  327. (forward-sexp 1)
  328. (let ((the-end (point)))
  329. (backward-sexp 1)
  330. (buffer-substring (point) the-end)))
  331. ;; This is correct but too slow.
  332. ;; The one below works almost always.
  333. ;;(defun scheme-let-indent (state indent-point)
  334. ;; (if (would-be-symbol (next-sexp-as-string))
  335. ;; (scheme-indent-specform 2 state indent-point)
  336. ;; (scheme-indent-specform 1 state indent-point)))
  337. (defun scheme-let-indent (state indent-point)
  338. (skip-chars-forward " \t")
  339. (if (looking-at "[a-zA-Z0-9+-*/?!@$%^&_:~]")
  340. (scheme-indent-specform 2 state indent-point)
  341. (scheme-indent-specform 1 state indent-point)))
  342. ;; (put 'begin 'scheme-indent-hook 0), say, causes begin to be indented
  343. ;; like defun if the first form is placed on the next line, otherwise
  344. ;; it is indented like any other form (i.e. forms line up under first).
  345. (put 'begin 'scheme-indent-hook 0)
  346. (put 'case 'scheme-indent-hook 1)
  347. (put 'do 'scheme-indent-hook 2)
  348. (put 'fluid-let 'scheme-indent-hook 1)
  349. (put 'if 'scheme-indent-hook 3)
  350. (put 'in-package 'scheme-indent-hook 1)
  351. (put 'lambda 'scheme-indent-hook 1)
  352. (put 'let 'scheme-indent-hook 'scheme-let-indent)
  353. (put 'let* 'scheme-indent-hook 1)
  354. (put 'let-syntax 'scheme-indent-hook 1)
  355. (put 'letrec 'scheme-indent-hook 1)
  356. (put 'local-declare 'scheme-indent-hook 1)
  357. (put 'macro 'scheme-indent-hook 1)
  358. (put 'make-environment 'scheme-indent-hook 0)
  359. (put 'make-package 'scheme-indent-hook 2)
  360. (put 'named-lambda 'scheme-indent-hook 1)
  361. (put 'sequence 'scheme-indent-hook 0)
  362. (put 'using-syntax 'scheme-indent-hook 1)
  363. (defun scheme-indent-sexp ()
  364. "Indent each line of the list starting just after point."
  365. (interactive)
  366. (let ((indent-stack (list nil)) (next-depth 0) bol
  367. outer-loop-done inner-loop-done state this-indent)
  368. (save-excursion (forward-sexp 1))
  369. (save-excursion
  370. (setq outer-loop-done nil)
  371. (while (not outer-loop-done)
  372. (setq last-depth next-depth
  373. innerloop-done nil)
  374. (while (and (not innerloop-done)
  375. (not (setq outer-loop-done (eobp))))
  376. (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
  377. nil nil state))
  378. (setq next-depth (car state))
  379. (if (car (nthcdr 4 state))
  380. (progn (indent-for-comment)
  381. (end-of-line)
  382. (setcar (nthcdr 4 state) nil)))
  383. (if (car (nthcdr 3 state))
  384. (progn
  385. (forward-line 1)
  386. (setcar (nthcdr 5 state) nil))
  387. (setq innerloop-done t)))
  388. (if (setq outer-loop-done (<= next-depth 0))
  389. nil
  390. (while (> last-depth next-depth)
  391. (setq indent-stack (cdr indent-stack)
  392. last-depth (1- last-depth)))
  393. (while (< last-depth next-depth)
  394. (setq indent-stack (cons nil indent-stack)
  395. last-depth (1+ last-depth)))
  396. (forward-line 1)
  397. (setq bol (point))
  398. (skip-chars-forward " \t")
  399. (if (or (eobp) (looking-at "[;\n]"))
  400. nil
  401. (if (and (car indent-stack)
  402. (>= (car indent-stack) 0))
  403. (setq this-indent (car indent-stack))
  404. (let ((val (calculate-scheme-indent
  405. (if (car indent-stack) (- (car indent-stack))))))
  406. (if (integerp val)
  407. (setcar indent-stack
  408. (setq this-indent val))
  409. (setcar indent-stack (- (car (cdr val))))
  410. (setq this-indent (car val)))))
  411. (if (/= (current-column) this-indent)
  412. (progn (delete-region bol (point))
  413. (indent-to this-indent)))))))))
  414. ;;; Schedit commands (old scheme interface)
  415. (defvar scheme-zap-name (expand-file-name "fromedit.zap" nil)
  416. "Name of transfer file between Scheme and Emacs")
  417. (defvar scheme-invocation-string "%scheme"
  418. "*String to give to the Cshell to proceed a sibling Scheme")
  419. (defun goto-parallel-scheme-fork ()
  420. (suspend-emacs scheme-invocation-string))
  421. ;; This currently assumes that Emacs runs as an inferior to Scheme
  422. (fset 'goto-scheme 'suspend-emacs)
  423. ;; if not, do (fset 'goto-scheme 'goto-parallel-scheme-fork)
  424. (defun resume-scheme ()
  425. "Suspend Emacs and resume Scheme"
  426. (interactive)
  427. (let ((zap-buffer (get-buffer scheme-zap-name))
  428. (this-buffer (current-buffer)))
  429. (if zap-buffer
  430. (save-excursion
  431. (unwind-protect
  432. (progn (set-buffer zap-buffer)
  433. (or buffer-file-name
  434. (setq buffer-file-name scheme-zap-name))
  435. (save-buffer)
  436. (erase-buffer)
  437. (setq buffer-modified-p nil))
  438. (set-buffer this-buffer)))))
  439. (goto-scheme))
  440. (defun scheme-do-zap-region (start end buffer &optional separate)
  441. "Internal routine which zaps a region of text for Scheme."
  442. (let ((the-text (buffer-substring start end)))
  443. (save-excursion
  444. (unwind-protect
  445. (progn (set-buffer (get-buffer-create scheme-zap-name))
  446. (insert-string the-text)
  447. (if separate (newline 2)))
  448. (set-buffer buffer)))))
  449. (defun scheme-zap-region (start end)
  450. "Zap region between point and mark into Scheme."
  451. (interactive "r")
  452. (scheme-do-zap-region start end (current-buffer)))
  453. (defun scheme-zap-expression (arg)
  454. "Zap sexp before point into Scheme."
  455. (interactive "P")
  456. (scheme-do-zap-region
  457. (let ((stab (syntax-table)))
  458. (unwind-protect
  459. (save-excursion
  460. (set-syntax-table lisp-mode-syntax-table)
  461. (forward-sexp -1)
  462. (point))
  463. (set-syntax-table stab)))
  464. (point)
  465. (current-buffer)
  466. t))
  467. (defun scheme-zap-define (arg)
  468. "Zap current definition into Scheme."
  469. (interactive "P")
  470. (let ((stab (syntax-table)))
  471. (unwind-protect
  472. (save-excursion
  473. (set-syntax-table scheme-mode-syntax-table)
  474. (if (not (= (point) (point-max))) (forward-char 1))
  475. (beginning-of-defun 1)
  476. (let ((start (point)))
  477. (forward-sexp 1)
  478. (scheme-do-zap-region start
  479. (point)
  480. (current-buffer)
  481. t)))
  482. (set-syntax-table stab))))
  483. (defun scheme-send-buffer (arg)
  484. "Zap whole buffer and resume Scheme"
  485. (interactive "P")
  486. (scheme-do-zap-region (point-min)
  487. (point-max)
  488. (current-buffer))
  489. (resume-scheme))
  490. (defun scheme-zap-define-and-resume (arg)
  491. "Zap current definition and resume Scheme"
  492. (interactive "P")
  493. (scheme-zap-define arg)
  494. (resume-scheme))
  495. (defun defining-p ()
  496. (save-excursion
  497. (let* ((here (point))
  498. (name (buffer-substring (progn (backward-sexp 1) (point)) here)))
  499. (beginning-of-defun 1)
  500. (if (char-equal (char-after (point)) ?\()
  501. (progn (forward-char 1)
  502. (let ((sub (substring (next-sexp-as-string) 0 3)))
  503. (if (or (string-equal sub "def") (string-equal sub "DEF"))
  504. (progn (forward-sexp 1)
  505. (forward-word 1)
  506. (backward-word 1)
  507. (string-equal name
  508. (next-sexp-as-string))))))))))
  509. (defun find-scheme-definition (name)
  510. "Find the definition of its argument in the current buffer"
  511. (interactive "sFind Scheme definition of: ")
  512. (beginning-of-buffer)
  513. (let ((stop nil))
  514. (while (not stop)
  515. (search-forward name)
  516. (setq stop (defining-p)))))
  517. ;;; Autoloads from xscheme:
  518. (autoload 'scheme "xscheme"
  519. "Run an inferior Scheme process reading a command line from the terminal."
  520. t)
  521. (autoload 'run-scheme "xscheme"
  522. "Run an inferior Scheme process."
  523. t)
  524. (autoload 'scheme-send-definition "xscheme"
  525. "Send the current definition to the Scheme process made by M-x run-scheme."
  526. t)
  527. (autoload 'scheme-send-definition-and-go "xscheme"
  528. "Send the current definition to the inferior Scheme, and switch to *scheme* buffer."
  529. t)