diff options
Diffstat (limited to 'lisp/ielm.el')
| -rw-r--r-- | lisp/ielm.el | 107 |
1 files changed, 77 insertions, 30 deletions
diff --git a/lisp/ielm.el b/lisp/ielm.el index aa60d5de6c3..944e2453cb9 100644 --- a/lisp/ielm.el +++ b/lisp/ielm.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; ielm.el --- interaction mode for Emacs Lisp | 1 | ;;; ielm.el --- interaction mode for Emacs Lisp |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1994, 2002, 2003 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1994, 2002, 2003, 2004 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: David Smith <maa036@lancaster.ac.uk> | 5 | ;; Author: David Smith <maa036@lancaster.ac.uk> |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -49,12 +49,57 @@ | |||
| 49 | :type 'boolean | 49 | :type 'boolean |
| 50 | :group 'ielm) | 50 | :group 'ielm) |
| 51 | 51 | ||
| 52 | (defcustom ielm-prompt-read-only t | ||
| 53 | "If non-nil, the IELM prompt is read only. | ||
| 54 | The read only region includes the newline before the prompt. | ||
| 55 | Setting this variable does not affect existing IELM runs. | ||
| 56 | This works by setting the buffer-local value of `comint-prompt-read-only'. | ||
| 57 | Setting that value directly affects new prompts in the current buffer. | ||
| 58 | |||
| 59 | If this option is enabled, then the safe way to temporarily | ||
| 60 | override the read-only-ness of ielm prompts is to call | ||
| 61 | `comint-kill-whole-line' or `comint-kill-region' with no | ||
| 62 | narrowing in effect. This way you will be certain that none of | ||
| 63 | the remaining prompts will be accidentally messed up. You may | ||
| 64 | wish to put something like the following in your `.emacs' file: | ||
| 65 | |||
| 66 | \(add-hook 'ielm-mode-hook | ||
| 67 | '(lambda () | ||
| 68 | (define-key ielm-map \"\C-w\" 'comint-kill-region) | ||
| 69 | (define-key ielm-map [C-S-backspace] | ||
| 70 | 'comint-kill-whole-line))) | ||
| 71 | |||
| 72 | If you set `comint-prompt-read-only' to t, you might wish to use | ||
| 73 | `comint-mode-hook' and `comint-mode-map' instead of | ||
| 74 | `ielm-mode-hook' and `ielm-map'. That will affect all comint | ||
| 75 | buffers, including ielm buffers. If you sometimes use ielm on | ||
| 76 | text-only terminals or with `emacs -nw', you might wish to use | ||
| 77 | another binding for `comint-kill-whole-line'." | ||
| 78 | :type 'boolean | ||
| 79 | :group 'ielm | ||
| 80 | :version "21.4") | ||
| 81 | |||
| 52 | (defcustom ielm-prompt "ELISP> " | 82 | (defcustom ielm-prompt "ELISP> " |
| 53 | "Prompt used in IELM." | 83 | "Prompt used in IELM. |
| 84 | Setting this variable does not affect existing IELM runs. | ||
| 85 | |||
| 86 | Interrupting the IELM process with \\<ielm-map>\\[comint-interrupt-subjob], | ||
| 87 | and then restarting it using \\[ielm], makes the then current | ||
| 88 | default value affect _new_ prompts. Unless the new prompt | ||
| 89 | differs only in text properties from the old one, IELM will no | ||
| 90 | longer recognize the old prompts. However, executing \\[ielm] | ||
| 91 | does not update the prompt of an *ielm* buffer with a running process. | ||
| 92 | For IELM buffers that are not called `*ielm*', you can execute | ||
| 93 | \\[inferior-emacs-lisp-mode] in that IELM buffer to update the value, | ||
| 94 | for new prompts. This works even if the buffer has a running process." | ||
| 54 | :type 'string | 95 | :type 'string |
| 55 | :group 'ielm | 96 | :group 'ielm) |
| 56 | :get #'(lambda (symbol) (substring-no-properties (symbol-value symbol))) | 97 | |
| 57 | :set #'(lambda (symbol value) (set symbol (propertize value 'read-only t 'rear-nonsticky t)))) | 98 | (defvar ielm-prompt-internal "ELISP> " |
| 99 | "Stored value of `ielm-prompt' in the current IELM buffer. | ||
| 100 | This is an internal variable used by IELM. Its purpose is to | ||
| 101 | prevent a running IELM process from being messed up when the user | ||
| 102 | customizes `ielm-prompt'.") | ||
| 58 | 103 | ||
| 59 | (defcustom ielm-dynamic-return t | 104 | (defcustom ielm-dynamic-return t |
| 60 | "*Controls whether \\<ielm-map>\\[ielm-return] has intelligent behaviour in IELM. | 105 | "*Controls whether \\<ielm-map>\\[ielm-return] has intelligent behaviour in IELM. |
| @@ -145,9 +190,7 @@ This variable is buffer-local.") | |||
| 145 | (define-key ielm-map "\C-c\C-v" 'ielm-print-working-buffer)) | 190 | (define-key ielm-map "\C-c\C-v" 'ielm-print-working-buffer)) |
| 146 | 191 | ||
| 147 | (defvar ielm-font-lock-keywords | 192 | (defvar ielm-font-lock-keywords |
| 148 | (list | 193 | '(("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)" |
| 149 | (cons (concat "^" (regexp-quote ielm-prompt)) 'font-lock-keyword-face) | ||
| 150 | '("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)" | ||
| 151 | (1 font-lock-comment-face) | 194 | (1 font-lock-comment-face) |
| 152 | (2 font-lock-constant-face))) | 195 | (2 font-lock-constant-face))) |
| 153 | "Additional expressions to highlight in ielm buffers.") | 196 | "Additional expressions to highlight in ielm buffers.") |
| @@ -250,8 +293,7 @@ simply inserts a newline." | |||
| 250 | (defun ielm-send-input nil | 293 | (defun ielm-send-input nil |
| 251 | "Evaluate the Emacs Lisp expression after the prompt." | 294 | "Evaluate the Emacs Lisp expression after the prompt." |
| 252 | (interactive) | 295 | (interactive) |
| 253 | (let ((buf (current-buffer)) | 296 | (let (ielm-input) ; set by ielm-input-sender |
| 254 | ielm-input) ; set by ielm-input-sender | ||
| 255 | (comint-send-input) ; update history, markers etc. | 297 | (comint-send-input) ; update history, markers etc. |
| 256 | (ielm-eval-input ielm-input))) | 298 | (ielm-eval-input ielm-input))) |
| 257 | 299 | ||
| @@ -374,7 +416,7 @@ simply inserts a newline." | |||
| 374 | (setq ** *) | 416 | (setq ** *) |
| 375 | (setq * ielm-result)) | 417 | (setq * ielm-result)) |
| 376 | (setq ielm-output (concat ielm-output "\n")))) | 418 | (setq ielm-output (concat ielm-output "\n")))) |
| 377 | (setq ielm-output (concat ielm-output ielm-prompt)) | 419 | (setq ielm-output (concat ielm-output ielm-prompt-internal)) |
| 378 | (comint-output-filter (ielm-process) ielm-output))) | 420 | (comint-output-filter (ielm-process) ielm-output))) |
| 379 | 421 | ||
| 380 | ;;; Process and marker utilities | 422 | ;;; Process and marker utilities |
| @@ -414,8 +456,8 @@ The current working buffer may be changed (with a call to | |||
| 414 | `set-buffer', or with \\[ielm-change-working-buffer]), and its value | 456 | `set-buffer', or with \\[ielm-change-working-buffer]), and its value |
| 415 | is preserved between successive evaluations. In this way, expressions | 457 | is preserved between successive evaluations. In this way, expressions |
| 416 | may be evaluated in a different buffer than the *ielm* buffer. | 458 | may be evaluated in a different buffer than the *ielm* buffer. |
| 417 | Display the name of the working buffer with \\[ielm-print-working-buffer], | 459 | By default, its name is shown on the mode line; you can always display |
| 418 | or the buffer itself with \\[ielm-display-working-buffer]. | 460 | it with \\[ielm-print-working-buffer], or the buffer itself with \\[ielm-display-working-buffer]. |
| 419 | 461 | ||
| 420 | During evaluations, the values of the variables `*', `**', and `***' | 462 | During evaluations, the values of the variables `*', `**', and `***' |
| 421 | are the results of the previous, second previous and third previous | 463 | are the results of the previous, second previous and third previous |
| @@ -426,14 +468,16 @@ buffer, then the values in the working buffer are used. The variables | |||
| 426 | Expressions evaluated by IELM are not subject to `debug-on-quit' or | 468 | Expressions evaluated by IELM are not subject to `debug-on-quit' or |
| 427 | `debug-on-error'. | 469 | `debug-on-error'. |
| 428 | 470 | ||
| 429 | The behaviour of IELM may be customised with the following variables: | 471 | The behaviour of IELM may be customized with the following variables: |
| 430 | * To stop beeping on error, set `ielm-noisy' to nil | 472 | * To stop beeping on error, set `ielm-noisy' to nil. |
| 431 | * If you don't like the prompt, you can change it by setting `ielm-prompt'. | 473 | * If you don't like the prompt, you can change it by setting `ielm-prompt'. |
| 432 | * Set `ielm-dynamic-return' to nil for bindings like `lisp-interaction-mode' | 474 | * If you do not like that the prompt is (by default) read-only, set |
| 475 | `ielm-prompt-read-only' to nil. | ||
| 476 | * Set `ielm-dynamic-return' to nil for bindings like `lisp-interaction-mode'. | ||
| 433 | * Entry to this mode runs `comint-mode-hook' and `ielm-mode-hook' | 477 | * Entry to this mode runs `comint-mode-hook' and `ielm-mode-hook' |
| 434 | (in that order). | 478 | (in that order). |
| 435 | 479 | ||
| 436 | Customised bindings may be defined in `ielm-map', which currently contains: | 480 | Customized bindings may be defined in `ielm-map', which currently contains: |
| 437 | \\{ielm-map}" | 481 | \\{ielm-map}" |
| 438 | (interactive) | 482 | (interactive) |
| 439 | (comint-mode) | 483 | (comint-mode) |
| @@ -443,15 +487,16 @@ Customised bindings may be defined in `ielm-map', which currently contains: | |||
| 443 | (setq comint-input-sender 'ielm-input-sender) | 487 | (setq comint-input-sender 'ielm-input-sender) |
| 444 | (setq comint-process-echoes nil) | 488 | (setq comint-process-echoes nil) |
| 445 | (make-local-variable 'comint-dynamic-complete-functions) | 489 | (make-local-variable 'comint-dynamic-complete-functions) |
| 490 | (set (make-local-variable 'ielm-prompt-internal) ielm-prompt) | ||
| 491 | (set (make-local-variable 'comint-prompt-read-only) ielm-prompt-read-only) | ||
| 446 | (setq comint-dynamic-complete-functions | 492 | (setq comint-dynamic-complete-functions |
| 447 | '(ielm-tab comint-replace-by-expanded-history ielm-complete-filename ielm-complete-symbol)) | 493 | '(ielm-tab comint-replace-by-expanded-history ielm-complete-filename ielm-complete-symbol)) |
| 448 | (setq comint-get-old-input 'ielm-get-old-input) | 494 | (setq comint-get-old-input 'ielm-get-old-input) |
| 449 | (make-local-variable 'comint-completion-addsuffix) | 495 | (make-local-variable 'comint-completion-addsuffix) |
| 450 | (setq comint-completion-addsuffix | 496 | (setq comint-completion-addsuffix '("/" . "")) |
| 451 | (cons (char-to-string directory-sep-char) "")) | ||
| 452 | |||
| 453 | (setq major-mode 'inferior-emacs-lisp-mode) | 497 | (setq major-mode 'inferior-emacs-lisp-mode) |
| 454 | (setq mode-name "IELM") | 498 | (setq mode-name "IELM") |
| 499 | (setq mode-line-process '(":%s on " (:eval (buffer-name ielm-working-buffer)))) | ||
| 455 | (use-local-map ielm-map) | 500 | (use-local-map ielm-map) |
| 456 | (set-syntax-table emacs-lisp-mode-syntax-table) | 501 | (set-syntax-table emacs-lisp-mode-syntax-table) |
| 457 | 502 | ||
| @@ -494,10 +539,11 @@ Customised bindings may be defined in `ielm-map', which currently contains: | |||
| 494 | (insert ielm-header) | 539 | (insert ielm-header) |
| 495 | (ielm-set-pm (point-max)) | 540 | (ielm-set-pm (point-max)) |
| 496 | (unless comint-use-prompt-regexp-instead-of-fields | 541 | (unless comint-use-prompt-regexp-instead-of-fields |
| 497 | (add-text-properties | 542 | (let ((inhibit-read-only t)) |
| 498 | (point-min) (point-max) | 543 | (add-text-properties |
| 499 | '(rear-nonsticky t field output inhibit-line-move-field-capture t))) | 544 | (point-min) (point-max) |
| 500 | (comint-output-filter (ielm-process) ielm-prompt) | 545 | '(rear-nonsticky t field output inhibit-line-move-field-capture t)))) |
| 546 | (comint-output-filter (ielm-process) ielm-prompt-internal) | ||
| 501 | (set-marker comint-last-input-start (ielm-pm)) | 547 | (set-marker comint-last-input-start (ielm-pm)) |
| 502 | (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)) | 548 | (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)) |
| 503 | 549 | ||
| @@ -521,12 +567,13 @@ Customised bindings may be defined in `ielm-map', which currently contains: | |||
| 521 | "Interactively evaluate Emacs Lisp expressions. | 567 | "Interactively evaluate Emacs Lisp expressions. |
| 522 | Switches to the buffer `*ielm*', or creates it if it does not exist." | 568 | Switches to the buffer `*ielm*', or creates it if it does not exist." |
| 523 | (interactive) | 569 | (interactive) |
| 524 | (if (comint-check-proc "*ielm*") | 570 | (let (old-point) |
| 525 | nil | 571 | (unless (comint-check-proc "*ielm*") |
| 526 | (save-excursion | 572 | (with-current-buffer (get-buffer-create "*ielm*") |
| 527 | (set-buffer (get-buffer-create "*ielm*")) | 573 | (unless (zerop (buffer-size)) (setq old-point (point))) |
| 528 | (inferior-emacs-lisp-mode))) | 574 | (inferior-emacs-lisp-mode))) |
| 529 | (pop-to-buffer "*ielm*")) | 575 | (pop-to-buffer "*ielm*") |
| 576 | (when old-point (push-mark old-point)))) | ||
| 530 | 577 | ||
| 531 | (provide 'ielm) | 578 | (provide 'ielm) |
| 532 | 579 | ||