-;;; make-mode.el --- makefile editing commands for Emacs
+;;; make-mode.el --- makefile editing commands for Emacs -*- lexical-binding:t -*-
;; Copyright (C) 1992, 1994, 1999-2011 Free Software Foundation, Inc.
(define-key map "\C-c\C-m\C-p" 'makefile-makepp-mode)
(define-key map "\M-p" 'makefile-previous-dependency)
(define-key map "\M-n" 'makefile-next-dependency)
- (define-key map "\e\t" 'makefile-complete)
+ (define-key map "\e\t" 'completion-at-point)
;; Make menus.
(define-key map [menu-bar makefile-mode]
'(menu-item "Find Targets and Macros" makefile-pickup-everything
:help "Notice names of all macros and targets in Makefile"))
(define-key map [menu-bar makefile-mode complete]
- '(menu-item "Complete Target or Macro" makefile-complete
+ '(menu-item "Complete Target or Macro" completion-at-point
:help "Perform completion on Makefile construct preceding point"))
(define-key map [menu-bar makefile-mode backslash]
'(menu-item "Backslash Region" makefile-backslash-region
List of special targets. You will be offered to complete
on one of those in the minibuffer whenever you enter a `.'.
at the beginning of a line in Makefile mode."
+ (add-hook 'completion-at-point-functions
+ #'makefile-completions-at-point nil t)
(add-hook 'write-file-functions
'makefile-warn-suspicious-lines nil t)
(add-hook 'write-file-functions
;;; Completion.
-(defun makefile-complete ()
- "Perform completion on Makefile construct preceding point.
-Can complete variable and target names.
-The context determines which are considered."
- (interactive)
+(defun makefile-completions-at-point ()
(let* ((beg (save-excursion
(skip-chars-backward "^$(){}:#= \t\n")
(point)))
;; Preceding "$(" or "${" means macros only.
((and (memq pc '(?\{ ?\())
(progn
- (setq paren (if (eq paren ?\{) ?\} ?\)))
+ (setq paren (if (eq pc ?\{) ?\} ?\)))
(backward-char)
(= (preceding-char) ?$)))
t)))))
-
- (table (apply-partially 'completion-table-with-terminator
- (cond
- (do-macros (or paren ""))
- ((save-excursion (goto-char beg) (bolp)) ":")
- (t " "))
- (append (if do-macros
- '()
- makefile-target-table)
- makefile-macro-table))))
- (completion-in-region beg (point) table)))
-
+ (suffix (cond
+ (do-macros (if paren (string paren)))
+ ((save-excursion (goto-char beg) (bolp)) ":")
+ (t " "))))
+ (list beg (point)
+ (append (if do-macros '() makefile-target-table)
+ makefile-macro-table)
+ :exit-function
+ (if suffix
+ (lambda (_s finished)
+ (when (memq finished '(sole finished))
+ (if (looking-at (regexp-quote suffix))
+ (goto-char (match-end 0))
+ (insert suffix))))))))
+
+(define-obsolete-function-alias 'makefile-complete 'completion-at-point "24.1")
\f
;; Backslashification. Stolen from cc-mode.el.