comparison lisp/emacs-lisp/lisp.el @ 30979:72284d9d7a11

(defun-prompt-regexp, parens-require-spaces): Doc fix. (down-list, backward-up-list, up-list, kill-sexp) (backward-kill-sexp, mark-sexp)): Make arg optional. (lisp-complete-symbol): Add optional arg PREDICATE.
author Dave Love <fx@gnu.org>
date Sun, 20 Aug 2000 18:10:48 +0000
parents ed528bfe1b9e
children ed0ed1c70495
comparison
equal deleted inserted replaced
30978:e143c9fd35c9 30979:72284d9d7a11
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
24 24
25 ;;; Commentary: 25 ;;; Commentary:
26 26
27 ;; Lisp editing commands to go with Lisp major mode. 27 ;; Lisp editing commands to go with Lisp major mode. More-or-less
28 ;; applicable in other modes too.
28 29
29 ;;; Code: 30 ;;; Code:
30 31
31 ;; Note that this variable is used by non-lisp modes too. 32 ;; Note that this variable is used by non-lisp modes too.
32 (defcustom defun-prompt-regexp nil 33 (defcustom defun-prompt-regexp nil
33 "*Non-nil => regexp to ignore, before the character that starts a defun. 34 "*If non-nil, a regexp to ignore before the character that starts a defun.
34 This is only necessary if the opening paren or brace is not in column 0. 35 This is only necessary if the opening paren or brace is not in column 0.
35 See function `beginning-of-defun'." 36 See function `beginning-of-defun'."
36 :type '(choice (const nil) 37 :type '(choice (const nil)
37 regexp) 38 regexp)
38 :group 'lisp) 39 :group 'lisp)
39 (make-variable-buffer-local 'defun-prompt-regexp) 40 (make-variable-buffer-local 'defun-prompt-regexp)
40 41
41 (defcustom parens-require-spaces t 42 (defcustom parens-require-spaces t
42 "Non-nil => `insert-parentheses' should insert whitespace as needed." 43 "Non-nil means `insert-parentheses' should insert whitespace as needed."
43 :type 'boolean 44 :type 'boolean
44 :group 'lisp) 45 :group 'lisp)
45 46
46 (defun forward-sexp (&optional arg) 47 (defun forward-sexp (&optional arg)
47 "Move forward across one balanced expression (sexp). 48 "Move forward across one balanced expression (sexp).
58 move forward across N balanced expressions." 59 move forward across N balanced expressions."
59 (interactive "p") 60 (interactive "p")
60 (or arg (setq arg 1)) 61 (or arg (setq arg 1))
61 (forward-sexp (- arg))) 62 (forward-sexp (- arg)))
62 63
63 (defun mark-sexp (arg) 64 (defun mark-sexp (&optional arg)
64 "Set mark ARG sexps from point. 65 "Set mark ARG sexps from point.
65 The place mark goes is the same place \\[forward-sexp] would 66 The place mark goes is the same place \\[forward-sexp] would
66 move to with the same argument." 67 move to with the same argument."
67 (interactive "p") 68 (interactive "p")
68 (push-mark 69 (push-mark
69 (save-excursion 70 (save-excursion
70 (forward-sexp arg) 71 (forward-sexp (or arg 1))
71 (point)) 72 (point))
72 nil t)) 73 nil t))
73 74
74 (defun forward-list (&optional arg) 75 (defun forward-list (&optional arg)
75 "Move forward across one balanced group of parentheses. 76 "Move forward across one balanced group of parentheses.
85 Negative arg -N means move forward across N groups of parentheses." 86 Negative arg -N means move forward across N groups of parentheses."
86 (interactive "p") 87 (interactive "p")
87 (or arg (setq arg 1)) 88 (or arg (setq arg 1))
88 (forward-list (- arg))) 89 (forward-list (- arg)))
89 90
90 (defun down-list (arg) 91 (defun down-list (&optional arg)
91 "Move forward down one level of parentheses. 92 "Move forward down one level of parentheses.
92 With ARG, do this that many times. 93 With ARG, do this that many times.
93 A negative argument means move backward but still go down a level. 94 A negative argument means move backward but still go down a level.
94 In Lisp programs, an argument is required." 95 In Lisp programs, an argument is required."
95 (interactive "p") 96 (interactive "p")
97 (or arg (setq arg 1))
96 (let ((inc (if (> arg 0) 1 -1))) 98 (let ((inc (if (> arg 0) 1 -1)))
97 (while (/= arg 0) 99 (while (/= arg 0)
98 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) 100 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
99 (setq arg (- arg inc))))) 101 (setq arg (- arg inc)))))
100 102
101 (defun backward-up-list (arg) 103 (defun backward-up-list (&optional arg)
102 "Move backward out of one level of parentheses. 104 "Move backward out of one level of parentheses.
103 With ARG, do this that many times. 105 With ARG, do this that many times.
104 A negative argument means move forward but still to a less deep spot. 106 A negative argument means move forward but still to a less deep spot.
105 In Lisp programs, an argument is required." 107 In Lisp programs, an argument is required."
106 (interactive "p") 108 (interactive "p")
107 (up-list (- arg))) 109 (up-list (- (or arg 1))))
108 110
109 (defun up-list (arg) 111 (defun up-list (&optional arg)
110 "Move forward out of one level of parentheses. 112 "Move forward out of one level of parentheses.
111 With ARG, do this that many times. 113 With ARG, do this that many times.
112 A negative argument means move backward but still to a less deep spot. 114 A negative argument means move backward but still to a less deep spot.
113 In Lisp programs, an argument is required." 115 In Lisp programs, an argument is required."
114 (interactive "p") 116 (interactive "p")
117 (or arg (setq arg 1))
115 (let ((inc (if (> arg 0) 1 -1))) 118 (let ((inc (if (> arg 0) 1 -1)))
116 (while (/= arg 0) 119 (while (/= arg 0)
117 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) 120 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg)))
118 (setq arg (- arg inc))))) 121 (setq arg (- arg inc)))))
119 122
120 (defun kill-sexp (arg) 123 (defun kill-sexp (&optional arg)
121 "Kill the sexp (balanced expression) following the cursor. 124 "Kill the sexp (balanced expression) following the cursor.
122 With ARG, kill that many sexps after the cursor. 125 With ARG, kill that many sexps after the cursor.
123 Negative arg -N means kill N sexps before the cursor." 126 Negative arg -N means kill N sexps before the cursor."
124 (interactive "p") 127 (interactive "p")
125 (let ((opoint (point))) 128 (let ((opoint (point)))
126 (forward-sexp arg) 129 (forward-sexp (or arg 1))
127 (kill-region opoint (point)))) 130 (kill-region opoint (point))))
128 131
129 (defun backward-kill-sexp (arg) 132 (defun backward-kill-sexp (&optional arg)
130 "Kill the sexp (balanced expression) preceding the cursor. 133 "Kill the sexp (balanced expression) preceding the cursor.
131 With ARG, kill that many sexps before the cursor. 134 With ARG, kill that many sexps before the cursor.
132 Negative arg -N means kill N sexps after the cursor." 135 Negative arg -N means kill N sexps after the cursor."
133 (interactive "p") 136 (interactive "p")
134 (kill-sexp (- arg))) 137 (kill-sexp (- (or arg 1))))
135 138
136 (defvar beginning-of-defun-function nil 139 (defvar beginning-of-defun-function nil
137 "If non-nil, function for `beginning-of-defun-raw' to call. 140 "If non-nil, function for `beginning-of-defun-raw' to call.
138 This is used to find the beginning of the defun instead of using the 141 This is used to find the beginning of the defun instead of using the
139 normal recipe (see `beginning-of-defun'). Major modes can define this 142 normal recipe (see `beginning-of-defun'). Major modes can define this
335 (error (cond ((eq 'scan-error (car data)) 338 (error (cond ((eq 'scan-error (car data))
336 (goto-char (nth 2 data)) 339 (goto-char (nth 2 data))
337 (error "Unmatched bracket or quote")) 340 (error "Unmatched bracket or quote"))
338 (t (signal (car data) (cdr data))))))) 341 (t (signal (car data) (cdr data)))))))
339 342
340 (defun lisp-complete-symbol () 343 (defun lisp-complete-symbol (&optional predicate)
341 "Perform completion on Lisp symbol preceding point. 344 "Perform completion on Lisp symbol preceding point.
342 Compare that symbol against the known Lisp symbols. 345 Compare that symbol against the known Lisp symbols.
343 346
344 The context determines which symbols are considered. 347 When called from a program, optional arg PREDICATE is a predicate
345 If the symbol starts just after an open-parenthesis, only symbols 348 determining which symbols are considered, e.g. `commandp'.
346 with function definitions are considered. Otherwise, all symbols with 349 If PREDICATE is nil, the context determines which symbols are
347 function definitions, values or properties are considered." 350 considered. If the symbol starts just after an open-parenthesis, only
351 symbols with function definitions are considered. Otherwise, all
352 symbols with function definitions, values or properties are
353 considered."
348 (interactive) 354 (interactive)
349 (let* ((end (point)) 355 (let* ((end (point))
350 (buffer-syntax (syntax-table)) 356 (beg (with-syntax-table emacs-lisp-mode-syntax-table
351 (beg (unwind-protect
352 (save-excursion 357 (save-excursion
353 (set-syntax-table emacs-lisp-mode-syntax-table)
354 (backward-sexp 1) 358 (backward-sexp 1)
355 (while (= (char-syntax (following-char)) ?\') 359 (while (= (char-syntax (following-char)) ?\')
356 (forward-char 1)) 360 (forward-char 1))
357 (point)) 361 (point))))
358 (set-syntax-table buffer-syntax))) 362 (pattern (buffer-substring-no-properties beg end))
359 (pattern (buffer-substring beg end))
360 (predicate 363 (predicate
361 (if (eq (char-after (1- beg)) ?\() 364 (or predicate
362 'fboundp 365 (if (eq (char-after (1- beg)) ?\()
363 (function (lambda (sym) 366 'fboundp
364 (or (boundp sym) (fboundp sym) 367 (function (lambda (sym)
365 (symbol-plist sym)))))) 368 (or (boundp sym) (fboundp sym)
369 (symbol-plist sym)))))))
366 (completion (try-completion pattern obarray predicate))) 370 (completion (try-completion pattern obarray predicate)))
367 (cond ((eq completion t)) 371 (cond ((eq completion t))
368 ((null completion) 372 ((null completion)
369 (message "Can't find completion for \"%s\"" pattern) 373 (message "Can't find completion for \"%s\"" pattern)
370 (ding)) 374 (ding))