comparison lisp/emacs-lisp/lisp.el @ 31982:ed0ed1c70495

(lisp-complete-symbol): Distinguish the let-binding case from the funcall case. (forward-sexp-function): New variable. (forward-sexp): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 29 Sep 2000 03:30:04 +0000
parents 72284d9d7a11
children d481da7b59b0
comparison
equal deleted inserted replaced
31981:533a4e5f06e2 31982:ed0ed1c70495
42 (defcustom parens-require-spaces t 42 (defcustom parens-require-spaces t
43 "Non-nil means `insert-parentheses' should insert whitespace as needed." 43 "Non-nil means `insert-parentheses' should insert whitespace as needed."
44 :type 'boolean 44 :type 'boolean
45 :group 'lisp) 45 :group 'lisp)
46 46
47 (defvar forward-sexp-function nil
48 "If non-nil, `forward-sexp' delegates to this function.
49 Should take the same arguments and behave similarly to `forward-sexp'.")
50
47 (defun forward-sexp (&optional arg) 51 (defun forward-sexp (&optional arg)
48 "Move forward across one balanced expression (sexp). 52 "Move forward across one balanced expression (sexp).
49 With ARG, do it that many times. Negative arg -N means 53 With ARG, do it that many times. Negative arg -N means
50 move backward across N balanced expressions." 54 move backward across N balanced expressions."
51 (interactive "p") 55 (interactive "p")
52 (or arg (setq arg 1)) 56 (or arg (setq arg 1))
53 (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) 57 (if forward-sexp-function
54 (if (< arg 0) (backward-prefix-chars))) 58 (funcall forward-sexp-function arg)
59 (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
60 (if (< arg 0) (backward-prefix-chars))))
55 61
56 (defun backward-sexp (&optional arg) 62 (defun backward-sexp (&optional arg)
57 "Move backward across one balanced expression (sexp). 63 "Move backward across one balanced expression (sexp).
58 With ARG, do it that many times. Negative arg -N means 64 With ARG, do it that many times. Negative arg -N means
59 move forward across N balanced expressions." 65 move forward across N balanced expressions."
352 symbols with function definitions, values or properties are 358 symbols with function definitions, values or properties are
353 considered." 359 considered."
354 (interactive) 360 (interactive)
355 (let* ((end (point)) 361 (let* ((end (point))
356 (beg (with-syntax-table emacs-lisp-mode-syntax-table 362 (beg (with-syntax-table emacs-lisp-mode-syntax-table
357 (save-excursion 363 (save-excursion
358 (backward-sexp 1) 364 (backward-sexp 1)
359 (while (= (char-syntax (following-char)) ?\') 365 (while (= (char-syntax (following-char)) ?\')
360 (forward-char 1)) 366 (forward-char 1))
361 (point)))) 367 (point))))
362 (pattern (buffer-substring-no-properties beg end)) 368 (pattern (buffer-substring-no-properties beg end))
363 (predicate 369 (predicate
364 (or predicate 370 (or predicate
365 (if (eq (char-after (1- beg)) ?\() 371 (save-excursion
366 'fboundp 372 (goto-char beg)
367 (function (lambda (sym) 373 (if (not (eq (char-before) ?\())
368 (or (boundp sym) (fboundp sym) 374 (lambda (sym) ;why not just nil ? -sm
369 (symbol-plist sym))))))) 375 (or (boundp sym) (fboundp sym)
376 (symbol-plist sym)))
377 ;; Looks like a funcall position. Let's double check.
378 (backward-char 1) ;skip paren
379 (if (condition-case nil
380 (progn (up-list -2) (forward-char 1)
381 (eq (char-after) ?\())
382 (error nil))
383 ;; If the first element of the parent list is an open
384 ;; parenthesis we are probably not in a funcall position.
385 ;; Maybe a `let' varlist or something.
386 nil
387 ;; Else, we assume that a function name is expected.
388 'fboundp)))))
370 (completion (try-completion pattern obarray predicate))) 389 (completion (try-completion pattern obarray predicate)))
371 (cond ((eq completion t)) 390 (cond ((eq completion t))
372 ((null completion) 391 ((null completion)
373 (message "Can't find completion for \"%s\"" pattern) 392 (message "Can't find completion for \"%s\"" pattern)
374 (ding)) 393 (ding))