comparison lisp/simple.el @ 1135:e33f6475229a

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 14 Sep 1992 06:53:22 +0000
parents 25b929c06f83
children e6cefcaba564
comparison
equal deleted inserted replaced
1134:05c961416bb5 1135:e33f6475229a
338 "Major mode not specialized for anything in particular. 338 "Major mode not specialized for anything in particular.
339 Other major modes are defined by comparison with this one." 339 Other major modes are defined by comparison with this one."
340 (interactive) 340 (interactive)
341 (kill-all-local-variables)) 341 (kill-all-local-variables))
342 342
343 (defvar read-expression-map (copy-keymap minibuffer-local-map)
344 "Minibuffer keymap used for reading Lisp expressions.")
345 (define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
346
343 (put 'eval-expression 'disabled t) 347 (put 'eval-expression 'disabled t)
344 348
345 ;; We define this, rather than making eval interactive, 349 ;; We define this, rather than making eval interactive,
346 ;; for the sake of completion of names like eval-region, eval-current-buffer. 350 ;; for the sake of completion of names like eval-region, eval-current-buffer.
347 (defun eval-expression (expression) 351 (defun eval-expression (expression)
348 "Evaluate EXPRESSION and print value in minibuffer. 352 "Evaluate EXPRESSION and print value in minibuffer.
349 Value is also consed on to front of the variable `values'." 353 Value is also consed on to front of the variable `values'."
350 (interactive "xEval: ") 354 (interactive (list (read-from-minibuffer "Eval: "
355 nil read-expression-map t)))
351 (setq values (cons (eval expression) values)) 356 (setq values (cons (eval expression) values))
352 (prin1 (car values) t)) 357 (prin1 (car values) t))
353 358
354 (defun edit-and-eval-command (prompt command) 359 (defun edit-and-eval-command (prompt command)
355 "Prompting with PROMPT, let user edit COMMAND and eval result. 360 "Prompting with PROMPT, let user edit COMMAND and eval result.
356 COMMAND is a Lisp expression. Let user edit that expression in 361 COMMAND is a Lisp expression. Let user edit that expression in
357 the minibuffer, then read and evaluate the result." 362 the minibuffer, then read and evaluate the result."
358 (let ((command (read-minibuffer prompt 363 (let ((command (read-from-minibuffer prompt
359 (prin1-to-string command)))) 364 (prin1-to-string command)
365 read-expression-map t)))
360 ;; Add edited command to command history, unless redundant. 366 ;; Add edited command to command history, unless redundant.
361 (or (equal command (car command-history)) 367 (or (equal command (car command-history))
362 (setq command-history (cons command command-history))) 368 (setq command-history (cons command command-history)))
363 (eval command))) 369 (eval command)))
364 370
375 (let ((elt (nth (1- arg) command-history)) 381 (let ((elt (nth (1- arg) command-history))
376 (minibuffer-history-position arg) 382 (minibuffer-history-position arg)
377 (minibuffer-history-sexp-flag t) 383 (minibuffer-history-sexp-flag t)
378 newcmd) 384 newcmd)
379 (if elt 385 (if elt
380 (let ((minibuffer-history-variable ' command-history)) 386 (progn
381 (setq newcmd (read-from-minibuffer "Redo: " 387 (setq newcmd (read-from-minibuffer "Redo: "
382 (prin1-to-string elt) 388 (prin1-to-string elt)
383 minibuffer-local-map 389 read-expression-map
384 t 390 t
385 (cons 'command-history 391 (cons 'command-history
386 arg))) 392 arg)))
393 ;; If command was added to command-history as a string,
394 ;; get rid of that. We want only evallable expressions there.
395 (if (stringp (car command-history))
396 (setq command-history (cdr command-history)))
387 ;; If command to be redone does not match front of history, 397 ;; If command to be redone does not match front of history,
388 ;; add it to the history. 398 ;; add it to the history.
389 (or (equal newcmd (car command-history)) 399 (or (equal newcmd (car command-history))
390 (setq command-history (cons newcmd command-history))) 400 (setq command-history (cons newcmd command-history)))
391 (eval newcmd)) 401 (eval newcmd))
392 (ding)))) 402 (ding))))
393 403
394 (defvar minibuffer-history nil) 404 (defvar minibuffer-history nil
395 (defvar minibuffer-history-sexp-flag nil) 405 "Default minibuffer history list.
406 This is used for all minibuffer input
407 except when an alternate history list is specified.")
408 (defvar minibuffer-history-sexp-flag nil
409 "Nonzero when doing history operations on `command-history'.
410 More generally, indicates that the history list being acted on
411 contains expressions rather than strings.")
396 (setq minibuffer-history-variable 'minibuffer-history) 412 (setq minibuffer-history-variable 'minibuffer-history)
397 (setq minibuffer-history-position nil) 413 (setq minibuffer-history-position nil)
414 (defvar minibuffer-history-search-history nil)
398 415
399 (mapcar 416 (mapcar
400 (function (lambda (key-and-command) 417 (function (lambda (key-and-command)
401 (mapcar 418 (mapcar
402 (function (lambda (keymap) 419 (function (lambda (keymap)
404 (car key-and-command) 421 (car key-and-command)
405 (cdr key-and-command)))) 422 (cdr key-and-command))))
406 '(minibuffer-local-map 423 '(minibuffer-local-map
407 minibuffer-local-ns-map 424 minibuffer-local-ns-map
408 minibuffer-local-completion-map 425 minibuffer-local-completion-map
409 minibuffer-local-must-match-map)))) 426 minibuffer-local-must-match-map
427 read-expression-map))))
410 '(("\en" . next-history-element) ([next] . next-history-element) 428 '(("\en" . next-history-element) ([next] . next-history-element)
411 ("\ep" . previous-history-element) ([prior] . previous-history-element) 429 ("\ep" . previous-history-element) ([prior] . previous-history-element)
412 ("\er" . previous-matching-history-element) 430 ("\er" . previous-matching-history-element)
413 ("\es" . next-matching-history-element))) 431 ("\es" . next-matching-history-element)))
414 432
415 (put 'previous-matching-history-element 'enable-recursive-minibuffers t)
416 (defun previous-matching-history-element (regexp n) 433 (defun previous-matching-history-element (regexp n)
417 (interactive "sPrevious element matching (regexp): \np") 434 "Find the previous history element that matches REGEXP.
435 \(Previous history elements refer to earlier actions.)
436 With prefix argument N, search for Nth previous match.
437 If N is negative, find the next or Nth next match."
438 (interactive
439 (let ((enable-recursive-minibuffers t)
440 (minibuffer-history-sexp-flag nil))
441 (list (read-from-minibuffer "Previous element matching (regexp): "
442 nil
443 minibuffer-local-map
444 nil
445 'minibuffer-history-search-history)
446 (prefix-numeric-value current-prefix-arg))))
418 (let ((history (symbol-value minibuffer-history-variable)) 447 (let ((history (symbol-value minibuffer-history-variable))
419 prevpos 448 prevpos
420 (pos minibuffer-history-position)) 449 (pos minibuffer-history-position))
421 (while (/= n 0) 450 (while (/= n 0)
422 (setq prevpos pos) 451 (setq prevpos pos)
427 "No earlier matching history item"))) 456 "No earlier matching history item")))
428 (if (string-match regexp 457 (if (string-match regexp
429 (if minibuffer-history-sexp-flag 458 (if minibuffer-history-sexp-flag
430 (prin1-to-string (nth (1- pos) history)) 459 (prin1-to-string (nth (1- pos) history))
431 (nth (1- pos) history))) 460 (nth (1- pos) history)))
432 (setq n (+ n (if (< n 0) -1 1))))) 461 (setq n (+ n (if (< n 0) 1 -1)))))
433 (setq minibuffer-history-position pos) 462 (setq minibuffer-history-position pos)
434 (erase-buffer) 463 (erase-buffer)
435 (let ((elt (nth (1- pos) history))) 464 (let ((elt (nth (1- pos) history)))
436 (insert (if minibuffer-history-sexp-flag 465 (insert (if minibuffer-history-sexp-flag
437 (prin1-to-string elt) 466 (prin1-to-string elt)
438 elt))) 467 elt)))
439 (goto-char (point-min)))) 468 (goto-char (point-min)))
440 469 (if (or (eq (car (car command-history)) 'previous-matching-history-element)
441 (put 'next-matching-history-element 'enable-recursive-minibuffers t) 470 (eq (car (car command-history)) 'next-matching-history-element))
471 (setq command-history (cdr command-history))))
472
442 (defun next-matching-history-element (regexp n) 473 (defun next-matching-history-element (regexp n)
443 (interactive "sNext element matching (regexp): \np") 474 "Find the next history element that matches REGEXP.
475 \(The next history element refers to a more recent action.)
476 With prefix argument N, search for Nth next match.
477 If N is negative, find the previous or Nth previous match."
478 (interactive
479 (let ((enable-recursive-minibuffers t)
480 (minibuffer-history-sexp-flag nil))
481 (list (read-from-minibuffer "Next element matching (regexp): "
482 nil
483 minibuffer-local-map
484 nil
485 'minibuffer-history-search-history)
486 (prefix-numeric-value current-prefix-arg))))
444 (previous-matching-history-element regexp (- n))) 487 (previous-matching-history-element regexp (- n)))
445 488
446 (defun next-history-element (n) 489 (defun next-history-element (n)
447 "Insert the next element of the minibuffer history into the minibuffer." 490 "Insert the next element of the minibuffer history into the minibuffer."
448 (interactive "p") 491 (interactive "p")