]> code.delx.au - gnu-emacs/blobdiff - lisp/comint.el
(x-select-enable-clipboard): Customize (per lispref).
[gnu-emacs] / lisp / comint.el
index a48dd1e7ce327059c4133ef93cbcaa0719d0d61e..f3922f3407dc32e9e015e2531ed8c3a23a4dc075 100644 (file)
@@ -218,6 +218,7 @@ The face used is `comint-highlight-input'."
 (defcustom comint-highlight-prompt t
   "*If non-nil, highlight program prompts.
 The face used is `comint-highlight-prompt'."
+  :type 'boolean
   :group 'comint)
 
 (defface comint-highlight-prompt
@@ -511,7 +512,6 @@ Entry to this mode runs the hooks on `comint-mode-hook'."
   (make-local-variable 'comint-scroll-to-bottom-on-input)
   (make-local-variable 'comint-scroll-to-bottom-on-output)
   (make-local-variable 'comint-scroll-show-maximum-output)
-  (make-local-hook 'pre-command-hook)
   (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom t t)
   (make-local-hook 'comint-output-filter-functions)
   (make-local-hook 'comint-exec-hook)
@@ -521,7 +521,9 @@ Entry to this mode runs the hooks on `comint-mode-hook'."
   (make-local-variable 'comint-file-name-quote-list)
   (make-local-variable 'comint-accum-marker)
   (setq comint-accum-marker (make-marker))
-  (set-marker comint-accum-marker nil))
+  (set-marker comint-accum-marker nil)
+  ;; This behavior is not useful in comint buffers, and is annoying
+  (set (make-local-variable 'next-line-add-newlines) nil))
 
 (if comint-mode-map
     nil
@@ -574,10 +576,10 @@ Entry to this mode runs the hooks on `comint-mode-hook'."
     (cons "In/Out" (make-sparse-keymap "In/Out")))
   (define-key comint-mode-map [menu-bar inout delete-output]
     '("Delete Current Output Group" . comint-delete-output))
-  (define-key comint-mode-map [menu-bar inout write-output]
-    '("Write Current Output Group to File" . comint-write-output))
   (define-key comint-mode-map [menu-bar inout append-output-to-file]
     '("Append Current Output Group to File" . comint-append-output-to-file))
+  (define-key comint-mode-map [menu-bar inout write-output]
+    '("Write Current Output Group to File" . comint-write-output))
   (define-key comint-mode-map [menu-bar inout next-prompt]
     '("Forward Output Group" . comint-next-prompt))
   (define-key comint-mode-map [menu-bar inout previous-prompt]
@@ -637,6 +639,28 @@ BUFFER can be either a buffer or the name of one."
   (let ((proc (get-buffer-process buffer)))
     (and proc (memq (process-status proc) '(open run stop)))))
 
+;;;###autoload
+(defun make-comint-in-buffer (name buffer program &optional startfile &rest switches)
+  "Make a comint process NAME in BUFFER, running PROGRAM.
+If BUFFER is nil, it defaults to NAME surrounded by `*'s.
+PROGRAM should be either a string denoting an executable program to create
+via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP
+connection to be opened via `open-network-stream'.  If there is already a
+running process in that buffer, it is not restarted.  Optional third arg
+STARTFILE is the name of a file to send the contents of to the process.
+
+If PROGRAM is a string, any more args are arguments to PROGRAM."
+  (or (fboundp 'start-process)
+      (error "Multi-processing is not supported for this system"))
+  (setq buffer (get-buffer-create (or buffer (concat "*" name "*"))))
+  ;; If no process, or nuked process, crank up a new one and put buffer in
+  ;; comint mode.  Otherwise, leave buffer and existing process alone.
+  (unless (comint-check-proc buffer)
+    (with-current-buffer buffer
+      (comint-mode)) ; Install local vars, mode, keymap, ...
+    (comint-exec buffer name program startfile switches))
+  buffer)
+
 ;;;###autoload
 (defun make-comint (name program &optional startfile &rest switches)
   "Make a comint process NAME in a buffer, running PROGRAM.
@@ -648,16 +672,7 @@ running process in that buffer, it is not restarted.  Optional third arg
 STARTFILE is the name of a file to send the contents of to the process.
 
 If PROGRAM is a string, any more args are arguments to PROGRAM."
-  (or (fboundp 'start-process)
-      (error "Multi-processing is not supported for this system"))
-  (let ((buffer (get-buffer-create (concat "*" name "*"))))
-    ;; If no process, or nuked process, crank up a new one and put buffer in
-    ;; comint mode.  Otherwise, leave buffer and existing process alone.
-    (unless (comint-check-proc buffer)
-      (with-current-buffer buffer
-       (comint-mode)) ; Install local vars, mode, keymap, ...
-      (comint-exec buffer name program startfile switches))
-    buffer))
+  (apply #'make-comint-in-buffer name nil program startfile switches))
 
 ;;;###autoload
 (defun comint-run (program)
@@ -1090,14 +1105,15 @@ See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'.
 Returns t if successful."
   (interactive)
   (if (and comint-input-autoexpand
-          (string-match "!\\|^\\^" (funcall comint-get-old-input))
           (if comint-use-prompt-regexp-instead-of-fields
               ;; Use comint-prompt-regexp
-              (save-excursion (beginning-of-line)
-                              (looking-at comint-prompt-regexp))
+              (save-excursion
+                (beginning-of-line)
+                (looking-at (concat comint-prompt-regexp "!\\|\\^")))
             ;; Use input fields.  User input that hasn't been entered
             ;; yet, at the end of the buffer, has a nil `field' property.
-            (null (get-char-property (point) 'field))))
+            (and (null (get-char-property (point) 'field))
+                 (string-match "!\\|^\\^" (field-string)))))
       ;; Looks like there might be history references in the command.
       (let ((previous-modified-tick (buffer-modified-tick)))
        (comint-replace-by-expanded-history-before-point silent start)
@@ -1314,6 +1330,16 @@ Argument 0 is the command name."
 ;;
 ;; Input processing stuff
 ;;
+(defun comint-add-to-input-history (cmd)
+  "Add CMD to the input history.
+Ignore duplicates if `comint-input-ignoredups' is non-nil."
+  (if (and (funcall comint-input-filter cmd)
+          (or (null comint-input-ignoredups)
+              (not (ring-p comint-input-ring))
+              (ring-empty-p comint-input-ring)
+              (not (string-equal (ring-ref comint-input-ring 0)
+                                 cmd))))
+      (ring-insert comint-input-ring cmd)))
 
 (defun comint-send-input ()
   "Send input to process.
@@ -1389,13 +1415,7 @@ Similarly for Soar, Scheme, etc."
              (delete-region pmark (point))
            (insert ?\n))
 
-         (if (and (funcall comint-input-filter history)
-                  (or (null comint-input-ignoredups)
-                      (not (ring-p comint-input-ring))
-                      (ring-empty-p comint-input-ring)
-                      (not (string-equal (ring-ref comint-input-ring 0)
-                                         history))))
-             (ring-insert comint-input-ring history))
+         (comint-add-to-input-history history)
 
          (run-hook-with-args 'comint-input-filter-functions
                              (concat input "\n"))
@@ -1411,8 +1431,7 @@ Similarly for Soar, Scheme, etc."
                  ;; input.  The terminating newline is put into a special
                  ;; `boundary' field to make cursor movement between input
                  ;; and output fields smoother.
-                 (overlay-put over 'field 'input)
-                 (overlay-put over 'front-sticky t))
+                 (overlay-put over 'field 'input))
                (when comint-highlight-input
                  (overlay-put over 'face 'comint-highlight-input)
                  (overlay-put over 'mouse-face 'highlight)
@@ -1421,7 +1440,6 @@ Similarly for Soar, Scheme, etc."
              ;; Make an overlay for the terminating newline
              (let ((over (make-overlay end (1+ end) nil t nil)))
                (overlay-put over 'field 'boundary)
-               (overlay-put over 'rear-nonsticky t)
                (overlay-put over 'evaporate t))))
 
          (comint-snapshot-last-prompt)
@@ -1563,8 +1581,6 @@ This variable is permanent-local.")
                (let ((over (make-overlay comint-last-output-start (point))))
                  (overlay-put over 'field 'output)
                  (overlay-put over 'inhibit-line-move-field-capture t)
-                 (overlay-put over 'front-sticky t)
-                 (overlay-put over 'rear-nonsticky t)
                  (overlay-put over 'evaporate t)
                  (setq comint-last-output-overlay over))))
 
@@ -1581,11 +1597,10 @@ This variable is permanent-local.")
                      (move-overlay comint-last-prompt-overlay
                                    prompt-start (point))
                    ;; Need to create the overlay
-                   (let ((over (make-overlay prompt-start (point))))
-                     (overlay-put over 'face 'comint-highlight-prompt)
-                     (overlay-put over 'front-sticky t)
-                     (overlay-put over 'rear-nonsticky t)
-                     (setq comint-last-prompt-overlay over))))))
+                   (setq comint-last-prompt-overlay
+                         (make-overlay prompt-start (point)))
+                   (overlay-put comint-last-prompt-overlay
+                                'face 'comint-highlight-prompt)))))
 
            (goto-char saved-point)
 
@@ -1700,8 +1715,10 @@ value of `comint-use-prompt-regexp-instead-of-fields'."
          (end-of-line)
          (buffer-substring beg (point))))
     ;; Return the contents of the field at the current point.
-    (field-string)))
-
+    (let ((pos (field-beginning (point))))
+      (unless (eq (get-char-property pos 'field) 'input)
+       (error "Not an input field"))
+      (field-string pos))))
 
 (defun comint-copy-old-input ()
   "Insert after prompt old input at point as new input to be edited.
@@ -1920,6 +1937,14 @@ otherwise."
     (write-region comint-last-input-end (point) filename
                  append nil nil mustbenew)))
 
+;; This function exists for the benefit of the menu; from the keyboard,
+;; users can just use `comint-write-output' with a prefix arg.
+(defun comint-append-output-to-file (filename)
+  "Append output from interpreter since last input to FILENAME.
+Any prompt at the end of the output is not written."
+  (interactive "fAppend output to file: ")
+  (comint-write-output filename t))
+
 (defun comint-show-output ()
   "Display start of this batch of interpreter output at top of window.
 Sets mark to the value of point when this command is run."
@@ -2308,7 +2333,11 @@ This mirrors the optional behavior of tcsh."
 If a cons pair, it should be of the form (DIRSUFFIX . FILESUFFIX) where
 DIRSUFFIX and FILESUFFIX are strings added on unambiguous or exact completion.
 This mirrors the optional behavior of tcsh."
-  :type 'boolean
+  :type '(choice (const :tag "None" nil)
+                (const :tag "Add /" t)
+                (cons :tag "Suffix pair"
+                      (string :tag "Directory suffix")
+                      (string :tag "File suffix")))
   :group 'comint-completion)
 
 (defcustom comint-completion-recexact nil