aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/emacs-lisp/lisp.el126
2 files changed, 83 insertions, 49 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0ccf22ad007..09fd7fe55c2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12007-11-26 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/lisp.el (end-of-defun): Restructure so that
4 end-of-defun-function is called consistently, even for negative arguments.
5 (end-of-defun-function): Default to forward-sexp.
6
12007-11-26 Juanma Barranquero <lekktu@gmail.com> 72007-11-26 Juanma Barranquero <lekktu@gmail.com>
2 8
3 * emacs-lisp/bytecomp.el (batch-byte-recompile-directory): Doc fix. 9 * emacs-lisp/bytecomp.el (batch-byte-recompile-directory): Doc fix.
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index e607245d0ed..65bbade816e 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -297,11 +297,11 @@ is called as a function to find the defun's beginning."
297 (goto-char (if arg-+ve floor ceiling)) 297 (goto-char (if arg-+ve floor ceiling))
298 nil)))))))) 298 nil))))))))
299 299
300(defvar end-of-defun-function nil 300(defvar end-of-defun-function #'forward-sexp
301 "If non-nil, function for function `end-of-defun' to call. 301 "Function for `end-of-defun' to call.
302This is used to find the end of the defun instead of using the normal 302This is used to find the end of the defun.
303recipe (see `end-of-defun'). Major modes can define this if the 303It is called with no argument, right after calling `beginning-of-defun-raw'.
304normal method is not appropriate.") 304So the function can assume that point is at the beginning of the defun body.")
305 305
306(defun buffer-end (arg) 306(defun buffer-end (arg)
307 "Return the \"far end\" position of the buffer, in direction ARG. 307 "Return the \"far end\" position of the buffer, in direction ARG.
@@ -326,45 +326,38 @@ is called as a function to find the defun's end."
326 (and transient-mark-mode mark-active) 326 (and transient-mark-mode mark-active)
327 (push-mark)) 327 (push-mark))
328 (if (or (null arg) (= arg 0)) (setq arg 1)) 328 (if (or (null arg) (= arg 0)) (setq arg 1))
329 (if end-of-defun-function 329 (while (> arg 0)
330 (if (> arg 0) 330 (let ((pos (point)))
331 (dotimes (i arg) 331 (end-of-line 1)
332 (funcall end-of-defun-function)) 332 (beginning-of-defun-raw 1)
333 ;; Better not call beginning-of-defun-function 333 (while (unless (eobp)
334 ;; directly, in case it's not defined. 334 (funcall end-of-defun-function)
335 (beginning-of-defun (- arg))) 335 (skip-chars-forward " \t")
336 (let ((first t)) 336 (if (looking-at "\\s<\\|\n")
337 (while (and (> arg 0) (< (point) (point-max))) 337 (forward-line 1))
338 (let ((pos (point))) 338 ;; If we started after the end of the previous function, then
339 (while (progn 339 ;; try again with the next one.
340 (if (and first 340 (when (<= (point) pos)
341 (progn 341 (or (bobp) (forward-char -1))
342 (end-of-line 1) 342 (beginning-of-defun-raw -1)
343 (beginning-of-defun-raw 1))) 343 'try-again))))
344 nil 344 (setq arg (1- arg)))
345 (or (bobp) (forward-char -1)) 345 (while (< arg 0)
346 (beginning-of-defun-raw -1)) 346 (let ((pos (point)))
347 (setq first nil) 347 (while (unless (bobp)
348 (forward-list 1) 348 (beginning-of-line 1)
349 (skip-chars-forward " \t") 349 (beginning-of-defun-raw 1)
350 (if (looking-at "\\s<\\|\n") 350 (let ((beg (point)))
351 (forward-line 1)) 351 (funcall end-of-defun-function)
352 (<= (point) pos)))) 352 (skip-chars-forward " \t")
353 (setq arg (1- arg))) 353 (if (looking-at "\\s<\\|\n")
354 (while (< arg 0) 354 (forward-line 1))
355 (let ((pos (point))) 355 ;; If we started from within the function just found, then
356 (beginning-of-defun-raw 1) 356 ;; try again with the previous one.
357 (forward-sexp 1) 357 (when (>= (point) pos)
358 (forward-line 1) 358 (goto-char beg)
359 (if (>= (point) pos) 359 'try-again)))))
360 (if (beginning-of-defun-raw 2) 360 (setq arg (1+ arg))))
361 (progn
362 (forward-list 1)
363 (skip-chars-forward " \t")
364 (if (looking-at "\\s<\\|\n")
365 (forward-line 1)))
366 (goto-char (point-min)))))
367 (setq arg (1+ arg))))))
368 361
369(defun mark-defun (&optional allow-extend) 362(defun mark-defun (&optional allow-extend)
370 "Put mark at end of this defun, point at beginning. 363 "Put mark at end of this defun, point at beginning.
@@ -573,12 +566,47 @@ character."
573 ;; "Unbalanced parentheses", but those may not be so 566 ;; "Unbalanced parentheses", but those may not be so
574 ;; accurate/helpful, e.g. quotes may actually be 567 ;; accurate/helpful, e.g. quotes may actually be
575 ;; mismatched. 568 ;; mismatched.
576 (error "Unmatched bracket or quote")) 569 (error "Unmatched bracket or quote"))))
577 (error (cond ((eq 'scan-error (car data))
578 (goto-char (nth 2 data))
579 (error "Unmatched bracket or quote"))
580 (t (signal (car data) (cdr data)))))))
581 570
571(defun field-complete (table &optional predicate)
572 (let* ((pattern (field-string-no-properties))
573 (completion (try-completion pattern table predicate)))
574 (cond ((eq completion t))
575 ((null completion)
576 (message "Can't find completion for \"%s\"" pattern)
577 (ding))
578 ((not (string= pattern completion))
579 (delete-region (field-beginning) (field-end))
580 (insert completion)
581 ;; Don't leave around a completions buffer that's out of date.
582 (let ((win (get-buffer-window "*Completions*" 0)))
583 (if win (with-selected-window win (bury-buffer)))))
584 (t
585 (let ((minibuf-is-in-use
586 (eq (minibuffer-window) (selected-window))))
587 (unless minibuf-is-in-use
588 (message "Making completion list..."))
589 (let ((list (all-completions pattern table predicate)))
590 (setq list (sort list 'string<))
591 (or (eq predicate 'fboundp)
592 (let (new)
593 (while list
594 (setq new (cons (if (fboundp (intern (car list)))
595 (list (car list) " <f>")
596 (car list))
597 new))
598 (setq list (cdr list)))
599 (setq list (nreverse new))))
600 (if (> (length list) 1)
601 (with-output-to-temp-buffer "*Completions*"
602 (display-completion-list list pattern))
603 ;; Don't leave around a completions buffer that's
604 ;; out of date.
605 (let ((win (get-buffer-window "*Completions*" 0)))
606 (if win (with-selected-window win (bury-buffer))))))
607 (unless minibuf-is-in-use
608 (message "Making completion list...%s" "done")))))))
609
582(defun lisp-complete-symbol (&optional predicate) 610(defun lisp-complete-symbol (&optional predicate)
583 "Perform completion on Lisp symbol preceding point. 611 "Perform completion on Lisp symbol preceding point.
584Compare that symbol against the known Lisp symbols. 612Compare that symbol against the known Lisp symbols.