emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read-only comint-prompt


From: Luc Teirlinck
Subject: Re: read-only comint-prompt
Date: Mon, 26 Apr 2004 23:07:57 -0500 (CDT)

I believe that the following patches to ielm.el and comint.el are, for
several reasons, better than the ones I proposed in my previous
message.  The new version prevents accidents where a newline before a
prompt is accidentally deleted, resulting in a mess with read-only
prompts in bad places.  I could install these if there are no
objections.  Again, the comint prompt would _not_ be read-only by
default, and I plan to add some further minor changes, that would make
kill-whole-line and kill-region ignore the read-only-ness of the
prompts.

===File ~/comint-new-diff===================================
*** comint.el   22 Apr 2004 18:50:10 -0500      1.295
--- comint.el   26 Apr 2004 21:28:02 -0500      
***************
*** 171,176 ****
--- 171,184 ----
  
  This is a good thing to set in mode hooks.")
  
+ (defcustom comint-prompt-read-only nil
+   "If non-nil, the comint prompt is read only.
+ This does not affect existing prompts.
+ Certain derived modes may override this option."
+   :type 'boolean
+   :group 'comint
+   :version "21.4")
+ 
  (defvar comint-delimiter-argument-list ()
    "List of characters to recognise as separate arguments in input.
  Strings comprising a character in this list will separate the arguments
***************
*** 1687,1702 ****
                (let ((inhibit-read-only t))
                  (add-text-properties comint-last-output-start (point)
                                       '(rear-nonsticky t
!                                        field output
!                                        inhibit-line-move-field-capture t))))
  
            ;; Highlight the prompt, where we define `prompt' to mean
            ;; the most recent output that doesn't end with a newline.
!           (unless (and (bolp) (null comint-last-prompt-overlay))
!             ;; Need to create or move the prompt overlay (in the case
!             ;; where there is no prompt ((bolp) == t), we still do
!             ;; this if there's already an existing overlay).
!             (let ((prompt-start (save-excursion (forward-line 0) (point))))
                (if comint-last-prompt-overlay
                    ;; Just move an existing overlay
                    (move-overlay comint-last-prompt-overlay
--- 1695,1721 ----
                (let ((inhibit-read-only t))
                  (add-text-properties comint-last-output-start (point)
                                       '(rear-nonsticky t
!                                      field output
!                                      inhibit-line-move-field-capture t))))
  
            ;; Highlight the prompt, where we define `prompt' to mean
            ;; the most recent output that doesn't end with a newline.
!           (let ((prompt-start (save-excursion (forward-line 0) (point)))
!                 (inhibit-read-only t))
!             (when comint-prompt-read-only
!               (unless (= (point-min) prompt-start)
!                 (add-text-properties
!                  (1- prompt-start) prompt-start
!                  '(read-only t rear-non-sticky t)))
!               (add-text-properties
!                prompt-start (point)
!                '(read-only t rear-non-sticky t front-sticky (read-only))))
!             (unless (and (bolp) (null comint-last-prompt-overlay))
!               ;; Need to create or move the prompt overlay (in the case
!               ;; where there is no prompt ((bolp) == t), we still do
!               ;; this if there's already an existing overlay).
!             
!               
                (if comint-last-prompt-overlay
                    ;; Just move an existing overlay
                    (move-overlay comint-last-prompt-overlay
============================================================

===File ~/ielm-new-diff=====================================
*** ielm.el     25 Apr 2004 21:59:05 -0500      1.41
--- ielm.el     26 Apr 2004 22:33:56 -0500      
***************
*** 52,85 ****
  (defcustom ielm-prompt-read-only t
    "If non-nil, the IELM prompt is read only.
  Setting this variable does not affect existing IELM runs.
! 
! You can give the IELM prompt more highly customized read-only
! type properties, by setting this option to nil, and then setting
! `ielm-prompt', outside of Custom, to a string with the desired
! text properties.
! 
! Interrupting the IELM process with \\<ielm-map>\\[comint-interrupt-subjob],
! and then restarting it using \\[ielm], makes the then current
! default value affect _new_ prompts.  However, executing \\[ielm]
! does not have this effect on *ielm* buffers with a running process.
! For IELM buffers that are not called `*ielm*', you can execute
! \\[inferior-emacs-lisp-mode] in that IELM buffer to update the value,
! for new prompts.  This works even if the buffer has a running process."
    :type 'boolean
    :group 'ielm
    :version "21.4")
  
  (defcustom ielm-prompt "ELISP> "
    "Prompt used in IELM.
! Setting the default value does not affect existing IELM runs.
! `inferior-emacs-lisp-mode' converts this into a buffer-local
! variable in IELM buffers.  The buffer-local value is meant for
! internal use by IELM.  Do not try to set the buffer-local value
! yourself in any way, unless you really know what you are doing.
  
  Interrupting the IELM process with \\<ielm-map>\\[comint-interrupt-subjob],
  and then restarting it using \\[ielm], makes the then current
! _default_ value affect _new_ prompts.  Unless the new prompt
  differs only in text properties from the old one, IELM will no
  longer recognize the old prompts.  However, executing \\[ielm]
  does not update the prompt of an *ielm* buffer with a running process.
--- 52,70 ----
  (defcustom ielm-prompt-read-only t
    "If non-nil, the IELM prompt is read only.
  Setting this variable does not affect existing IELM runs.
! This works by setting the buffer-local value of `comint-prompt-read-only'.
! Setting that value directly affects new prompts in the current buffer."
    :type 'boolean
    :group 'ielm
    :version "21.4")
  
  (defcustom ielm-prompt "ELISP> "
    "Prompt used in IELM.
! Setting this variable does not affect existing IELM runs.
  
  Interrupting the IELM process with \\<ielm-map>\\[comint-interrupt-subjob],
  and then restarting it using \\[ielm], makes the then current
! default value affect _new_ prompts.  Unless the new prompt
  differs only in text properties from the old one, IELM will no
  longer recognize the old prompts.  However, executing \\[ielm]
  does not update the prompt of an *ielm* buffer with a running process.
***************
*** 89,94 ****
--- 74,85 ----
    :type 'string
    :group 'ielm)
  
+ (defvar ielm-prompt-internal "ELISP> "
+   "Stored value of `ielm-prompt' in the current IELM buffer.
+ This is an internal variable used by IELM.  Its purpose is to
+ prevent a running IELM process from being messed up when the user
+ customizes `ielm-prompt'.")
+ 
  (defcustom ielm-dynamic-return t
    "*Controls whether \\<ielm-map>\\[ielm-return] has intelligent behaviour in 
IELM.
  If non-nil, \\[ielm-return] evaluates input for complete sexps, or inserts a 
newline
***************
*** 178,186 ****
    (define-key ielm-map "\C-c\C-v" 'ielm-print-working-buffer))
  
  (defvar ielm-font-lock-keywords
!   (list
!    (cons (concat "^" (regexp-quote ielm-prompt)) 'font-lock-keyword-face)
!    '("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)"
       (1 font-lock-comment-face)
       (2 font-lock-constant-face)))
    "Additional expressions to highlight in ielm buffers.")
--- 169,175 ----
    (define-key ielm-map "\C-c\C-v" 'ielm-print-working-buffer))
  
  (defvar ielm-font-lock-keywords
!   '(("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)"
       (1 font-lock-comment-face)
       (2 font-lock-constant-face)))
    "Additional expressions to highlight in ielm buffers.")
***************
*** 283,290 ****
  (defun ielm-send-input nil
    "Evaluate the Emacs Lisp expression after the prompt."
    (interactive)
!   (let ((buf (current-buffer))
!       ielm-input)                     ; set by ielm-input-sender
      (comint-send-input)                       ; update history, markers etc.
      (ielm-eval-input ielm-input)))
  
--- 272,278 ----
  (defun ielm-send-input nil
    "Evaluate the Emacs Lisp expression after the prompt."
    (interactive)
!   (let (ielm-input)                   ; set by ielm-input-sender
      (comint-send-input)                       ; update history, markers etc.
      (ielm-eval-input ielm-input)))
  
***************
*** 407,413 ****
            (setq ** *)
            (setq * ielm-result))
          (setq ielm-output (concat ielm-output "\n"))))
!     (setq ielm-output (concat ielm-output ielm-prompt))
      (comint-output-filter (ielm-process) ielm-output)))
  
  ;;; Process and marker utilities
--- 395,401 ----
            (setq ** *)
            (setq * ielm-result))
          (setq ielm-output (concat ielm-output "\n"))))
!     (setq ielm-output (concat ielm-output ielm-prompt-internal))
      (comint-output-filter (ielm-process) ielm-output)))
  
  ;;; Process and marker utilities
***************
*** 478,497 ****
    (setq comint-input-sender 'ielm-input-sender)
    (setq comint-process-echoes nil)
    (make-local-variable 'comint-dynamic-complete-functions)
!   (set (make-local-variable 'ielm-prompt)
!        (if ielm-prompt-read-only
!          (propertize ielm-prompt
!                      'read-only t
!                      'rear-nonsticky t
!                      'front-sticky '(read-only))
!        ielm-prompt))
    (setq comint-dynamic-complete-functions
        '(ielm-tab comint-replace-by-expanded-history ielm-complete-filename 
ielm-complete-symbol))
    (setq comint-get-old-input 'ielm-get-old-input)
    (make-local-variable 'comint-completion-addsuffix)
!   (setq comint-completion-addsuffix
!       (cons (char-to-string directory-sep-char) ""))
! 
    (setq major-mode 'inferior-emacs-lisp-mode)
    (setq mode-name "IELM")
    (setq mode-line-process '(":%s on " (:eval (buffer-name 
ielm-working-buffer))))
--- 466,478 ----
    (setq comint-input-sender 'ielm-input-sender)
    (setq comint-process-echoes nil)
    (make-local-variable 'comint-dynamic-complete-functions)
!   (set (make-local-variable 'ielm-prompt-internal) ielm-prompt)
!   (set (make-local-variable 'comint-prompt-read-only) ielm-prompt-read-only)
    (setq comint-dynamic-complete-functions
        '(ielm-tab comint-replace-by-expanded-history ielm-complete-filename 
ielm-complete-symbol))
    (setq comint-get-old-input 'ielm-get-old-input)
    (make-local-variable 'comint-completion-addsuffix)
!   (setq comint-completion-addsuffix '("/" . ""))
    (setq major-mode 'inferior-emacs-lisp-mode)
    (setq mode-name "IELM")
    (setq mode-line-process '(":%s on " (:eval (buffer-name 
ielm-working-buffer))))
***************
*** 541,547 ****
          (add-text-properties
           (point-min) (point-max)
           '(rear-nonsticky t field output inhibit-line-move-field-capture t))))
!     (comint-output-filter (ielm-process) ielm-prompt)
      (set-marker comint-last-input-start (ielm-pm))
      (set-process-filter (get-buffer-process (current-buffer)) 
'comint-output-filter))
  
--- 522,528 ----
          (add-text-properties
           (point-min) (point-max)
           '(rear-nonsticky t field output inhibit-line-move-field-capture t))))
!     (comint-output-filter (ielm-process) ielm-prompt-internal)
      (set-marker comint-last-input-start (ielm-pm))
      (set-process-filter (get-buffer-process (current-buffer)) 
'comint-output-filter))
  
***************
*** 568,574 ****
    (let (old-point)
      (unless (comint-check-proc "*ielm*")
        (with-current-buffer (get-buffer-create "*ielm*")
!       (unless (eq (buffer-size) 0) (setq old-point (point)))
        (inferior-emacs-lisp-mode)))
      (pop-to-buffer "*ielm*")
      (when old-point (push-mark old-point))))
--- 549,555 ----
    (let (old-point)
      (unless (comint-check-proc "*ielm*")
        (with-current-buffer (get-buffer-create "*ielm*")
!       (unless (zerop (buffer-size)) (setq old-point (point)))
        (inferior-emacs-lisp-mode)))
      (pop-to-buffer "*ielm*")
      (when old-point (push-mark old-point))))
============================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]