]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/meta-mode.el
* font-lock.el (font-lock-maximum-decoration): Mention what numeric levels mean.
[gnu-emacs] / lisp / progmodes / meta-mode.el
index 7e679f7fe3137a275ec8fb068796bf8a496cc059..ab640c0e270d1be4f0b35cf3d597603c0046a429 100644 (file)
@@ -1,7 +1,6 @@
-;;; meta-mode.el --- major mode for editing Metafont or MetaPost sources
+;;; meta-mode.el --- major mode for editing Metafont or MetaPost sources -*- lexical-binding:t -*-
 
-;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-;;   2009, 2010  Free Software Foundation, Inc.
+;; Copyright (C) 1997, 2001-2011  Free Software Foundation, Inc.
 
 ;; Author: Ulrik Vieth <vieth@thphy.uni-duesseldorf.de>
 ;; Version: 1.0
@@ -472,16 +471,13 @@ If the list was changed, sort the list and remove duplicates first."
   (string-lessp (car a) (car b)))
 
 
-(defun meta-complete-symbol ()
-  "Perform completion on Metafont or MetaPost symbol preceding point."
-  ;; FIXME: Use completion-at-point-functions.
-  (interactive "*")
+(defun meta-completions-at-point ()
   (let ((list meta-complete-list)
         entry)
     (while list
       (setq entry (car list)
             list (cdr list))
-      (if (meta-looking-at-backward (car entry) 200)
+      (if (looking-back (car entry) (max (point-min) (- (point) 200)))
           (setq list nil)))
     (if (numberp (nth 1 entry))
         (let* ((sub (nth 1 entry))
@@ -489,31 +485,19 @@ If the list was changed, sort the list and remove duplicates first."
                (begin (match-beginning sub))
                (end (match-end sub))
                (list (funcall (nth 2 entry))))
-          (completion-in-region
-           begin end
-           (if (zerop (length close)) list
-             (apply-partially 'completion-table-with-terminator
-                              close list))))
-      (funcall (nth 1 entry)))))
-
-
-(defun meta-looking-at-backward (regexp &optional limit)
-  ;; utility function used in `meta-complete-symbol'
-  (let ((pos (point)))
-    (save-excursion
-      (and (re-search-backward
-            regexp (if limit (max (point-min) (- (point) limit))) t)
-           (eq (match-end 0) pos)))))
-
-(defun meta-match-buffer (n)
-  ;; utility function used in `meta-complete-symbol'
-  (if (match-beginning n)
-      (let ((str (buffer-substring (match-beginning n) (match-end n))))
-        (set-text-properties 0 (length str) nil str)
-        (copy-sequence str))
-    ""))
-
-
+          (list
+           begin end list
+           :exit-function
+           (unless (zerop (length close))
+             (lambda (_s finished)
+               (when (memq finished '(sole finished))
+                 (if (looking-at (regexp-quote close))
+                     (goto-char (match-end 0))
+                   (insert close)))))))
+      (nth 1 entry))))
+
+(define-obsolete-function-alias 'meta-complete-symbol
+  'completion-at-point "24.1")
 \f
 ;;; Indentation.
 
@@ -907,7 +891,7 @@ The environment marked is the one that contains point or follows point."
     (define-key map "\C-c;"     'meta-comment-region)
     (define-key map "\C-c:"     'meta-uncomment-region)
     ;; Symbol Completion:
-    (define-key map "\M-\t"     'meta-complete-symbol)
+    (define-key map "\M-\t"     'completion-at-point)
     ;; Shell Commands:
     ;; (define-key map "\C-c\C-c"  'meta-command-file)
     ;; (define-key map "\C-c\C-k"  'meta-kill-job)
@@ -936,7 +920,7 @@ The environment marked is the one that contains point or follows point."
        ["Uncomment Region"              meta-uncomment-region
         :active (meta-mark-active)]
        "--"
-       ["Complete Symbol"               meta-complete-symbol t]
+       ["Complete Symbol"               completion-at-point t]
 ;      "--"
 ;      ["Command on Buffer"             meta-command-file t]
 ;      ["Kill Job"                      meta-kill-job t]
@@ -995,6 +979,7 @@ The environment marked is the one that contains point or follows point."
 
   (set (make-local-variable 'parse-sexp-ignore-comments) t)
 
+  (add-hook 'completion-at-point-functions #'meta-completions-at-point nil t)
   (set (make-local-variable 'comment-indent-function) #'meta-comment-indent)
   (set (make-local-variable 'indent-line-function) #'meta-indent-line)
   ;; No need to define a mode-specific 'indent-region-function.