comparison lisp/simple.el @ 93397:b532cf17d6ad

(minibuffer-default-add-function): New variable with the default to minibuffer-default-add-completions. (minibuffer-default-add-done): New variable. Make it buffer-local. (minibuffer-default-add-completions): New function. (goto-history-element): Set minibuffer-default-add-done to t and call a function in minibuffer-default-add-function when the specified absolute history position is greater than the length of the minibuffer-default list and minibuffer-default-add-done is nil. Change "^End of history; no next item$" to "^End of defaults; no next item$".
author Juri Linkov <juri@jurta.org>
date Sat, 29 Mar 2008 22:56:17 +0000
parents e550714b0fde
children 715d9d088f88
comparison
equal deleted inserted replaced
93396:c15f559a5ada 93397:b532cf17d6ad
1302 (prefix-numeric-value current-prefix-arg)))) 1302 (prefix-numeric-value current-prefix-arg))))
1303 (previous-matching-history-element regexp (- n))) 1303 (previous-matching-history-element regexp (- n)))
1304 1304
1305 (defvar minibuffer-temporary-goal-position nil) 1305 (defvar minibuffer-temporary-goal-position nil)
1306 1306
1307 (defvar minibuffer-default-add-function 'minibuffer-default-add-completions
1308 "Function run by `goto-history-element' before consuming `minibuffer-default'.
1309 This is useful to dynamically add more elements to the list `minibuffer-default'
1310 when `goto-history-element' reaches the end of this list.
1311 Before calling this function `goto-history-element' sets the variable
1312 `minibuffer-default-add-done' to t, so it will call this function only
1313 once. In special cases, when this function needs to be called more
1314 than once, it can set `minibuffer-default-add-done' to nil explicitly,
1315 overriding the setting of this variable to t in `goto-history-element'.")
1316
1317 (defvar minibuffer-default-add-done nil
1318 "When nil, add more elements to the end of the list of default values.
1319 The value nil causes `goto-history-element' to add more elements to
1320 the list of defaults when it reaches the end of this list. It does
1321 this by calling a function defined by `minibuffer-default-add-function'.")
1322
1323 (make-variable-buffer-local 'minibuffer-default-add-done)
1324
1325 (defun minibuffer-default-add-completions ()
1326 "Return a list of all completions without the default value.
1327 This function is used to add all elements of the completion table to
1328 the end of the list of defaults just after the default value."
1329 (interactive)
1330 (let ((def minibuffer-default)
1331 (all (all-completions ""
1332 minibuffer-completion-table
1333 minibuffer-completion-predicate
1334 t)))
1335 (if (listp def)
1336 (append def all)
1337 (cons def (delete def all)))))
1338
1307 (defun goto-history-element (nabs) 1339 (defun goto-history-element (nabs)
1308 "Puts element of the minibuffer history in the minibuffer. 1340 "Puts element of the minibuffer history in the minibuffer.
1309 The argument NABS specifies the absolute history position." 1341 The argument NABS specifies the absolute history position."
1310 (interactive "p") 1342 (interactive "p")
1343 (when (and (not minibuffer-default-add-done)
1344 (functionp minibuffer-default-add-function)
1345 (< nabs (- (if (listp minibuffer-default)
1346 (length minibuffer-default)
1347 1))))
1348 (setq minibuffer-default-add-done t
1349 minibuffer-default (funcall minibuffer-default-add-function)))
1311 (let ((minimum (if minibuffer-default 1350 (let ((minimum (if minibuffer-default
1312 (- (if (listp minibuffer-default) 1351 (- (if (listp minibuffer-default)
1313 (length minibuffer-default) 1352 (length minibuffer-default)
1314 1)) 1353 1))
1315 0)) 1354 0))
1318 (null minibuffer-text-before-history)) 1357 (null minibuffer-text-before-history))
1319 (setq minibuffer-text-before-history 1358 (setq minibuffer-text-before-history
1320 (minibuffer-contents-no-properties))) 1359 (minibuffer-contents-no-properties)))
1321 (if (< nabs minimum) 1360 (if (< nabs minimum)
1322 (if minibuffer-default 1361 (if minibuffer-default
1323 (error "End of history; no next item") 1362 (error "End of defaults; no next item")
1324 (error "End of history; no default available"))) 1363 (error "End of history; no default available")))
1325 (if (> nabs (length (symbol-value minibuffer-history-variable))) 1364 (if (> nabs (length (symbol-value minibuffer-history-variable)))
1326 (error "Beginning of history; no preceding item")) 1365 (error "Beginning of history; no preceding item"))
1327 (unless (memq last-command '(next-history-element 1366 (unless (memq last-command '(next-history-element
1328 previous-history-element)) 1367 previous-history-element))