From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: Re: read-only comint-prompt Date: Mon, 26 Apr 2004 23:07:57 -0500 (CDT) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200404270407.i3R47vb01156@raven.dms.auburn.edu> References: <200404270011.i3R0Bek29614@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1083040524 15155 80.91.224.253 (27 Apr 2004 04:35:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 27 Apr 2004 04:35:24 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Apr 27 06:35:16 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BIKJQ-00007t-00 for ; Tue, 27 Apr 2004 06:35:16 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BIKJO-0006cJ-00 for ; Tue, 27 Apr 2004 06:35:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BIJyl-0001kL-9U for emacs-devel@quimby.gnus.org; Tue, 27 Apr 2004 00:13:55 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BIJx3-0000xM-8r for emacs-devel@gnu.org; Tue, 27 Apr 2004 00:12:09 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BIJwV-0000dP-Gw for emacs-devel@gnu.org; Tue, 27 Apr 2004 00:12:06 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BIJwU-0000ba-VF for emacs-devel@gnu.org; Tue, 27 Apr 2004 00:11:35 -0400 Original-Received: from raven.dms.auburn.edu (raven.dms.auburn.edu [131.204.53.29]) by manatee.dms.auburn.edu (8.12.10/8.12.10) with ESMTP id i3R4BATS028404; Mon, 26 Apr 2004 23:11:10 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.6+Sun/8.11.6) id i3R47vb01156; Mon, 26 Apr 2004 23:07:57 -0500 (CDT) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: teirllm@dms.auburn.edu In-reply-to: <200404270011.i3R0Bek29614@raven.dms.auburn.edu> (message from Luc Teirlinck on Mon, 26 Apr 2004 19:11:40 -0500 (CDT)) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:22207 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:22207 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 \\\\[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 \\\\[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 \\\\[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-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)))) ============================================================