unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* read-only comint-prompt
@ 2004-04-27  0:11 Luc Teirlinck
  2004-04-27  4:07 ` Luc Teirlinck
  2004-04-27  7:42 ` Juanma Barranquero
  0 siblings, 2 replies; 3+ messages in thread
From: Luc Teirlinck @ 2004-04-27  0:11 UTC (permalink / raw)


I recently implemented changes to the ielm read-only prompt.  An
obvious question is: what is so special about the _ielm_ prompt vs
other comint prompts?  Making the comint prompt _optionally_ read-only
(not by default) has been discussed before, quite a while ago, but
apparently nothing has been done.  What about the following as a
start?  Like the new ielm prompt, it also protects against accidental
pasting inside the prompt (most notably in the invisible trailing
space part of the prompt).  If this seems OK, then maybe further
possible improvements might be functions comint-kill-whole-line and
comint-kill-region, whose only difference with the regular functions
would be that they bind inhibit-read-only to t around the call,  That
would help people like me who like to "clean up" comint buffers after
messing them up by doing stupidities.

===File ~/comint-diff=======================================
*** comint.el	22 Apr 2004 18:50:10 -0500	1.295
--- comint.el	26 Apr 2004 16:37:34 -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,1717 ----
                (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
! 		(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-diff=========================================
*** ielm.el	25 Apr 2004 21:59:05 -0500	1.41
--- ielm.el	26 Apr 2004 14:47:55 -0500	
***************
*** 478,490 ****
    (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)
--- 478,485 ----
    (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) 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)
============================================================

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: read-only comint-prompt
  2004-04-27  0:11 read-only comint-prompt Luc Teirlinck
@ 2004-04-27  4:07 ` Luc Teirlinck
  2004-04-27  7:42 ` Juanma Barranquero
  1 sibling, 0 replies; 3+ messages in thread
From: Luc Teirlinck @ 2004-04-27  4:07 UTC (permalink / raw)
  Cc: emacs-devel

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))))
============================================================

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: read-only comint-prompt
  2004-04-27  0:11 read-only comint-prompt Luc Teirlinck
  2004-04-27  4:07 ` Luc Teirlinck
@ 2004-04-27  7:42 ` Juanma Barranquero
  1 sibling, 0 replies; 3+ messages in thread
From: Juanma Barranquero @ 2004-04-27  7:42 UTC (permalink / raw)



On Mon, 26 Apr 2004 19:11:40 -0500 (CDT)
Luc Teirlinck <teirllm@dms.auburn.edu> wrote:

> I recently implemented changes to the ielm read-only prompt.  An
> obvious question is: what is so special about the _ielm_ prompt vs
> other comint prompts?

Nothing, probably.

> Making the comint prompt _optionally_ read-only
> (not by default) has been discussed before, quite a while ago, but
> apparently nothing has been done.

That's right.  Originally I did the IELM prompt read-only in the way it
was because someone (Stefan or Miles, ISTR) said exactly that: it was
something that should be generalized.  The issue has been sleeping until
someone has deemed it important enough to fix it. That's you :)

                                                                Juanma

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-04-27  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-27  0:11 read-only comint-prompt Luc Teirlinck
2004-04-27  4:07 ` Luc Teirlinck
2004-04-27  7:42 ` Juanma Barranquero

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).