home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / ilisp / ilisp-src.el < prev    next >
Encoding:
Text File  |  1992-06-29  |  19.9 KB  |  587 lines

  1. ;;; -*-Emacs-Lisp-*-
  2. ;;;%Header
  3. ;;; Inferior LISP interaction package source submodule.
  4. ;;; Copyright (C) 1990, 1991, 1992 Chris McConnell, ccm@cs.cmu.edu.
  5.  
  6. ;;; See ilisp.el for more information.
  7.  
  8. ;;;%Source file operations
  9. (if (not (boundp 'tags-file-name)) (defvar tags-file-name nil))
  10. (defvar lisp-last-definition nil "Last definition (name type) looked for.")
  11. (defvar lisp-last-file nil "Last used source file.")
  12. (defvar lisp-first-point nil "First point found in last source file.")
  13. (defvar lisp-last-point nil "Last point in last source file.")
  14. (defvar lisp-last-locator nil "Last source locator used.")
  15. (defvar lisp-search nil "Set to T when searching for definitions.")
  16. (defvar lisp-using-tags nil "Set to T when using tags.")
  17.  
  18. ;;;%%lisp-directory
  19. (defvar lisp-edit-files t
  20.   "If T, then buffers in one of lisp-source-modes will be searched by
  21. edit-definitions-lisp if the source cannot be found through the
  22. inferior LISP.  It can also be a list of files to edit definitions
  23. from set up by \(\\[lisp-directory]).  If it is set to nil, then no
  24. additional files will be searched.")
  25.  
  26. ;;;
  27. (defun lisp-extensions ()
  28.   "Return a regexp for matching the extensions of files that enter one
  29. of lisp-source-modes according to auto-mode-alist."
  30.   (let ((entries auto-mode-alist)
  31.     (extensions nil))
  32.     (while entries
  33.       (let ((entry (car entries)))
  34.     (if (memq (cdr entry) lisp-source-modes)
  35.         (setq extensions 
  36.           (concat "\\|" (car entry) extensions))))
  37.       (setq entries (cdr entries)))
  38.   (substring extensions 2)))
  39.  
  40. ;;;
  41. (defun lisp-directory (directory add)
  42.   "Edit the files in DIRECTORY that have an auto-mode alist entry in
  43. lisp-source-modes.  With a positive prefix, add the files on to the
  44. already existing files.  With a negative prefix, clear the list.  In
  45. either case set tags-file-name to nil so that tags are not used."
  46.   (interactive 
  47.    (list (if (not (eq current-prefix-arg '-))
  48.          (read-file-name "Lisp Directory: "
  49.                  nil
  50.                  default-directory
  51.                  nil))
  52.          current-prefix-arg))
  53.   (setq tags-file-name nil)
  54.   (if (eq add '-)
  55.       (progn (setq lisp-edit-files t)
  56.          (message "No current lisp directory"))
  57.       (if add
  58.       (message "Added %s as a lisp directory" directory)
  59.       (message "%s is the lisp directory" directory))
  60.       (setq directory (expand-file-name directory))
  61.       (if (file-directory-p directory)
  62.       (setq lisp-edit-files
  63.         (append
  64.          (directory-files directory t (lisp-extensions))
  65.          (if add (if (eq lisp-edit-files t) nil lisp-edit-files))))
  66.       (error "%s is not a directory" directory))))
  67.  
  68. ;;;%%Utilities
  69. (defun lisp-setup-edit-definitions (message edit-files)
  70.   "Set up *Edit-Definitions* with MESSAGE. If EDIT-FILES is T, insert
  71. all buffer filenames that are in one of lisp-source-modes into the
  72. current buffer.  If it is a list of files set up by lisp-directory,
  73. insert those in the buffer.  If it is a string put that in the buffer."
  74.   (setq lisp-using-tags nil
  75.     lisp-search (not (stringp edit-files)))
  76.   (set-buffer (get-buffer-create "*Edit-Definitions*"))
  77.   (erase-buffer)
  78.   (insert message)
  79.   (insert "\n\n")
  80.   (if edit-files
  81.       (progn
  82.     (if (eq edit-files t)
  83.         (let ((buffers (buffer-list)))
  84.           (while buffers
  85.         (let ((buffer (car buffers)))
  86.           (if (save-excursion 
  87.             (set-buffer buffer) 
  88.             (and (memq major-mode lisp-source-modes)
  89.                  (buffer-file-name buffer)))
  90.               (progn (insert ?\") (insert (buffer-file-name buffer))
  91.                  (insert "\"\n"))))
  92.         (setq buffers (cdr buffers))))
  93.         (if (stringp edit-files)
  94.         (progn (insert edit-files)
  95.                    ;; Remove garbage collection messages
  96.                (replace-regexp "^;[^\n]*\n" ""))
  97.         (let ((files edit-files))
  98.           (while files
  99.             (insert ?\")
  100.             (insert (car files))
  101.             (insert "\"\n")
  102.             (setq files (cdr files))))))
  103.     (goto-char (point-min))
  104.     (forward-line 2)
  105.     (set-buffer-modified-p nil))
  106.       (error 
  107.        (substitute-command-keys
  108.     "Use \\[lisp-directory] to define source files."))))
  109.       
  110. ;;;
  111. (defun lisp-locate-definition (locator definition file point 
  112.                        &optional
  113.                        back pop)
  114.   "Use LOCATOR to find the next DEFINITION (symbol . type) in FILE
  115. starting at POINT, optionally BACKWARDS and POP to buffer.  Return T
  116. if successful."
  117.   (if (and file (file-exists-p file))
  118.       (let* ((symbol (car definition))
  119.          (type (cdr definition))
  120.          (first (not (eq lisp-last-file file)))
  121.          (buffer (current-buffer))
  122.          name)
  123.     (lisp-find-file file pop)
  124.     (if first (setq lisp-first-point (point)))
  125.     (if back
  126.         (if first
  127.         (goto-char (point-max))
  128.         (goto-char point)
  129.         (forward-line -1) 
  130.         (end-of-line))
  131.         (goto-char point)
  132.         (if (not first) 
  133.         (progn (forward-line 1) (beginning-of-line))))
  134.     (if (eq type 't)
  135.         (message "Search %s for %s" file symbol)
  136.         (message "Searching %s for %s %s" file type
  137.              (setq name (lisp-buffer-symbol symbol))))
  138.     (if (funcall locator symbol type first back)
  139.         (progn
  140.           (setq lisp-last-file file
  141.             lisp-last-point (point))
  142.           (if (bolp)
  143.           (forward-line -1)
  144.           (beginning-of-line))
  145.           (recenter 0)
  146.           (if name 
  147.           (message "Found %s %s definition" type name)
  148.           (message "Found %s"))
  149.           t)
  150.         (if first 
  151.         (goto-char lisp-first-point)
  152.         (set-buffer buffer)
  153.         (goto-char point))
  154.         nil))))
  155.  
  156. ;;;
  157. (defun lisp-next-file (back)
  158.   "Return the next filename in *Edit-Definitions*, or nil if none."
  159.   (let ((file t))
  160.     (set-buffer (get-buffer-create "*Edit-Definitions*"))
  161.     (if back 
  162.     (progn (forward-line -1)
  163.            (if (looking-at "\n")
  164.            (progn 
  165.              (forward-line 1)
  166.              (end-of-line)
  167.              (setq file nil)))))
  168.   (if file
  169.       (progn
  170.     (skip-chars-forward "^\"")
  171.     (if (eobp)
  172.         (progn (bury-buffer (current-buffer))
  173.            (setq result nil))
  174.         (let* ((start (progn (forward-char 1) (point))))
  175.           (skip-chars-forward "^\"") 
  176.           (setq file
  177.             (prog1 (buffer-substring start (point))
  178.               (end-of-line)))
  179.           (bury-buffer (current-buffer))))))
  180.   (if (not (eq file 't)) file)))
  181.  
  182. ;;;
  183. (defun lisp-next-definition (back pop)
  184.   "Go to the next definition from *Edit-Definitions* going BACK with
  185. prefix and POPPING.  Return 'first if found first time, 'none if no
  186. definition ever, T if another definition is found, and nil if no more
  187. definitions are found."
  188.   (let ((done nil)
  189.     (result nil))
  190.     (while
  191.     (not
  192.      (or
  193.       (setq result
  194.         (lisp-locate-definition    ;Same file
  195.          lisp-last-locator
  196.          lisp-last-definition lisp-last-file lisp-last-point back))
  197.       (let ((file (lisp-next-file back)))
  198.         (if file
  199.         (if (lisp-locate-definition 
  200.              lisp-last-locator lisp-last-definition 
  201.              file 1 back 
  202.              (prog1 pop (setq pop nil)))
  203.             (setq result 'first)
  204.             (setq result (if (not lisp-search) 'none)))
  205.         t)))))
  206.     (set-buffer (window-buffer (selected-window)))
  207.     result))
  208.  
  209. ;;;%%Next-definition
  210. (defun next-definition-lisp (back &optional pop)
  211.   "Edit the next definition from *Edit-Definitions* going BACK with
  212. prefix and optionally POPPING or call tags-loop-continue if using tags."
  213.   (interactive "P")
  214.   (if lisp-using-tags
  215.       (tags-loop-continue)
  216.       (let* ((result (lisp-next-definition back pop))
  217.          (symbol (car lisp-last-definition))
  218.          (type (cdr lisp-last-definition))
  219.          (name (if (not (eq type 't)) (lisp-buffer-symbol symbol))))
  220.     (cond ((or (eq result 'first) (eq result 't))
  221.            (if name
  222.            (message "Found %s %s definition" type name)
  223.            (message "Found %s" symbol)))
  224.           ((eq result 'none)
  225.            (error "Can't find %s %s definition" type name))
  226.           (t 
  227.            (if name 
  228.            (error "No more %s %s definitions" type name)
  229.            (message "Done")))))))
  230.  
  231. ;;;%%Edit-definitions
  232. (defun edit-definitions-lisp (symbol type &optional stay search locator)
  233.   "Find the source files for the TYPE definitions of SYMBOL.  If STAY,
  234. use the same window.  If SEARCH, do not look for symbol in inferior
  235. LISP.  The definition will be searched for through the inferior LISP
  236. and if not found it will be searched for in the current tags file and
  237. if not found in the files in lisp-edit-files set up by
  238. \(\\[lisp-directory]) or the buffers in one of lisp-source-modes if
  239. lisp-edit-files is T.  If lisp-edit-files is nil, no search will be
  240. done if not found through the inferior LISP.  TYPES are from
  241. ilisp-source-types which is an alist of symbol strings or list
  242. strings.  With a negative prefix, look for the current symbol as the
  243. first type in ilisp-source-types."
  244.   (interactive 
  245.    (let* ((types (ilisp-value 'ilisp-source-types t))
  246.       (default (if types (car (car types))))
  247.       (function (lisp-function-name))
  248.       (symbol (lisp-buffer-symbol function)))
  249.      (if (lisp-minus-prefix)
  250.      (list function default)
  251.      (list (ilisp-read-symbol 
  252.         (format "Edit Definition [%s]: " symbol)
  253.         function
  254.         nil
  255.         t)
  256.            (if types 
  257.            (ilisp-completing-read
  258.             (format "Type [%s]: " default)
  259.             types default))))))
  260.   (let* ((name (lisp-buffer-symbol symbol))
  261.      (symbol-name (lisp-symbol-name symbol))
  262.      (command (ilisp-value 'ilisp-find-source-command t))
  263.      (source
  264.       (if (and command (not search) (comint-check-proc ilisp-buffer))
  265.           (ilisp-send
  266.            (format command symbol-name
  267.                (lisp-symbol-package symbol)
  268.                type)
  269.            (concat "Finding " type " " name " definitions")
  270.            'source)
  271.           "nil"))
  272.      (result (lisp-last-line source))
  273.      (case-fold-search t)
  274.      (source-ok (not (or (ilisp-value 'comint-errorp t)
  275.                  (string-match "nil" (car result)))))
  276.      (tagged nil))
  277.     (unwind-protect
  278.      (if (and tags-file-name (not source-ok))
  279.          (progn (setq lisp-using-tags t)
  280.             (find-tag symbol-name nil stay)
  281.             (setq tagged t)))
  282.       (if (not tagged)
  283.       (progn
  284.         (setq lisp-last-definition (cons symbol type)
  285.           lisp-last-file nil
  286.           lisp-last-locator (or locator (ilisp-value 'ilisp-locator)))
  287.         (lisp-setup-edit-definitions
  288.          (format "%s %s definitions:" type name)
  289.          (if source-ok (cdr result) lisp-edit-files))
  290.         (next-definition-lisp nil t))))))
  291.  
  292. ;;;%%Searching
  293. (defun lisp-locate-search (pattern type first back)
  294.   "Find PATTERN in the current buffer."
  295.   (if back
  296.       (search-backward pattern nil t)
  297.       (search-forward pattern nil t)))
  298.  
  299. ;;;
  300. (defun lisp-locate-regexp (regexp type first back)
  301.   "Find REGEXP in the current buffer."
  302.   (if back
  303.       (re-search-backward regexp nil t)
  304.       (re-search-forward regexp nil t)))
  305.  
  306. ;;;
  307. (defvar lisp-last-pattern nil "Last search regexp.")
  308. (defun search-lisp (pattern regexp)
  309.   "Search for PATTERN through the files in lisp-edit-files if it is a
  310. list and the current buffers in one of lisp-source-modes otherwise.
  311. If lisp-edit-files is nil, no search will be done.  If called with a
  312. prefix, search for regexp.  If there is a tags file, call tags-search instead."
  313.   (interactive
  314.    (list (read-string (if current-prefix-arg 
  315.               "Search for regexp: "
  316.               "Search for: ") lisp-last-pattern)
  317.      current-prefix-arg))
  318.   (if tags-file-name
  319.       (progn (setq lisp-using-tags t)
  320.          (tags-search (if regexp pattern (regexp-quote pattern))))
  321.       (setq lisp-last-pattern pattern
  322.         lisp-last-definition (cons pattern t)
  323.         lisp-last-file nil
  324.         lisp-last-locator (if regexp
  325.                   'lisp-locate-regexp
  326.                   'lisp-locate-search))
  327.       (lisp-setup-edit-definitions (format "Searching for %s:" pattern) 
  328.                    lisp-edit-files)
  329.       (next-definition-lisp nil nil)))
  330.  
  331. ;;;%%Replacing
  332. (defvar lisp-last-replace nil "Last replace regexp.")
  333. (defun replace-lisp (old new regexp)
  334.   "Query replace OLD by NEW through the files in lisp-edit-files if it
  335. is a list and the current buffers in one of lisp-source-modes
  336. otherwise.  If lisp-edit-files is nil, no search will be done.  If
  337. called with a prefix, replace regexps.  If there is a tags file, then
  338. call tags-query-replace instead."
  339.   (interactive
  340.    (let ((old (read-string (if current-prefix-arg
  341.                    "Replace regexp: "
  342.                    "Replace: ") lisp-last-pattern)))
  343.      (list old
  344.        (read-string (if current-prefix-arg
  345.                 (format "Replace regexp %s by: " old)
  346.                 (format "Replace %s by: " old))
  347.             lisp-last-replace)
  348.        current-prefix-arg)))
  349.   (if tags-file-name
  350.       (progn (setq lisp-using-tags t)
  351.          (tags-query-replace (if regexp old (regexp-quote old))
  352.                  new))
  353.       (setq lisp-last-pattern old
  354.         lisp-last-replace new)
  355.       (lisp-setup-edit-definitions 
  356.        (format "Replacing %s by %s:\n\n" old new)
  357.        lisp-edit-files)
  358.       (let (file)
  359.     (while (setq file (lisp-next-file nil))
  360.       (lisp-find-file file)
  361.       (let ((point (point)))
  362.         (goto-char (point-min))
  363.         (if (if regexp 
  364.             (re-search-forward old nil t)
  365.             (search-forward old nil t))
  366.         (progn (beginning-of-line)
  367.                (if regexp
  368.                (query-replace-regexp old new)
  369.                (query-replace old new)))
  370.         (goto-char point)))))))
  371.  
  372. ;;;%%Edit-callers
  373. (defvar lisp-callers nil 
  374.   "T if we found callers through inferior LISP.")
  375.  
  376. ;;;
  377. (defun who-calls-lisp (function &optional no-show)
  378.   "Put the functions that call FUNCTION into the buffer *All-Callers*
  379. and show it unless NO-SHOW is T.  Return T if successful."
  380.   (interactive 
  381.    (let* ((function (lisp-defun-name))
  382.       (symbol (lisp-buffer-symbol function)))
  383.      (if (lisp-minus-prefix)
  384.      (list function)
  385.      (list (ilisp-read-symbol 
  386.         (format "Who Calls [%s]: " symbol)
  387.         function
  388.         t t)))))
  389.   (let* ((name (lisp-buffer-symbol function))
  390.      (command (ilisp-value 'ilisp-callers-command t))
  391.      (callers
  392.       (if command
  393.           (ilisp-send
  394.            (format command
  395.                (lisp-symbol-name function)
  396.                (lisp-symbol-package function))
  397.            (concat "Finding callers of " name)
  398.            'callers)))
  399.      (last-line (lisp-last-line callers))
  400.      (case-fold-search t))
  401.     (set-buffer (get-buffer-create "*All-Callers*"))
  402.     (erase-buffer)
  403.     (insert (format "All callers of function %s:\n\n" name))
  404.     (if (and command (not (ilisp-value 'comint-errorp t)))
  405.     (if (string-match "nil" (car last-line))
  406.         (error "%s has no callers" name)
  407.         (message "")
  408.         (insert (cdr last-line))
  409.         (goto-char (point-min))
  410.         ;; Remove garbage collection messages
  411.         (replace-regexp "^;[^\n]*\n" "")
  412.         (goto-char (point-min))
  413.         (forward-line 2)
  414.         (if (not no-show) 
  415.         (if temp-buffer-show-hook
  416.             (funcall temp-buffer-show-hook 
  417.                  (get-buffer "*All-Callers*"))
  418.             (view-buffer "*All-Callers*")))
  419.         t)
  420.     (insert "Using the current source files to find callers.")
  421.     nil)))
  422.  
  423. ;;;
  424. (defun next-caller-lisp (back &optional pop)
  425.   "Edit the next caller from *All-Callers*.  With prefix, edit
  426. the previous caller.  If it can't get caller information from the
  427. inferior LISP, this will search using the current source files.  See
  428. lisp-directory."
  429.   (interactive "P")
  430.   (if (not lisp-callers)
  431.       (next-definition-lisp back pop)
  432.       (set-buffer (get-buffer-create "*All-Callers*"))
  433.       (if back (forward-line -1))
  434.       (skip-chars-forward " \t\n")
  435.       (if (eobp)
  436.       (progn
  437.         (bury-buffer (current-buffer))
  438.         (error "No more callers"))
  439.       (let* ((start (point))
  440.          (caller-function
  441.           (progn
  442.             (skip-chars-forward "^ \t\n")
  443.             (buffer-substring start (point)))))
  444.         (bury-buffer (current-buffer))
  445.         (edit-definitions-lisp (lisp-string-to-symbol caller-function) 
  446.                   (car (car (ilisp-value 'ilisp-source-types)))
  447.                   (not pop))))))
  448.  
  449. ;;;
  450. (defun edit-callers-lisp (function)
  451.   "Edit the callers of FUNCTION.  With a minus prefix use the symbol
  452. at the start of the current defun."
  453.   (interactive
  454.    (let* ((function (lisp-defun-name)))
  455.      (if (lisp-minus-prefix)
  456.      (list function)
  457.      (list (ilisp-read-symbol 
  458.         (format "Edit callers of [%s]: "
  459.             (lisp-buffer-symbol function))
  460.         function
  461.         t)))))
  462.   (if (save-excursion (setq lisp-callers (who-calls-lisp function t)))
  463.       (progn 
  464.     (setq lisp-last-locator (ilisp-value 'ilisp-calls-locator))
  465.     (next-caller-lisp nil t))
  466.       (edit-definitions-lisp function "calls" nil t 
  467.                 (ilisp-value 'ilisp-calls-locator))))
  468.  
  469. ;;;%Locators
  470. (defun lisp-re (back format &rest args)
  471.   "Search BACK if T using FORMAT applied to ARGS."
  472.   (let ((regexp (apply 'format format args)))
  473.     (if back
  474.     (re-search-backward regexp nil t)
  475.     (re-search-forward regexp nil t))))
  476.  
  477. ;;;
  478. (defun lisp-locate-ilisp (symbol type first back)
  479.   "Find SYMBOL's TYPE definition in the current file and return T if
  480. successful.  A definition is of the form
  481. \(def<whitespace>(?name<whitespace>."
  482.   (lisp-re back
  483.        "^[ \t\n]*(def[^ \t\n]*[ \t\n]+(?%s[ \t\n]+" 
  484.        (regexp-quote (lisp-symbol-name symbol))))
  485.  
  486. ;;;
  487. (defun lisp-locate-calls (symbol type first back)
  488.   "Locate calls to SYMBOL."
  489.   (lisp-re back "\\(#'\\|(\\|'\\)%s\\([ \t\n]+\\|)\\)"
  490.        (regexp-quote (lisp-buffer-symbol symbol))))
  491.  
  492. ;;;%%Common LISP
  493. (defun lisp-locate-clisp (symbol type first back)
  494.   "Try to find SYMBOL's TYPE definition in the current buffer and return
  495. T if sucessful.  FIRST is T if this is the first time in a file.  BACK
  496. is T to go backwards."
  497.   (let* ((name (regexp-quote (lisp-symbol-name symbol)))
  498.      (prefix 
  499.       ;; Automatically generated defstruct accessors
  500.       (if (string-match "-" name)
  501.           (let ((struct (substring name 0 (1- (match-end 0)))))
  502.         (format 
  503.          "^\\(.\\)?[ \t\n]*(def[^ \t\n]*\\([ \t\n]+\\(.\\)?\\|\\|[ \t\n]*.[ \t\n]+\\)(?%s[ \t\n)]\\|:conc-name\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s-" 
  504.          struct struct))))
  505.      ;; Defclass accessors
  506.      (class
  507.       "\\(:accessor\\|:writer\\|:reader\\)\\([ \t\n]+\\(.\\)?+[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n)]"))
  508.     (or
  509.      (if (equal type "any")
  510.      (lisp-re 
  511.       back
  512.       (concat
  513.        "^\\(.\\)?[ \t\n]*(def[^ \t\n]*\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)\\((setf\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)\\|(?[ \t\n]*\\(.\\)?[ \t\n]*\\)%s[ \t\n)]"
  514.        (if prefix (concat "\\|" prefix))
  515.        "\\|"
  516.        class)
  517.       name name))
  518.      ;; (qualifiers* (type1 type2 ...))
  519.      (if (string-match "(\\([^(]*\\)\\(([^)]*)\\)" type)
  520.      (let* ((quals (substring type (match-beginning 1) (match-end 1)))
  521.         (class
  522.          (read (substring type (match-beginning 2) (match-end 2))))
  523.         (class-re nil)
  524.         (position 0))
  525.        (while (setq position (string-match 
  526.                   "\\([ \t\n]+.[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\|[ \t\n]+\\)"
  527.                   quals position))
  528.          (setq quals
  529.            (concat (substring quals 0 position)
  530.                "\\([ \t\n]+.[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\|[ \t\n]+\\)"
  531.                (substring quals (match-end 0)))))
  532.        (while class
  533.          (setq class-re 
  534.            (concat 
  535.             class-re 
  536.             (format
  537.              "[ \t\n]*\\(.\\)?[ \t\n]*([ \t\n]*\\(.\\)?[ \t\n]*[^ \t\n]*\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n]*\\(.\\)?[ \t\n]*"
  538.              (car class)))
  539.            class (cdr class)))
  540.        (lisp-re back 
  541.             "^\\(.\\)?[ \t\n]*(def[^ \t\n]*\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[^ \t\n]*([^ \t\n]*%s"
  542.             name quals class-re)))
  543.      ;; Setf method
  544.      (if (equal type "setf")
  545.      (lisp-re back 
  546.           "^\\(.\\)?[ \t\n]*(def[^ \t\n]*\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)(setf\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n]*\\(.\\)?[ \t\n]*)"
  547.           name))
  548.      ;; Function
  549.      (if (equal type "function")
  550.      (lisp-re back 
  551.           "^\\(.\\)?[ \t\n]*(defun\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n(]"
  552.           name))
  553.      ;; Macro
  554.      (if (equal type "macro")
  555.      (lisp-re back 
  556.           "^\\(.\\)?[ \t\n]*(defmacro\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n(]"
  557.           name))
  558.      ;; Variable
  559.      (if (equal type "variable")
  560.      (lisp-re back 
  561.           "^\\(.\\)?[ \t\n]*(def\\(\\(var\\)\\|\\(parameter\\)\\|constant\\)\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n(]"
  562.           name))
  563.      ;; Structure
  564.      (if (equal type "structure")
  565.      (lisp-re back 
  566.           "^\\(.\\)?[ \t\n]*(defstruct\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)(?[ \t\n]*\\(.\\)?[ \t\n]*%s[ \t\n(]"
  567.           name))
  568.      ;; Type
  569.      (if (equal type "type")
  570.      (lisp-re back 
  571.           "^\\(.\\)?[ \t\n]*(deftype\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n(]"
  572.           name))
  573.      ;; Class
  574.      (if (equal type "class")
  575.      (lisp-re back
  576.           "^\\(.\\)?[ \t\n]*(defclass\\([ \t\n]+\\(.\\)?[ \t\n]*\\|[ \t\n]*.[ \t\n]+\\)%s[ \t\n(]"
  577.           name))
  578.      ;; Standard def form
  579.      (if first (lisp-locate-ilisp symbol type first back))
  580.      ;; Automatically generated defstruct accessors
  581.      (if (and first prefix) (lisp-re back prefix))
  582.      ;; Defclass accessors
  583.      (lisp-re back class name)
  584.      ;; Give up!
  585.      )))
  586.  
  587.