Merge from emacs--rel--22
[bpt/emacs.git] / lisp / eshell / em-unix.el
index 62296dd..e970c87 100644 (file)
@@ -1,6 +1,7 @@
 ;;; em-unix.el --- UNIX command aliases
 
-;; Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -8,7 +9,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
-(provide 'em-unix)
+;;; Commentary:
+
+;; This file contains implementations of several UNIX command in Emacs
+;; Lisp, for several reasons:
+;;
+;;   1) it makes them available on all platforms where the Lisp
+;;      functions used are available
+;;
+;;   2) it makes their functionality accessible and modified by the
+;;      Lisp programmer.
+;;
+;;   3) it allows Eshell to refrain from having to invoke external
+;;      processes for common operations.
+
+;;; Code:
 
-(eval-when-compile (require 'esh-maint))
 (require 'eshell)
 
 (defgroup eshell-unix nil
@@ -39,20 +53,6 @@ by name)."
   :tag "UNIX commands in Lisp"
   :group 'eshell-module)
 
-;;; Commentary:
-
-;; This file contains implementations of several UNIX command in Emacs
-;; Lisp, for several reasons:
-;;
-;;   1) it makes them available on all platforms where the Lisp
-;;      functions used are available
-;;
-;;   2) it makes their functionality accessible and modified by the
-;;      Lisp programmer.
-;;
-;;   3) it allows Eshell to refrain from having to invoke external
-;;      processes for common operations.
-
 (defcustom eshell-unix-load-hook '(eshell-unix-initialize)
   "*A list of functions to run when `eshell-unix' is loaded."
   :type 'hook
@@ -77,7 +77,7 @@ receiving side of a command pipeline."
   :type 'boolean
   :group 'eshell-unix)
 
-(defcustom eshell-plain-locate-behavior (eshell-under-xemacs-p)
+(defcustom eshell-plain-locate-behavior (featurep 'xemacs)
   "*If non-nil, standalone \"locate\" commands will behave normally.
 Standalone in this context means not redirected, and not on the
 receiving side of a command pipeline."
@@ -136,8 +136,6 @@ Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine."
   :type 'boolean
   :group 'eshell-unix)
 
-(require 'esh-opt)
-
 ;;; Functions:
 
 (defun eshell-unix-initialize ()
@@ -167,6 +165,35 @@ Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine."
 
 (put 'eshell/man 'eshell-no-numeric-conversions t)
 
+(defun eshell/info (&rest args)
+  "Run the info command in-frame with the same behavior as command-line `info', ie:
+  'info'           => goes to top info window
+  'info arg1'      => IF arg1 is a file, then visits arg1
+  'info arg1'      => OTHERWISE goes to top info window and then menu item arg1
+  'info arg1 arg2' => does action for arg1 (either visit-file or menu-item) and then menu item arg2
+  etc."
+  (eval-and-compile (require 'info))
+  (let ((file (cond
+                ((not (stringp (car args)))
+                 nil)
+                ((file-exists-p (expand-file-name (car args)))
+                 (expand-file-name (car args)))
+                ((file-exists-p (concat (expand-file-name (car args)) ".info"))
+                 (concat (expand-file-name (car args)) ".info")))))
+
+    ;; If the first arg is a file, then go to that file's Top node
+    ;; Otherwise, go to the global directory
+    (if file
+      (progn
+        (setq args (cdr args))
+        (Info-find-node file "Top"))
+      (Info-directory))
+
+    ;; Treat all remaining args as menu references
+    (while args
+      (Info-menu (car args))
+      (setq args (cdr args)))))
+
 (defun eshell-remove-entries (path files &optional top-level)
   "From PATH, remove all of the given FILES, perhaps interactively."
   (while files
@@ -929,7 +956,10 @@ Show wall-clock time elapsed during execution of COMMAND.")
      (add-hook 'eshell-post-command-hook 'eshell-show-elapsed-time nil t)
      ;; after setting
      (throw 'eshell-replace-command
-           (eshell-parse-command (car time-args) (cdr time-args))))))
+           (eshell-parse-command (car time-args)
+;;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-08/msg00205.html
+                                 (eshell-stringify-list
+                                  (eshell-flatten-list (cdr time-args))))))))
 
 (defalias 'eshell/whoami 'user-login-name)
 
@@ -941,6 +971,12 @@ Show wall-clock time elapsed during execution of COMMAND.")
   (if eshell-diff-window-config
       (set-window-configuration eshell-diff-window-config)))
 
+(defun nil-blank-string (string)
+  "Return STRING, or nil if STRING contains only non-blank characters."
+  (cond
+    ((string-match "[^[:blank:]]" string) string)
+    (nil)))
+
 (defun eshell/diff (&rest args)
   "Alias \"diff\" to call Emacs `diff' function."
   (let ((orig-args (eshell-stringify-list (eshell-flatten-list args))))
@@ -962,7 +998,8 @@ Show wall-clock time elapsed during execution of COMMAND.")
          (setcdr (last args 3) nil))
        (with-current-buffer
            (condition-case err
-               (diff old new (eshell-flatten-and-stringify args))
+               (diff old new
+                     (nil-blank-string (eshell-flatten-and-stringify args)))
              (error
               (throw 'eshell-replace-command
                      (eshell-parse-command "*diff" orig-args))))
@@ -1010,7 +1047,7 @@ Show wall-clock time elapsed during execution of COMMAND.")
 
 (put 'eshell/occur 'eshell-no-numeric-conversions t)
 
-;;; Code:
+(provide 'em-unix)
 
 ;;; arch-tag: 2462edd2-a76a-4cf2-897d-92e9a82ac1c9
 ;;; em-unix.el ends here