aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-06-01 05:31:15 +0000
committerRichard M. Stallman1993-06-01 05:31:15 +0000
commitcccd719e434f078dfc64891f6579564d84c24334 (patch)
tree247b18e30dfea616077caa2d48d33c3a708c5189
parent130bf67c14ed2eb6c1673fa65402eb6f931c2ba0 (diff)
downloademacs-cccd719e434f078dfc64891f6579564d84c24334.tar.gz
emacs-cccd719e434f078dfc64891f6579564d84c24334.zip
(comint-filter): Put window-start before the input.
-rw-r--r--lisp/comint.el132
1 files changed, 68 insertions, 64 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index bb20f2ab578..fb97ec7a5a4 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -140,7 +140,7 @@ This is a good thing to set in mode hooks.")
140 "Size of input history ring.") 140 "Size of input history ring.")
141 141
142(defvar comint-process-echoes nil 142(defvar comint-process-echoes nil
143 "*If non-`nil', assume that the subprocess echoes any input. 143 "*If non-nil, assume that the subprocess echoes any input.
144If so, delete one copy of the input so that only one copy eventually 144If so, delete one copy of the input so that only one copy eventually
145appears in the buffer. 145appears in the buffer.
146 146
@@ -151,46 +151,46 @@ This variable is buffer-local.")
151 "Function that submits old text in comint mode. 151 "Function that submits old text in comint mode.
152This function is called when return is typed while the point is in old text. 152This function is called when return is typed while the point is in old text.
153It returns the text to be submitted as process input. The default is 153It returns the text to be submitted as process input. The default is
154comint-get-old-input-default, which grabs the current line, and strips off 154`comint-get-old-input-default', which grabs the current line, and strips off
155leading text matching comint-prompt-regexp") 155leading text matching `comint-prompt-regexp'.")
156 156
157(defvar comint-input-sentinel (function ignore) 157(defvar comint-input-sentinel (function ignore)
158 "Called on each input submitted to comint mode process by comint-send-input. 158 "Called on each input submitted to comint mode process by `comint-send-input'.
159Thus it can, for instance, track cd/pushd/popd commands issued to the csh.") 159Thus it can, for instance, track cd/pushd/popd commands issued to the csh.")
160 160
161(defvar comint-input-filter 161(defvar comint-input-filter
162 (function (lambda (str) (not (string-match "\\`\\s *\\'" str)))) 162 (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
163 "Predicate for filtering additions to input history. 163 "Predicate for filtering additions to input history.
164Only inputs answering true to this function are saved on the input 164Only inputs answering true to this function are saved on the input
165history list. Default is to save anything that isn't all whitespace") 165history list. Default is to save anything that isn't all whitespace")
166 166
167(defvar comint-input-sender (function comint-simple-send) 167(defvar comint-input-sender (function comint-simple-send)
168 "Function to actually send to PROCESS the STRING submitted by user. 168 "Function to actually send to PROCESS the STRING submitted by user.
169Usually this is just 'comint-simple-send, but if your mode needs to 169Usually this is just `comint-simple-send', but if your mode needs to
170massage the input string, this is your hook. This is called from 170massage the input string, put a different function here.
171the user command comint-send-input. comint-simple-send just sends 171`comint-simple-send' just sends the string plus a newline.
172the string plus a newline.") 172This is called from the user command `comint-send-input'.")
173 173
174(defvar comint-eol-on-send 'T 174(defvar comint-eol-on-send t
175 "If non-nil, then jump to the end of the line before sending input to process. 175 "*Non-nil means go to the end of the line before sending input to process.
176See comint-send-input") 176See `comint-send-input'.")
177 177
178(defvar comint-mode-hook '() 178(defvar comint-mode-hook '()
179 "Called upon entry into comint-mode 179 "Called upon entry into comint-mode
180This is run before the process is cranked up.") 180This is run before the process is cranked up.")
181 181
182(defvar comint-exec-hook '() 182(defvar comint-exec-hook '()
183 "Called each time a process is exec'd by comint-exec. 183 "Called each time a process is exec'd by `comint-exec'.
184This is called after the process is cranked up. It is useful for things that 184This is called after the process is cranked up. It is useful for things that
185must be done each time a process is executed in a comint-mode buffer (e.g., 185must be done each time a process is executed in a comint mode buffer (e.g.,
186(process-kill-without-query)). In contrast, the comint-mode-hook is only 186`(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only
187executed once when the buffer is created.") 187executed once when the buffer is created.")
188 188
189(defvar comint-mode-map nil) 189(defvar comint-mode-map nil)
190 190
191(defvar comint-ptyp t 191(defvar comint-ptyp t
192 "True if communications via pty; false if by pipe. Buffer local. 192 "True if communications via pty; false if by pipe. Buffer local.
193This is to work around a bug in emacs process signalling.") 193This is to work around a bug in Emacs process signalling.")
194 194
195;;(defvar comint-last-input-match "" 195;;(defvar comint-last-input-match ""
196;; "Last string searched for by comint input history search, for defaulting. 196;; "Last string searched for by comint input history search, for defaulting.
@@ -208,20 +208,19 @@ This is to work around a bug in emacs process signalling.")
208Interpreter name is same as buffer name, sans the asterisks. 208Interpreter name is same as buffer name, sans the asterisks.
209Return at end of buffer sends line as input. 209Return at end of buffer sends line as input.
210Return not at end copies rest of line to end and sends it. 210Return not at end copies rest of line to end and sends it.
211Setting mode variable comint-eol-on-send means jump to the end of the line 211Setting variable `comint-eol-on-send' means jump to the end of the line
212before submitting new input. 212before submitting new input.
213 213
214This mode is typically customised to create inferior-lisp-mode, 214This mode is typically customised to create Inferior Lisp mode,
215shell-mode, etc.. This can be done by setting the hooks 215Shell mode, etc. This can be done by setting the hooks
216comint-input-sentinel, comint-input-filter, comint-input-sender and 216`comint-input-sentinel', `comint-input-filter', `comint-input-sender' and
217comint-get-old-input to appropriate functions, and the variable 217`comint-get-old-input' to appropriate functions, and the variable
218comint-prompt-regexp to the appropriate regular expression. 218`comint-prompt-regexp' to the appropriate regular expression.
219 219
220An input history is maintained of size comint-input-ring-size, and 220An input history is maintained of size `comint-input-ring-size', and
221can be accessed with the commands comint-next-input [\\[comint-next-input]] and 221can be accessed with the commands \\[comint-next-input] and \\[comint-previous-input].
222comint-previous-input [\\[comint-previous-input]]. Commands not keybound by 222Commands with no default key bindings include `send-invisible',
223default are send-invisible, comint-dynamic-complete, and 223`comint-dynamic-complete', and `comint-list-dynamic-completions'.
224comint-list-dynamic-completions.
225 224
226If you accidentally suspend your process, use \\[comint-continue-subjob] 225If you accidentally suspend your process, use \\[comint-continue-subjob]
227to continue it. 226to continue it.
@@ -287,16 +286,16 @@ Entry to this mode runs the hooks on comint-mode-hook"
287;;; so that client modes won't interfere with each other. This function 286;;; so that client modes won't interfere with each other. This function
288;;; isn't necessary in emacs 18.5x, but we keep it around for 18.4x versions. 287;;; isn't necessary in emacs 18.5x, but we keep it around for 18.4x versions.
289(defun full-copy-sparse-keymap (km) 288(defun full-copy-sparse-keymap (km)
290 "Recursively copy the sparse keymap KM" 289 "Recursively copy the sparse keymap KM."
291 (cond ((consp km) 290 (cond ((consp km)
292 (cons (full-copy-sparse-keymap (car km)) 291 (cons (full-copy-sparse-keymap (car km))
293 (full-copy-sparse-keymap (cdr km)))) 292 (full-copy-sparse-keymap (cdr km))))
294 (t km))) 293 (t km)))
295 294
296(defun comint-check-proc (buffer) 295(defun comint-check-proc (buffer)
297 "True if there is a process associated w/buffer BUFFER, and 296 "True if there is a living process associated w/buffer BUFFER.
298it is alive (status RUN or STOP). BUFFER can be either a buffer or the 297Living means the status is `run' or `stop'.
299name of one" 298BUFFER can be either a buffer or the name of one."
300 (let ((proc (get-buffer-process buffer))) 299 (let ((proc (get-buffer-process buffer)))
301 (and proc (memq (process-status proc) '(run stop))))) 300 (and proc (memq (process-status proc) '(run stop)))))
302 301
@@ -320,10 +319,10 @@ the process. Any more args are arguments to PROGRAM."
320 buffer)) 319 buffer))
321 320
322(defun comint-exec (buffer name command startfile switches) 321(defun comint-exec (buffer name command startfile switches)
323 "Fires up a process in buffer for comint modes. 322 "Start up a process in buffer BUFFER for comint modes.
324Blasts any old process running in the buffer. Doesn't set the buffer mode. 323Blasts any old process running in the buffer. Doesn't set the buffer mode.
325You can use this to cheaply run a series of processes in the same comint 324You can use this to cheaply run a series of processes in the same comint
326buffer. The hook comint-exec-hook is run after each exec." 325buffer. The hook `comint-exec-hook' is run after each exec."
327 (save-excursion 326 (save-excursion
328 (set-buffer buffer) 327 (set-buffer buffer)
329 (let ((proc (get-buffer-process buffer))) ; Blast any old process. 328 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
@@ -593,15 +592,17 @@ If N is negative, find the previous or Nth previous match."
593After the process output mark, sends all text from the process mark to 592After the process output mark, sends all text from the process mark to
594point as input to the process. Before the process output mark, calls value 593point as input to the process. Before the process output mark, calls value
595of variable `comint-get-old-input' to retrieve old input, copies it to the 594of variable `comint-get-old-input' to retrieve old input, copies it to the
596process mark, and sends it. If variable `comint-process-echoes' is `nil', 595process mark, and sends it. If variable `comint-process-echoes' is nil,
597a terminal newline is also inserted into the buffer and sent to the process 596a terminal newline is also inserted into the buffer and sent to the process
598\(if it is non-`nil', all text from the process mark to point is deleted, 597\(if it is non-nil, all text from the process mark to point is deleted,
599since it is assumed the remote process will re-echo it). The value of 598since it is assumed the remote process will re-echo it).
600variable `comint-input-sentinel' is called on the input before sending it.
601The input is entered into the input history ring, if the value of variable
602`comint-input-filter' returns non-`nil' when called on the input.
603 599
604If variable `comint-eol-on-send' is non-`nil', then point is moved to the 600The value of variable `comint-input-sentinel' is called on the input
601before sending it. The input is entered into the input history ring,
602if the value of variable `comint-input-filter' returns non-nil when
603called on the input.
604
605If variable `comint-eol-on-send' is non-nil, then point is moved to the
605end of line before sending the input. 606end of line before sending the input.
606 607
607`comint-get-old-input', `comint-input-sentinel', and `comint-input-filter' 608`comint-get-old-input', `comint-input-sentinel', and `comint-input-filter'
@@ -669,6 +670,10 @@ Similarly for Soar, Scheme, etc."
669 (setq oend (+ oend nchars))) 670 (setq oend (+ oend nchars)))
670 671
671 (insert-before-markers string) 672 (insert-before-markers string)
673 ;; Don't insert initial prompt outside the top of the window.
674 (if (= (window-start (selected-window)) (point))
675 (set-window-start (selected-window) (- (point) (length string))))
676
672 (and comint-last-input-end 677 (and comint-last-input-end
673 (marker-buffer comint-last-input-end) 678 (marker-buffer comint-last-input-end)
674 (= (point) comint-last-input-end) 679 (= (point) comint-last-input-end)
@@ -682,9 +687,9 @@ Similarly for Soar, Scheme, etc."
682 (set-buffer obuf))) 687 (set-buffer obuf)))
683 688
684(defun comint-get-old-input-default () 689(defun comint-get-old-input-default ()
685 "Default for comint-get-old-input. 690 "Default for `comint-get-old-input'.
686Take the current line, and discard any initial text matching 691Take the current line, and discard any initial text matching
687comint-prompt-regexp." 692`comint-prompt-regexp'."
688 (save-excursion 693 (save-excursion
689 (beginning-of-line) 694 (beginning-of-line)
690 (comint-skip-prompt) 695 (comint-skip-prompt)
@@ -693,7 +698,7 @@ comint-prompt-regexp."
693 (buffer-substring beg (point))))) 698 (buffer-substring beg (point)))))
694 699
695(defun comint-skip-prompt () 700(defun comint-skip-prompt ()
696 "Skip past the text matching regexp comint-prompt-regexp. 701 "Skip past the text matching regexp `comint-prompt-regexp'.
697If this takes us past the end of the current line, don't skip at all." 702If this takes us past the end of the current line, don't skip at all."
698 (let ((eol (save-excursion (end-of-line) (point)))) 703 (let ((eol (save-excursion (end-of-line) (point))))
699 (if (and (looking-at comint-prompt-regexp) 704 (if (and (looking-at comint-prompt-regexp)
@@ -714,7 +719,7 @@ If this takes us past the end of the current line, don't skip at all."
714(defun comint-simple-send (proc string) 719(defun comint-simple-send (proc string)
715 "Default function for sending to PROC input STRING. 720 "Default function for sending to PROC input STRING.
716This just sends STRING plus a newline. To override this, 721This just sends STRING plus a newline. To override this,
717set the hook COMINT-INPUT-SENDER." 722set the hook `comint-input-sender'."
718 (comint-send-string proc string) 723 (comint-send-string proc string)
719 (comint-send-string proc "\n")) 724 (comint-send-string proc "\n"))
720 725
@@ -724,10 +729,10 @@ If a prefix argument is given (\\[universal-argument]), then no prompt skip
724-- go straight to column 0. 729-- go straight to column 0.
725 730
726The prompt skip is done by skipping text matching the regular expression 731The prompt skip is done by skipping text matching the regular expression
727comint-prompt-regexp, a buffer local variable. 732`comint-prompt-regexp', a buffer local variable.
728 733
729If you don't like this command, reset c-a to beginning-of-line 734If you don't like this command, bind C-a to `beginning-of-line'
730in your hook, comint-mode-hook." 735in your hook, `comint-mode-hook'."
731 (interactive "P") 736 (interactive "P")
732 (beginning-of-line) 737 (beginning-of-line)
733 (if (null arg) (comint-skip-prompt))) 738 (if (null arg) (comint-skip-prompt)))
@@ -741,12 +746,11 @@ in your hook, comint-mode-hook."
741Prompt with argument PROMPT, a string. Optional argument STARS causes 746Prompt with argument PROMPT, a string. Optional argument STARS causes
742input to be echoed with '*' characters on the prompt line. Input ends with 747input to be echoed with '*' characters on the prompt line. Input ends with
743RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if 748RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if
744inhibit-quit is set because e.g. this function was called from a process 749`inhibit-quit' is set because e.g. this function was called from a process
745filter and C-g is pressed, this function will return `nil', rather than a 750filter and C-g is pressed, this function returns nil rather than a string).
746string).
747 751
748Note that the keystrokes comprising the text can still be recovered 752Note that the keystrokes comprising the text can still be recovered
749(temporarily) with \\[view-lossage]. This may be a security bug for some 753\(temporarily) with \\[view-lossage]. This may be a security bug for some
750applications." 754applications."
751 (let ((ans "") 755 (let ((ans "")
752 (c 0) 756 (c 0)
@@ -787,8 +791,8 @@ applications."
787 791
788(defun send-invisible (str) 792(defun send-invisible (str)
789 "Read a string without echoing. 793 "Read a string without echoing.
790Then send it to the process running in the current buffer. A new-line 794Then send it to the process running in the current buffer. A new-line
791is additionally sent. String is not saved on comint input history list. 795is additionally sent. String is not saved on comint input history list.
792Security bug: your string can still be temporarily recovered with 796Security bug: your string can still be temporarily recovered with
793\\[view-lossage]." 797\\[view-lossage]."
794; (interactive (list (comint-read-noecho "Enter non-echoed text"))) 798; (interactive (list (comint-read-noecho "Enter non-echoed text")))
@@ -804,14 +808,14 @@ Security bug: your string can still be temporarily recovered with
804;;; Low-level process communication 808;;; Low-level process communication
805 809
806(defvar comint-input-chunk-size 512 810(defvar comint-input-chunk-size 512
807 "*Long inputs send to comint processes are broken up into chunks of this size. 811 "*Long inputs are sent to comint processes in chunks of this size.
808If your process is choking on big inputs, try lowering the value.") 812If your process is choking on big inputs, try lowering the value.")
809 813
810(defun comint-send-string (proc str) 814(defun comint-send-string (proc str)
811 "Send PROCESS the contents of STRING as input. 815 "Send PROCESS the contents of STRING as input.
812This is equivalent to process-send-string, except that long input strings 816This is equivalent to `process-send-string', except that long input strings
813are broken up into chunks of size comint-input-chunk-size. Processes 817are broken up into chunks of size `comint-input-chunk-size'. Processes
814are given a chance to output between chunks. This can help prevent processes 818are given a chance to output between chunks. This can help prevent processes
815from hanging when you send them long inputs on some OS's." 819from hanging when you send them long inputs on some OS's."
816 (let* ((len (length str)) 820 (let* ((len (length str))
817 (i (min len comint-input-chunk-size))) 821 (i (min len comint-input-chunk-size)))
@@ -824,8 +828,8 @@ from hanging when you send them long inputs on some OS's."
824 828
825(defun comint-send-region (proc start end) 829(defun comint-send-region (proc start end)
826 "Sends to PROC the region delimited by START and END. 830 "Sends to PROC the region delimited by START and END.
827This is a replacement for process-send-region that tries to keep 831This is a replacement for `process-send-region' that tries to keep
828your process from hanging on long inputs. See comint-send-string." 832your process from hanging on long inputs. See `comint-send-string'."
829 (comint-send-string proc (buffer-substring start end))) 833 (comint-send-string proc (buffer-substring start end)))
830 834
831 835
@@ -1012,7 +1016,7 @@ Useful if you accidentally suspend the top-level process."
1012;;; This is pretty stupid about strings. It decides we're in a string 1016;;; This is pretty stupid about strings. It decides we're in a string
1013;;; if there's a quote on both sides of point on the current line. 1017;;; if there's a quote on both sides of point on the current line.
1014(defun comint-extract-string () 1018(defun comint-extract-string ()
1015 "Returns string around POINT that starts the current line or nil." 1019 "Return string around POINT that starts the current line, or nil."
1016 (save-excursion 1020 (save-excursion
1017 (let* ((point (point)) 1021 (let* ((point (point))
1018 (bol (progn (beginning-of-line) (point))) 1022 (bol (progn (beginning-of-line) (point)))
@@ -1110,7 +1114,7 @@ Useful if you accidentally suspend the top-level process."
1110 1114
1111 1115
1112(defun comint-match-partial-pathname () 1116(defun comint-match-partial-pathname ()
1113 "Returns the filename at point or causes an error." 1117 "Return the filename at point, or signal an error."
1114 (save-excursion 1118 (save-excursion
1115 (if (re-search-backward "[^~/A-Za-z0-9_.$#,=-]" nil 'move) 1119 (if (re-search-backward "[^~/A-Za-z0-9_.$#,=-]" nil 'move)
1116 (forward-char 1)) 1120 (forward-char 1))
@@ -1122,14 +1126,14 @@ Useful if you accidentally suspend the top-level process."
1122 1126
1123 1127
1124(defun comint-replace-by-expanded-filename () 1128(defun comint-replace-by-expanded-filename ()
1125"Expand the filename at point. 1129 "Expand the filename at point.
1126Replace the filename with an expanded, canonicalised, and completed 1130Replace the filename with an expanded, canonicalised, and completed
1127 replacement. 1131 replacement.
1128\"Expanded\" means environment variables (e.g., $HOME) and ~'s are 1132\"Expanded\" means environment variables (e.g., $HOME) and ~'s are
1129replaced with the corresponding directories. \"Canonicalised\" means .. 1133replaced with the corresponding directories. \"Canonicalised\" means ..
1130and \. are removed, and the filename is made absolute instead of relative. 1134and \. are removed, and the filename is made absolute instead of relative.
1131See functions expand-file-name and substitute-in-file-name. See also 1135See functions `expand-file-name' and `substitute-in-file-name'. See also
1132comint-dynamic-complete." 1136`comint-dynamic-complete'."
1133 (interactive) 1137 (interactive)
1134 (let* ((pathname (comint-match-partial-pathname)) 1138 (let* ((pathname (comint-match-partial-pathname))
1135 (pathdir (file-name-directory pathname)) 1139 (pathdir (file-name-directory pathname))