comparison lisp/prim/minibuf.el @ 169:15872534500d r20-3b11

Import from CVS: tag r20-3b11
author cvs
date Mon, 13 Aug 2007 09:46:53 +0200
parents 5a88923fcbfe
children 8eaf7971accc
comparison
equal deleted inserted replaced
168:9851d5c6556e 169:15872534500d
284 "History list symbol to add minibuffer values to. 284 "History list symbol to add minibuffer values to.
285 Each minibuffer output is added with 285 Each minibuffer output is added with
286 (set minibuffer-history-variable 286 (set minibuffer-history-variable
287 (cons STRING (symbol-value minibuffer-history-variable)))") 287 (cons STRING (symbol-value minibuffer-history-variable)))")
288 (defvar minibuffer-history-position) 288 (defvar minibuffer-history-position)
289
290 ;; Added by hniksic:
291 (defvar initial-minibuffer-history-position)
292 (defvar current-minibuffer-contents)
293 (defvar current-minibuffer-point)
289 294
290 (defcustom minibuffer-history-minimum-string-length 3 295 (defcustom minibuffer-history-minimum-string-length 3
291 "*If this variable is non-nil, a string will not be added to the 296 "*If this variable is non-nil, a string will not be added to the
292 minibuffer history if its length is less than that value." 297 minibuffer history if its length is less than that value."
293 :type '(choice (const :tag "Any" nil) 298 :type '(choice (const :tag "Any" nil)
374 (set-buffer buffer) 379 (set-buffer buffer)
375 (reset-buffer buffer) 380 (reset-buffer buffer)
376 (setq default-directory dir) 381 (setq default-directory dir)
377 (make-local-variable 'print-escape-newlines) 382 (make-local-variable 'print-escape-newlines)
378 (setq print-escape-newlines t) 383 (setq print-escape-newlines t)
384 (make-local-variable 'current-minibuffer-contents)
385 (make-local-variable 'current-minibuffer-point)
386 (make-local-variable 'initial-minibuffer-history-position)
387 (setq current-minibuffer-contents ""
388 current-minibuffer-point 1)
379 (if (not minibuffer-smart-completion-tracking-behavior) 389 (if (not minibuffer-smart-completion-tracking-behavior)
380 nil 390 nil
381 (make-local-variable 'mode-motion-hook) 391 (make-local-variable 'mode-motion-hook)
382 (or mode-motion-hook 392 (or mode-motion-hook
383 ;;####disgusting 393 ;;####disgusting
392 (message nil) 402 (message nil)
393 (if initial-contents 403 (if initial-contents
394 (if (consp initial-contents) 404 (if (consp initial-contents)
395 (progn 405 (progn
396 (insert (car initial-contents)) 406 (insert (car initial-contents))
397 (goto-char (1+ (cdr initial-contents)))) 407 (goto-char (1+ (cdr initial-contents)))
398 (insert initial-contents))) 408 (setq current-minibuffer-contents (car initial-contents)
409 current-minibuffer-point (cdr initial-contents)))
410 (insert initial-contents)
411 (setq current-minibuffer-contents initial-contents
412 current-minibuffer-point (point))))
399 (use-local-map (or keymap minibuffer-local-map)) 413 (use-local-map (or keymap minibuffer-local-map))
400 (let ((mouse-grabbed-buffer 414 (let ((mouse-grabbed-buffer
401 (and minibuffer-smart-completion-tracking-behavior 415 (and minibuffer-smart-completion-tracking-behavior
402 (current-buffer))) 416 (current-buffer)))
403 (current-prefix-arg current-prefix-arg) 417 (current-prefix-arg current-prefix-arg)
411 (minibuffer-history-position (cond ((consp _history_) 425 (minibuffer-history-position (cond ((consp _history_)
412 (cdr _history_)) 426 (cdr _history_))
413 (t 427 (t
414 0))) 428 0)))
415 (minibuffer-scroll-window owindow)) 429 (minibuffer-scroll-window owindow))
430 (setq initial-minibuffer-history-position
431 minibuffer-history-position)
416 (if abbrev-table 432 (if abbrev-table
417 (setq local-abbrev-table abbrev-table 433 (setq local-abbrev-table abbrev-table
418 abbrev-mode t)) 434 abbrev-mode t))
419 ;; This is now run from read-minibuffer-internal 435 ;; This is now run from read-minibuffer-internal
420 ;(if minibuffer-setup-hook 436 ;(if minibuffer-setup-hook
1172 If N is negative, find the next or Nth next match." 1188 If N is negative, find the next or Nth next match."
1173 (interactive 1189 (interactive
1174 (let ((enable-recursive-minibuffers t) 1190 (let ((enable-recursive-minibuffers t)
1175 (minibuffer-history-sexp-flag nil)) 1191 (minibuffer-history-sexp-flag nil))
1176 (if (eq 't (symbol-value minibuffer-history-variable)) 1192 (if (eq 't (symbol-value minibuffer-history-variable))
1177 (error "history is not being recorded in this context")) 1193 (error "History is not being recorded in this context"))
1178 (list (read-from-minibuffer "Previous element matching (regexp): " 1194 (list (read-from-minibuffer "Previous element matching (regexp): "
1179 (car minibuffer-history-search-history) 1195 (car minibuffer-history-search-history)
1180 minibuffer-local-map 1196 minibuffer-local-map
1181 nil 1197 nil
1182 'minibuffer-history-search-history) 1198 'minibuffer-history-search-history)
1183 (prefix-numeric-value current-prefix-arg)))) 1199 (prefix-numeric-value current-prefix-arg))))
1184 (let ((history (symbol-value minibuffer-history-variable)) 1200 (let ((history (symbol-value minibuffer-history-variable))
1185 prevpos 1201 prevpos
1186 (pos minibuffer-history-position)) 1202 (pos minibuffer-history-position))
1187 (if (eq history t) 1203 (if (eq history t)
1188 (error "history is not being recorded in this context")) 1204 (error "History is not being recorded in this context"))
1189 (while (/= n 0) 1205 (while (/= n 0)
1190 (setq prevpos pos) 1206 (setq prevpos pos)
1191 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history))) 1207 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
1192 (if (= pos prevpos) 1208 (if (= pos prevpos)
1193 (if (= pos 1) ;; rewritten for I18N3 snarfing 1209 (if (= pos 1) ;; rewritten for I18N3 snarfing
1198 (let ((print-level nil)) 1214 (let ((print-level nil))
1199 (prin1-to-string (nth (1- pos) history))) 1215 (prin1-to-string (nth (1- pos) history)))
1200 (nth (1- pos) history))) 1216 (nth (1- pos) history)))
1201 (setq n (+ n (if (< n 0) 1 -1))))) 1217 (setq n (+ n (if (< n 0) 1 -1)))))
1202 (setq minibuffer-history-position pos) 1218 (setq minibuffer-history-position pos)
1219 (setq current-minibuffer-contents (buffer-string)
1220 current-minibuffer-point (point))
1203 (erase-buffer) 1221 (erase-buffer)
1204 (let ((elt (nth (1- pos) history))) 1222 (let ((elt (nth (1- pos) history)))
1205 (insert (if minibuffer-history-sexp-flag 1223 (insert (if minibuffer-history-sexp-flag
1206 (let ((print-level nil)) 1224 (let ((print-level nil))
1207 (prin1-to-string elt)) 1225 (prin1-to-string elt))
1218 If N is negative, find the previous or Nth previous match." 1236 If N is negative, find the previous or Nth previous match."
1219 (interactive 1237 (interactive
1220 (let ((enable-recursive-minibuffers t) 1238 (let ((enable-recursive-minibuffers t)
1221 (minibuffer-history-sexp-flag nil)) 1239 (minibuffer-history-sexp-flag nil))
1222 (if (eq t (symbol-value minibuffer-history-variable)) 1240 (if (eq t (symbol-value minibuffer-history-variable))
1223 (error "history is not being recorded in this context")) 1241 (error "History is not being recorded in this context"))
1224 (list (read-from-minibuffer "Next element matching (regexp): " 1242 (list (read-from-minibuffer "Next element matching (regexp): "
1225 (car minibuffer-history-search-history) 1243 (car minibuffer-history-search-history)
1226 minibuffer-local-map 1244 minibuffer-local-map
1227 nil 1245 nil
1228 'minibuffer-history-search-history) 1246 'minibuffer-history-search-history)
1231 1249
1232 (defun next-history-element (n) 1250 (defun next-history-element (n)
1233 "Insert the next element of the minibuffer history into the minibuffer." 1251 "Insert the next element of the minibuffer history into the minibuffer."
1234 (interactive "p") 1252 (interactive "p")
1235 (if (eq 't (symbol-value minibuffer-history-variable)) 1253 (if (eq 't (symbol-value minibuffer-history-variable))
1236 (error "history is not being recorded in this context")) 1254 (error "History is not being recorded in this context"))
1237 (or (zerop n) 1255 (unless (zerop n)
1238 (let ((narg (min (max 1 (- minibuffer-history-position n)) 1256 (when (eq minibuffer-history-position
1239 (length (symbol-value minibuffer-history-variable))))) 1257 initial-minibuffer-history-position)
1240 (if (or (zerop narg) 1258 (setq current-minibuffer-contents (buffer-string)
1241 (= minibuffer-history-position narg)) 1259 current-minibuffer-point (point)))
1242 (error (if (>= n 0) ;; rewritten for I18N3 snarfing 1260 (let ((narg (- minibuffer-history-position n)))
1243 (format "No following item in %s" 1261 (cond ((< narg 0)
1244 minibuffer-history-variable) 1262 (error "No following item in %s" minibuffer-history-variable))
1245 (format "No preceding item in %s" 1263 ((> narg (length (symbol-value minibuffer-history-variable)))
1246 minibuffer-history-variable))) 1264 (error "No preceding item in %s" minibuffer-history-variable)))
1247 (erase-buffer) 1265 (erase-buffer)
1248 (setq minibuffer-history-position narg) 1266 (setq minibuffer-history-position narg)
1249 (let ((elt (nth (1- minibuffer-history-position) 1267 (if (eq narg initial-minibuffer-history-position)
1250 (symbol-value minibuffer-history-variable)))) 1268 (progn
1251 (insert 1269 (insert current-minibuffer-contents)
1252 (if (not (stringp elt)) 1270 (goto-char current-minibuffer-point))
1253 (let ((print-level nil)) 1271 (let ((elt (nth (1- minibuffer-history-position)
1254 (condition-case nil 1272 (symbol-value minibuffer-history-variable))))
1255 (let ((print-readably t) 1273 (insert
1256 (print-escape-newlines t)) 1274 (if (not (stringp elt))
1257 (prin1-to-string elt)) 1275 (let ((print-level nil))
1258 (error (prin1-to-string elt)))) 1276 (condition-case nil
1259 elt))) 1277 (let ((print-readably t)
1260 ;; FSF has point-min here. 1278 (print-escape-newlines t))
1261 (goto-char (point-max)))))) 1279 (prin1-to-string elt))
1280 (error (prin1-to-string elt))))
1281 elt)))
1282 ;; FSF has point-min here.
1283 (goto-char (point-max))))))
1262 1284
1263 (defun previous-history-element (n) 1285 (defun previous-history-element (n)
1264 "Inserts the previous element of the minibuffer history into the minibuffer." 1286 "Inserts the previous element of the minibuffer history into the minibuffer."
1265 (interactive "p") 1287 (interactive "p")
1266 (next-history-element (- n))) 1288 (next-history-element (- n)))