]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/em-term.el
Merge from origin/emacs-24
[gnu-emacs] / lisp / eshell / em-term.el
index 7875fbc9c8055801c0474c25d8a919bed7a08da8..4a6ac23544951c2f4f4a173846b5459097660522 100644 (file)
@@ -1,6 +1,6 @@
-;;; em-term.el --- running visual commands
+;;; em-term.el --- running visual commands  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -31,6 +31,7 @@
 
 ;;; Code:
 
+(require 'cl-lib)
 (require 'esh-util)
 (require 'esh-ext)
 (eval-when-compile (require 'eshell))
@@ -61,13 +62,19 @@ which commands are considered visual in nature."
     "less" "more"                       ; M-x view-file
     "lynx" "ncftp"                      ; w3.el, ange-ftp
     "pine" "tin" "trn" "elm")           ; GNUS!!
-  "A list of commands that present their output in a visual fashion."
+  "A list of commands that present their output in a visual fashion.
+
+Commands listed here are run in a term buffer.
+
+See also `eshell-visual-subcommands' and `eshell-visual-options'."
   :type '(repeat string)
   :group 'eshell-term)
 
 (defcustom eshell-visual-subcommands
   nil
-  "An alist of the form
+  "An alist of subcommands that present their output in a visual fashion.
+
+An alist of the form
 
   ((COMMAND1 SUBCOMMAND1 SUBCOMMAND2...)
    (COMMAND2 SUBCOMMAND1 ...))
@@ -77,9 +84,13 @@ visual fashion.  A likely entry is
 
   (\"git\" \"log\" \"diff\" \"show\")
 
-because git shows logs and diffs using a pager by default."
+because git shows logs and diffs using a pager by default.
+
+See also `eshell-visual-commands' and `eshell-visual-options'."
   :type '(repeat (cons (string :tag "Command")
-                      (repeat (string :tag "Subcommand")))))
+                      (repeat (string :tag "Subcommand"))))
+  :version "24.4"
+  :group 'eshell-term)
 
 (defcustom eshell-visual-options
   nil
@@ -94,9 +105,13 @@ fashion.  For example, a sensible entry would be
   (\"git\" \"--help\")
 
 because \"git <command> --help\" shows the command's
-documentation with a pager."
+documentation with a pager.
+
+See also `eshell-visual-commands' and `eshell-visual-subcommands'."
   :type '(repeat (cons (string :tag "Command")
-                      (repeat (string :tag "Option")))))
+                      (repeat (string :tag "Option"))))
+  :version "24.4"
+  :group 'eshell-term)
 
 ;; If you change this from term-term-name, you need to ensure that the
 ;; value you choose exists in the system's terminfo database.  (Bug#12485)
@@ -127,18 +142,23 @@ character to the invoked process."
   "Initialize the `term' interface code."
   (make-local-variable 'eshell-interpreter-alist)
   (setq eshell-interpreter-alist
-       (cons (cons (function
-                    (lambda (command args)
-                      (let ((command (file-name-nondirectory command)))
-                        (or (member command eshell-visual-commands)
-                            (member (car args)
-                                    (cdr (assoc command eshell-visual-subcommands)))
-                            (intersection args
-                                          (cdr (assoc command eshell-visual-options))
-                                          :test 'string=)))))
+       (cons (cons #'eshell-visual-command-p
                    'eshell-exec-visual)
              eshell-interpreter-alist)))
 
+(defun eshell-visual-command-p (command args)
+  "Returns non-nil when given a visual command.
+If either COMMAND or a subcommand in ARGS (e.g. git log) is a
+visual command, returns non-nil."
+  (let ((command (file-name-nondirectory command)))
+    (and (eshell-interactive-output-p)
+         (or (member command eshell-visual-commands)
+             (member (car args)
+                     (cdr (assoc command eshell-visual-subcommands)))
+             (cl-intersection args
+                              (cdr (assoc command eshell-visual-options))
+                              :test 'string=)))))
+
 (defun eshell-exec-visual (&rest args)
   "Run the specified PROGRAM in a terminal emulation buffer.
 ARGS are passed to the program.  At the moment, no piping of input is
@@ -169,7 +189,8 @@ allowed."
          (term-set-escape-char ?\C-x))))
   nil)
 
-(defun eshell-term-sentinel (proc string)
+;; Process sentinels receive two arguments.
+(defun eshell-term-sentinel (proc _string)
   "Destroy the buffer visiting PROC."
   (let ((proc-buf (process-buffer proc)))
     (when (and proc-buf (buffer-live-p proc-buf)