]> code.delx.au - gnu-emacs/blobdiff - lisp/term.el
respect epa-file-encrypt-to, defaulting to it when encrypting, if set, and
[gnu-emacs] / lisp / term.el
index b7eb9fd1845383548c97ad3ff3341b86eade956b..9c5115921651b2161f04af9e79cc7660d5ab2b03 100644 (file)
@@ -1,7 +1,8 @@
 ;;; term.el --- general command interpreter in a window stuff
 
-;; Copyright (C) 1988, 1990, 1992, 1994, 1995, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1990, 1992, 1994, 1995, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008, 2009, 2010
+;;   Free Software Foundation, Inc.
 
 ;; Author: Per Bothner <per@bothner.com>
 ;; Maintainer: Dan Nicolaescu <dann@ics.uci.edu>, Per Bothner <per@bothner.com>
@@ -502,8 +503,8 @@ This is a good thing to set in mode hooks.")
 (defvar term-delimiter-argument-list ()
   "List of characters to recognize as separate arguments in input.
 Strings comprising a character in this list will separate the arguments
-surrounding them, and also be regarded as arguments in their own right (unlike
-whitespace).  See `term-arguments'.
+surrounding them, and also be regarded as arguments in their own right
+\(unlike whitespace).  See `term-arguments'.
 Defaults to the empty list.
 
 For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?\\;).
@@ -1170,7 +1171,7 @@ Entry to this mode runs the hooks on `term-mode-hook'."
            (let* ((str (car cur)) (len (length str)) (start (- (point) len)))
              (if (and (>= start (point-min))
                       (string= str (buffer-substring start (point))))
-                 (progn (delete-backward-char len)
+                 (progn (delete-char (- len))
                         (setq term-kill-echo-list (cdr cur))
                         (setq term-current-column nil)
                         (setq term-current-row nil)
@@ -1203,11 +1204,8 @@ Entry to this mode runs the hooks on `term-mode-hook'."
   "Send the last character typed through the terminal-emulator
 without any interpretation."
   (interactive)
-  ;; Convert `return' to C-m, etc.
-  (when (and (symbolp last-input-event)
-            (get last-input-event 'ascii-character))
-    (setq last-input-event (get last-input-event 'ascii-character)))
-  (term-send-raw-string (make-string 1 last-input-event)))
+  (let ((keys (this-command-keys)))
+    (term-send-raw-string (string (aref keys (1- (length keys)))))))
 
 (defun term-send-raw-meta ()
   (interactive)
@@ -1234,8 +1232,7 @@ without any interpretation."
   (if (featurep 'xemacs)
       (term-send-raw-string
        (or (condition-case () (x-get-selection) (error ()))
-          (x-get-cutbuffer)
-          (error "No selection or cut buffer available")))
+          (error "No selection available")))
     ;; Give temporary modes such as isearch a chance to turn off.
     (run-hooks 'mouse-leave-buffer-hook)
     (setq this-command 'yank)
@@ -1303,7 +1300,6 @@ you type \\[term-send-input] which sends the current line to the inferior."
         (term-page (when (term-pager-enabled) " page"))
         (serial-item-speed)
         (serial-item-config)
-        (temp)
         (proc (get-buffer-process (current-buffer))))
     (when (and (term-check-proc (current-buffer))
                (equal (process-type nil) 'serial))
@@ -1347,8 +1343,7 @@ the process.  Any more args are arguments to PROGRAM."
     ;; If no process, or nuked process, crank up a new one and put buffer in
     ;; term mode.  Otherwise, leave buffer and existing process alone.
     (cond ((not (term-check-proc buffer))
-          (save-excursion
-            (set-buffer buffer)
+          (with-current-buffer buffer
             (term-mode)) ; Install local vars, mode, keymap, ...
           (term-exec buffer name program startfile switches)))
     buffer))
@@ -1375,9 +1370,8 @@ commands to use in that buffer.
 Blasts any old process running in the buffer.  Doesn't set the buffer mode.
 You can use this to cheaply run a series of processes in the same term
 buffer.  The hook `term-exec-hook' is run after each exec."
-  (save-excursion
-    (set-buffer buffer)
-    (let ((proc (get-buffer-process buffer)))  ; Blast any old process.
+  (with-current-buffer buffer
+    (let ((proc (get-buffer-process buffer))) ; Blast any old process.
       (when proc (delete-process proc)))
     ;; Crank up a new process
     (let ((proc (term-exec-1 name buffer command switches)))
@@ -1389,20 +1383,19 @@ buffer.  The hook `term-exec-hook' is run after each exec."
       (set-process-filter proc 'term-emulate-terminal)
       (set-process-sentinel proc 'term-sentinel)
       ;; Feed it the startfile.
-      (cond (startfile
-            ;;This is guaranteed to wait long enough
-            ;;but has bad results if the term does not prompt at all
-            ;;      (while (= size (buffer-size))
-            ;;        (sleep-for 1))
-            ;;I hope 1 second is enough!
-            (sleep-for 1)
-            (goto-char (point-max))
-            (insert-file-contents startfile)
-            (setq startfile (buffer-substring (point) (point-max)))
-            (delete-region (point) (point-max))
-            (term-send-string proc startfile)))
+      (when startfile
+        ;;This is guaranteed to wait long enough
+        ;;but has bad results if the term does not prompt at all
+        ;;          (while (= size (buffer-size))
+        ;;            (sleep-for 1))
+        ;;I hope 1 second is enough!
+        (sleep-for 1)
+        (goto-char (point-max))
+        (insert-file-contents startfile)
+       (term-send-string
+        proc (delete-and-extract-region (point) (point-max)))))
     (run-hooks 'term-exec-hook)
-    buffer)))
+    buffer))
 
 (defun term-sentinel (proc msg)
   "Sentinel for term buffers.
@@ -1412,24 +1405,16 @@ The main purpose is to get rid of the local keymap."
       (if (null (buffer-name buffer))
          ;; buffer killed
          (set-process-buffer proc nil)
-       (let ((obuf (current-buffer)))
-         ;; save-excursion isn't the right thing if
-         ;; process-buffer is current-buffer
-         (unwind-protect
-             (progn
-               ;; Write something in the compilation buffer
-               ;; and hack its mode line.
-               (set-buffer buffer)
-               ;; Get rid of local keymap.
-               (use-local-map nil)
-               (term-handle-exit (process-name proc)
-                                 msg)
-               ;; Since the buffer and mode line will show that the
-               ;; process is dead, we can delete it now.  Otherwise it
-               ;; will stay around until M-x list-processes.
-               (delete-process proc))
-           (set-buffer obuf)))
-       ))))
+       (with-current-buffer buffer
+          ;; Write something in the compilation buffer
+          ;; and hack its mode line.
+          ;; Get rid of local keymap.
+          (use-local-map nil)
+          (term-handle-exit (process-name proc) msg)
+          ;; Since the buffer and mode line will show that the
+          ;; process is dead, we can delete it now.  Otherwise it
+          ;; will stay around until M-x list-processes.
+          (delete-process proc))))))
 
 (defun term-handle-exit (process-name msg)
   "Write process exit (or other change) message MSG in the current buffer."
@@ -1531,7 +1516,7 @@ if [ $1 = .. ]; then shift; fi; exec \"$@\""
 ;; term-replace-by-expanded-history-before-point Workhorse function.
 
 (defun term-read-input-ring (&optional silent)
-  "Sets the buffer's `term-input-ring' from a history file.
+  "Set the buffer's `term-input-ring' from a history file.
 The name of the file is given by the variable `term-input-ring-file-name'.
 The history ring is of size `term-input-ring-size', regardless of file size.
 If `term-input-ring-file-name' is nil this function does nothing.
@@ -1557,8 +1542,7 @@ See also `term-input-ignoredups' and `term-write-input-ring'."
               (count 0)
               (ring (make-ring term-input-ring-size)))
           (unwind-protect
-              (save-excursion
-                (set-buffer history-buf)
+              (with-current-buffer history-buf
                 (widen)
                 (erase-buffer)
                 (insert-file-contents file)
@@ -1580,7 +1564,7 @@ See also `term-input-ignoredups' and `term-write-input-ring'."
                 term-input-ring-index nil)))))
 
 (defun term-write-input-ring ()
-  "Writes the buffer's `term-input-ring' to a history file.
+  "Write the buffer's `term-input-ring' to a history file.
 The name of the file is given by the variable `term-input-ring-file-name'.
 The original contents of the file are lost if `term-input-ring' is not empty.
 If `term-input-ring-file-name' is nil this function does nothing.
@@ -1601,8 +1585,7 @@ See also `term-read-input-ring'."
                (index (ring-length ring)))
           ;; Write it all out into a buffer first.  Much faster, but messier,
           ;; than writing it one line at a time.
-          (save-excursion
-            (set-buffer history-buf)
+          (with-current-buffer history-buf
             (erase-buffer)
             (while (> index 0)
               (setq index (1- index))
@@ -1816,15 +1799,11 @@ Returns t if successful."
   "Expand directory stack reference before point.
 See `term-replace-by-expanded-history'.  Returns t if successful."
   (save-excursion
-    (let ((toend (- (save-excursion (end-of-line nil) (point)) (point)))
+    (let ((toend (- (line-end-position) (point)))
          (start (progn (term-bol nil) (point))))
       (while (progn
-              (skip-chars-forward "^!^"
-                                  (save-excursion
-                                    (end-of-line nil) (- (point) toend)))
-              (< (point)
-                 (save-excursion
-                   (end-of-line nil) (- (point) toend))))
+              (skip-chars-forward "^!^" (- (line-end-position) toend))
+              (< (point) (- (line-end-position) toend)))
        ;; This seems a bit complex.  We look for references such as !!, !-num,
        ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^.
        ;; If that wasn't enough, the plings can be suffixed with argument
@@ -2013,12 +1992,12 @@ Argument 0 is the command name."
   "Send input to process.
 After the process output mark, sends all text from the process mark to
 point as input to the process.  Before the process output mark, calls value
-of variable term-get-old-input to retrieve old input, copies it to the
+of variable `term-get-old-input' to retrieve old input, copies it to the
 process mark, and sends it.  A terminal newline is also inserted into the
 buffer and sent to the process.  The list of function names contained in the
 value of `term-input-filter-functions' is called on the input before sending
 it.  The input is entered into the input history ring, if the value of variable
-term-input-filter returns non-nil when called on the input.
+`term-input-filter' returns non-nil when called on the input.
 
 Any history reference may be expanded depending on the value of the variable
 `term-input-autoexpand'.  The list of function names contained in the value
@@ -2130,7 +2109,7 @@ Calls `term-get-old-input' to get old input."
 (defun term-skip-prompt ()
   "Skip past the text matching regexp `term-prompt-regexp'.
 If this takes us past the end of the current line, don't skip at all."
-  (let ((eol (save-excursion (end-of-line) (point))))
+  (let ((eol (line-end-position)))
     (when (and (looking-at term-prompt-regexp)
               (<= (match-end 0) eol))
       (goto-char (match-end 0)))))
@@ -2154,7 +2133,7 @@ set the hook `term-input-sender'."
   (term-send-string proc "\n"))
 
 (defun term-bol (arg)
-  "Goes to the beginning of line, then skips past the prompt, if any.
+  "Go to the beginning of line, then skip past the prompt, if any.
 If a prefix argument is given (\\[universal-argument]), then no prompt skip
 -- go straight to column 0.
 
@@ -2460,10 +2439,8 @@ See `term-prompt-regexp'."
               (y-or-n-p (format "Save buffer %s first? "
                                 (buffer-name buff))))
       ;; save BUFF.
-      (let ((old-buffer (current-buffer)))
-       (set-buffer buff)
-       (save-buffer)
-       (set-buffer old-buffer)))))
+      (with-current-buffer buff
+       (save-buffer)))))
 
 
 ;; (TERM-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
@@ -2491,11 +2468,10 @@ See `term-prompt-regexp'."
   "Return string around `point' that starts the current line or nil."
   (save-excursion
     (let* ((point (point))
-          (bol (progn (beginning-of-line) (point)))
-          (eol (progn (end-of-line) (point)))
-          (start (progn (goto-char point)
-                        (and (search-backward "\"" bol t)
-                             (1+ (point)))))
+          (bol (line-beginning-position))
+          (eol (line-end-position))
+          (start (and (search-backward "\"" bol t)
+                       (1+ (point))))
           (end (progn (goto-char point)
                       (and (search-forward "\"" eol t)
                            (1- (point))))))
@@ -2635,10 +2611,7 @@ See `term-prompt-regexp'."
 
 (defun term-move-columns (delta)
   (setq term-current-column (max 0 (+ (term-current-column) delta)))
-  (let (point-at-eol)
-    (save-excursion
-      (end-of-line)
-      (setq point-at-eol (point)))
+  (let ((point-at-eol (line-end-position)))
     (move-to-column term-current-column t)
     ;; If move-to-column extends the current line it will use the face
     ;; from the last character on the line, set the face for the chars
@@ -2682,7 +2655,6 @@ See `term-prompt-regexp'."
   (while (string-match "\eAnSiT.+\n" message)
     ;; Extract the command code and the argument.
     (let* ((start (match-beginning 0))
-          (end (match-end 0))
           (command-code (aref message (+ start 6)))
           (argument
            (save-match-data
@@ -3453,8 +3425,7 @@ The top-most line is line 0."
 (defun term-display-buffer-line (buffer line)
   (let* ((window (display-buffer buffer t))
         (pos))
-    (save-excursion
-      (set-buffer buffer)
+    (with-current-buffer buffer
       (save-restriction
        (widen)
        (goto-char (point-min))
@@ -3497,7 +3468,8 @@ The top-most line is line 0."
 (defun term-process-pager ()
   (when (not term-pager-break-map)
     (let* ((map (make-keymap))
-          (i 0) tmp)
+           ;; (i 0)
+           tmp)
       ;; (while (< i 128)
       ;;   (define-key map (make-string 1 i) 'term-send-raw)
       ;;   (setq i (1+ i)))
@@ -3780,7 +3752,7 @@ all pending output has been dealt with."))
       (goto-char saved-point))))
 
 (defun term-erase-in-display (kind)
-  "Erases (that is blanks out) part of the window.
+  "Erase (that is blank out) part of the window.
 If KIND is 0, erase from (point) to (point-max);
 if KIND is 1, erase from home to point; else erase from home to point-max."
   (term-handle-deferred-scroll)
@@ -3817,10 +3789,8 @@ if KIND is 1, erase from home to point; else erase from home to point-max."
     (term-vertical-motion 1)
     (when (bolp)
       (backward-char))
-    (setq save-eol (point))
-    (save-excursion
-      (end-of-line)
-      (setq pnt-at-eol (point)))
+    (setq save-eol (point)
+          pnt-at-eol (line-end-position))
     (move-to-column (+ (term-start-line-column) (- term-width count)) t)
     ;; If move-to-column extends the current line it will use the face
     ;; from the last character on the line, set the face for the chars
@@ -3896,8 +3866,7 @@ if KIND is 1, erase from home to point; else erase from home to point-max."
             (message "Output logging off."))
     (if (get-buffer name)
        nil
-      (save-excursion
-       (set-buffer (get-buffer-create name))
+      (with-current-buffer (get-buffer-create name)
        (fundamental-mode)
        (buffer-disable-undo (current-buffer))
        (erase-buffer)))
@@ -3936,7 +3905,6 @@ This is a good place to put keybindings.")
 ;; term-dynamic-list-filename-completions List completions in help buffer.
 ;; term-replace-by-expanded-filename   Expand and complete filename at point;
 ;;                                     replace with expanded/completed name.
-;; term-dynamic-simple-complete                Complete stub given candidates.
 
 ;; These are not installed in the term-mode keymap.  But they are
 ;; available for people who want them.  Shell-mode installs them:
@@ -4145,6 +4113,7 @@ See also `term-dynamic-complete-filename'."
                   (t
                    (message "Partially completed")
                    'partial)))))))
+(make-obsolete 'term-dynamic-simple-complete 'completion-in-region "23.2")
 
 
 (defun term-dynamic-list-filename-completions ()
@@ -4169,8 +4138,7 @@ Typing SPC flushes the help buffer."
       (display-completion-list (sort completions 'string-lessp)))
     (message "Hit space to flush")
     (let (key first)
-      (if (save-excursion
-           (set-buffer (get-buffer "*Completions*"))
+      (if (with-current-buffer (get-buffer "*Completions*")
            (setq key (read-key-sequence nil)
                  first (aref key 0))
            (and (consp first)
@@ -4180,7 +4148,7 @@ Typing SPC flushes the help buffer."
          ;; If the user does mouse-choose-completion with the mouse,
          ;; execute the command, then delete the completion window.
          (progn
-           (mouse-choose-completion first)
+           (choose-completion first)
            (set-window-configuration conf))
        (if (eq first ?\s)
            (set-window-configuration conf)
@@ -4188,7 +4156,7 @@ Typing SPC flushes the help buffer."
 
 ;; I need a make-term that doesn't surround with *s -mm
 (defun term-ansi-make-term (name program &optional startfile &rest switches)
-"Make a term process NAME in a buffer, running PROGRAM.
+  "Make a term process NAME in a buffer, running PROGRAM.
 The name of the buffer is NAME.
 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
@@ -4197,8 +4165,7 @@ the process.  Any more args are arguments to PROGRAM."
     ;; If no process, or nuked process, crank up a new one and put buffer in
     ;; term mode.  Otherwise, leave buffer and existing process alone.
     (cond ((not (term-check-proc buffer))
-          (save-excursion
-            (set-buffer buffer)
+          (with-current-buffer buffer
             (term-mode)) ; Install local vars, mode, keymap, ...
           (term-exec buffer name program startfile switches)))
     buffer))
@@ -4256,7 +4223,7 @@ Return t if this is a Unix-based system, where serial ports are
 files, such as /dev/ttyS0.
 Return nil if this is Windows or DOS, where serial ports have
 special identifiers such as COM1."
-  (not (member system-type (list 'windows-nt 'cygwin 'ms-dos))))
+  (not (memq system-type '(windows-nt cygwin ms-dos))))
 
 (defvar serial-name-history
   (if (serial-port-is-file-p)
@@ -4290,7 +4257,7 @@ returns nil, which is recognized by `serial-process-configure'
 for special serial ports that cannot be configured.")
 
 (defun serial-supported-or-barf ()
-  "Signal an error if serial processes are not supported"
+  "Signal an error if serial processes are not supported."
   (unless (fboundp 'make-serial-process)
     (error "Serial processes are not supported on this system")))
 
@@ -4383,8 +4350,7 @@ use in that buffer.
                    :coding 'no-conversion
                    :noquery t))
          (buffer (process-buffer process)))
-    (save-excursion
-      (set-buffer buffer)
+    (with-current-buffer buffer
       (term-mode)
       (term-char-mode)
       (goto-char (point-max))
@@ -4453,9 +4419,7 @@ The return value may be nil for a special serial port."
 (defun serial-update-config-menu ()
   (setq serial-mode-line-config-menu (make-sparse-keymap "Configuration"))
   (let ((config (process-contact
-                 (get-buffer-process (current-buffer)) t))
-        (y)
-        (str))
+                 (get-buffer-process (current-buffer)) t)))
     (dolist (y '((:flowcontrol hw   "Hardware flowcontrol (RTS/CTS)")
                  (:flowcontrol sw   "Software flowcontrol (XON/XOFF)")
                  (:flowcontrol nil  "No flowcontrol")
@@ -4556,10 +4520,9 @@ The return value may be nil for a special serial port."
 ;; For modes that use term-mode, term-dynamic-complete-functions is the
 ;; hook to add completion functions to.  Functions on this list should return
 ;; non-nil if completion occurs (i.e., further completion should not occur).
-;; You could use term-dynamic-simple-complete to do the bulk of the
+;; You could use completion-in-region to do the bulk of the
 ;; completion job.
 \f
 (provide 'term)
 
-;; arch-tag: eee16bc8-2cd7-4147-9534-a5694752f716
 ;;; term.el ends here