comparison lisp/progmodes/make-mode.el @ 106381:752b44ae030c

(makefile-special-targets-list): No need for it to be an alist any more. (makefile-complete): Use completion-in-region.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 03 Dec 2009 03:02:34 +0000
parents afa0e028ba97
children 1d1d5d9bd884
comparison
equal deleted inserted replaced
106380:f14ff1a09863 106381:752b44ae030c
229 229
230 ;; 230 ;;
231 ;; Special targets for DMake, Sun's make ... 231 ;; Special targets for DMake, Sun's make ...
232 ;; 232 ;;
233 (defcustom makefile-special-targets-list 233 (defcustom makefile-special-targets-list
234 '(("DEFAULT") ("DONE") ("ERROR") ("EXPORT") 234 '("DEFAULT" "DONE" "ERROR" "EXPORT"
235 ("FAILED") ("GROUPEPILOG") ("GROUPPROLOG") ("IGNORE") 235 "FAILED" "GROUPEPILOG" "GROUPPROLOG" "IGNORE"
236 ("IMPORT") ("INCLUDE") ("INCLUDEDIRS") ("INIT") 236 "IMPORT" "INCLUDE" "INCLUDEDIRS" "INIT"
237 ("KEEP_STATE") ("MAKEFILES") ("MAKE_VERSION") ("NO_PARALLEL") 237 "KEEP_STATE" "MAKEFILES" "MAKE_VERSION" "NO_PARALLEL"
238 ("PARALLEL") ("PHONY") ("PRECIOUS") ("REMOVE") 238 "PARALLEL" "PHONY" "PRECIOUS" "REMOVE"
239 ("SCCS_GET") ("SILENT") ("SOURCE") ("SUFFIXES") 239 "SCCS_GET" "SILENT" "SOURCE" "SUFFIXES"
240 ("WAIT") ("c.o") ("C.o") ("m.o") 240 "WAIT" "c.o" "C.o" "m.o"
241 ("el.elc") ("y.c") ("s.o")) 241 "el.elc" "y.c" "s.o")
242 "*List of special targets. 242 "List of special targets.
243 You will be offered to complete on one of those in the minibuffer whenever 243 You will be offered to complete on one of those in the minibuffer whenever
244 you enter a \".\" at the beginning of a line in `makefile-mode'." 244 you enter a \".\" at the beginning of a line in `makefile-mode'."
245 :type '(repeat (list string)) 245 :type '(repeat (list string))
246 :group 'makefile) 246 :group 'makefile)
247 (put 'makefile-special-targets-list 'risky-local-variable t) 247 (put 'makefile-special-targets-list 'risky-local-variable t)
1183 (interactive) 1183 (interactive)
1184 (let* ((beg (save-excursion 1184 (let* ((beg (save-excursion
1185 (skip-chars-backward "^$(){}:#= \t\n") 1185 (skip-chars-backward "^$(){}:#= \t\n")
1186 (point))) 1186 (point)))
1187 (try (buffer-substring beg (point))) 1187 (try (buffer-substring beg (point)))
1188 (do-macros nil) 1188 (paren nil)
1189 (paren nil)) 1189 (do-macros
1190 1190 (save-excursion
1191 (save-excursion 1191 (goto-char beg)
1192 (goto-char beg) 1192 (let ((pc (preceding-char)))
1193 (let ((pc (preceding-char))) 1193 (cond
1194 (cond 1194 ;; Preceding "$" means macros only.
1195 ;; Beginning of line means anything. 1195 ((= pc ?$)
1196 ((bolp) 1196 t)
1197 ()) 1197
1198 1198 ;; Preceding "$(" or "${" means macros only.
1199 ;; Preceding "$" means macros only. 1199 ((and (memq pc '(?\{ ?\())
1200 ((= pc ?$) 1200 (progn
1201 (setq do-macros t)) 1201 (setq paren (if (eq paren ?\{) ?\} ?\)))
1202 1202 (backward-char)
1203 ;; Preceding "$(" or "${" means macros only. 1203 (= (preceding-char) ?$)))
1204 ((and (or (= pc ?{) 1204 t)))))
1205 (= pc ?\()) 1205
1206 (progn 1206 (table (apply-partially 'completion-table-with-terminator
1207 (setq paren pc) 1207 (cond
1208 (backward-char) 1208 (do-macros (or paren ""))
1209 (and (not (bolp)) 1209 ((save-excursion (goto-char beg) (bolp)) ":")
1210 (= (preceding-char) ?$)))) 1210 (t " "))
1211 (setq do-macros t))))) 1211 (append (if do-macros
1212 1212 '()
1213 ;; Try completion. 1213 makefile-target-table)
1214 (let* ((table (append (if do-macros 1214 makefile-macro-table))))
1215 '() 1215 (completion-in-region beg (point) table)))
1216 makefile-target-table)
1217 makefile-macro-table))
1218 (completion (try-completion try table)))
1219 (cond
1220 ;; Exact match, so insert closing paren or colon.
1221 ((eq completion t)
1222 (insert (if do-macros
1223 (if (eq paren ?{)
1224 ?}
1225 ?\))
1226 (if (save-excursion
1227 (goto-char beg)
1228 (bolp))
1229 ":"
1230 " "))))
1231
1232 ;; No match.
1233 ((null completion)
1234 (message "Can't find completion for \"%s\"" try)
1235 (ding))
1236
1237 ;; Partial completion.
1238 ((not (string= try completion))
1239 ;; FIXME it would be nice to supply the closing paren if an
1240 ;; exact, unambiguous match were found. That is not possible
1241 ;; right now. Ditto closing ":" for targets.
1242 (delete-region beg (point))
1243
1244 ;; DO-MACROS means doing macros only. If not that, then check
1245 ;; to see if this completion is a macro. Special insertion
1246 ;; must be done for macros.
1247 (if (or do-macros
1248 (assoc completion makefile-macro-table))
1249 (let ((makefile-use-curly-braces-for-macros-p
1250 (or (eq paren ?{)
1251 makefile-use-curly-braces-for-macros-p)))
1252 (delete-backward-char 2)
1253 (makefile-do-macro-insertion completion)
1254 (delete-backward-char 1))
1255
1256 ;; Just insert targets.
1257 (insert completion)))
1258
1259 ;; Can't complete any more, so make completion list. FIXME
1260 ;; this doesn't do the right thing when the completion is
1261 ;; actually inserted. I don't think there is an easy way to do
1262 ;; that.
1263 (t
1264 (message "Making completion list...")
1265 (let ((list (all-completions try table)))
1266 (with-output-to-temp-buffer "*Completions*"
1267 (display-completion-list list try)))
1268 (message "Making completion list...done"))))))
1269 1216
1270 1217
1271 1218
1272 ;; Backslashification. Stolen from cc-mode.el. 1219 ;; Backslashification. Stolen from cc-mode.el.
1273 1220