diff lisp/indent.el @ 106482:806e9f7990d8

* minibuffer.el (completion-at-point-functions): New var. (completion-at-point): New command. * indent.el (indent-for-tab-command): Handle the new `complete' behavior. * progmodes/python.el (python-mode-map): Use completion-at-point. (python-completion-at-point): Rename from python-partial-symbol and adjust for use in completion-at-point-functions. (python-mode): Setup completion-at-point for Python completion. * emacs-lisp/lisp.el (lisp-completion-at-point): New function extracted from lisp-complete-symbol. (lisp-complete-symbol): Use it. * emacs-lisp/lisp-mode.el (emacs-lisp-mode): Use define-derived-mode, setup completion-at-point for Elisp completion. (emacs-lisp-mode-map, lisp-interaction-mode-map): Use completion-at-point. * ielm.el (ielm-map): Use completion-at-point. (inferior-emacs-lisp-mode): Setup completion-at-point for Elisp completion. * progmodes/sym-comp.el: Move to... * obsolete/sym-comp.el: Move from progmodes.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 07 Dec 2009 20:06:26 +0000
parents f1b56c6c0ebc
children 1d1d5d9bd884
line wrap: on
line diff
--- a/lisp/indent.el	Mon Dec 07 19:21:57 2009 +0000
+++ b/lisp/indent.el	Mon Dec 07 20:06:26 2009 +0000
@@ -49,6 +49,9 @@
 If t, hitting TAB always just indents the current line.
 If nil, hitting TAB indents the current line if point is at the left margin
 or in the line's indentation, otherwise it inserts a \"real\" TAB character.
+If `complete', TAB first tries to indent the current line, and if the line
+was already indented, then try to complete the thing at point.
+
 Some programming language modes have their own variable to control this,
 e.g., `c-tab-always-indent', and do not respect this variable."
   :group 'indent
@@ -103,26 +106,32 @@
 		 (eq this-command last-command))))
     (insert-tab arg))
    (t
-    (let ((end-marker
-	   (and arg
-		(save-excursion
-		  (forward-line 0) (forward-sexp) (point-marker))))
-	  (old-indent
-	   (current-indentation)))
+    (let ((old-tick (buffer-chars-modified-tick))
+          (old-point (point))
+	  (old-indent (current-indentation)))
 
       ;; Indent the line.
       (funcall indent-line-function)
 
-      ;; If a prefix argument was given, rigidly indent the following
-      ;; sexp to match the change in the current line's indentation.
-      ;;
-      (when arg
-	(let ((indentation-change (- (current-indentation) old-indent)))
-	  (unless (zerop indentation-change)
-	    (save-excursion
-	      (forward-line 1)
-	      (when (< (point) end-marker)
-		(indent-rigidly (point) end-marker indentation-change))))))))))
+      (cond
+       ;; If the text was already indented right, try completion.
+       ((and (eq tab-always-indent 'complete)
+             (eq old-point (point))
+             (eq old-tick (buffer-chars-modified-tick)))
+        (completion-at-point))
+
+       ;; If a prefix argument was given, rigidly indent the following
+       ;; sexp to match the change in the current line's indentation.
+       (arg
+        (let ((end-marker
+               (save-excursion
+                 (forward-line 0) (forward-sexp) (point-marker)))
+              (indentation-change (- (current-indentation) old-indent)))
+          (save-excursion
+            (forward-line 1)
+            (when (and (not (zerop indentation-change))
+                       (< (point) end-marker))
+              (indent-rigidly (point) end-marker indentation-change))))))))))
 
 (defun insert-tab (&optional arg)
   (let ((count (prefix-numeric-value arg)))