* lisp/eshell/em-hist.el (eshell-isearch-map): Initialize in the defvar.
[bpt/emacs.git] / lisp / eshell / em-hist.el
index 993e9d6..694fe71 100644 (file)
@@ -1,6 +1,6 @@
 ;;; em-hist.el --- history list management
 
-;; Copyright (C) 1999-201 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -54,8 +54,7 @@
 
 ;;; Code:
 
-(eval-when-compile
-  (require 'cl))
+(eval-when-compile (require 'cl-lib))
 
 (require 'ring)
 (require 'esh-opt)
 (require 'eshell)
 
 ;;;###autoload
-(eshell-defgroup eshell-hist nil
+(progn
+(defgroup eshell-hist nil
   "This module provides command history management."
   :tag "History list management"
-  :group 'eshell-module)
+  :group 'eshell-module))
 
 ;;; User Variables:
 
   "If non-nil, name of the file to read/write input history.
 See also `eshell-read-history' and `eshell-write-history'.
 If it is nil, Eshell will use the value of HISTFILE."
-  :type 'file
+  :type '(choice (const :tag "Use HISTFILE" nil)
+                file)
   :group 'eshell-hist)
 
 (defcustom eshell-history-size 128
   "Size of the input history ring.  If nil, use envvar HISTSIZE."
-  :type 'integer
+  :type '(choice (const :tag "Use HISTSIZE" nil)
+                integer)
   :group 'eshell-hist)
 
 (defcustom eshell-hist-ignoredups nil
@@ -187,21 +189,18 @@ element, regardless of any text on the command line.  In that case,
 (defvar eshell-matching-input-from-input-string "")
 (defvar eshell-save-history-index nil)
 
-(defvar eshell-isearch-map nil)
-
-(unless eshell-isearch-map
-  (setq eshell-isearch-map (copy-keymap isearch-mode-map))
-  (define-key eshell-isearch-map [(control ?m)] 'eshell-isearch-return)
-  (define-key eshell-isearch-map [return] 'eshell-isearch-return)
-  (define-key eshell-isearch-map [(control ?r)] 'eshell-isearch-repeat-backward)
-  (define-key eshell-isearch-map [(control ?s)] 'eshell-isearch-repeat-forward)
-  (define-key eshell-isearch-map [(control ?g)] 'eshell-isearch-abort)
-  (define-key eshell-isearch-map [backspace] 'eshell-isearch-delete-char)
-  (define-key eshell-isearch-map [delete] 'eshell-isearch-delete-char)
-  (defvar eshell-isearch-cancel-map)
-  (define-prefix-command 'eshell-isearch-cancel-map)
-  (define-key eshell-isearch-map [(control ?c)] 'eshell-isearch-cancel-map)
-  (define-key eshell-isearch-cancel-map [(control ?c)] 'eshell-isearch-cancel))
+(defvar eshell-isearch-map
+  (let ((map (copy-keymap isearch-mode-map)))
+    (define-key map [(control ?m)] 'eshell-isearch-return)
+    (define-key map [return] 'eshell-isearch-return)
+    (define-key map [(control ?r)] 'eshell-isearch-repeat-backward)
+    (define-key map [(control ?s)] 'eshell-isearch-repeat-forward)
+    (define-key map [(control ?g)] 'eshell-isearch-abort)
+    (define-key map [backspace] 'eshell-isearch-delete-char)
+    (define-key map [delete] 'eshell-isearch-delete-char)
+    (define-key map "\C-c\C-c" 'eshell-isearch-cancel)
+    map)
+  "Keymap used in isearch in Eshell.")
 
 (defvar eshell-rebind-keys-alist)
 
@@ -261,7 +260,13 @@ element, regardless of any text on the command line.  In that case,
 
   (make-local-variable 'eshell-history-size)
   (or eshell-history-size
-      (setq eshell-history-size (getenv "HISTSIZE")))
+      (let ((hsize (getenv "HISTSIZE")))
+        (setq eshell-history-size
+             (if (and (stringp hsize)
+                      (integerp (setq hsize (string-to-number hsize)))
+                      (> hsize 0))
+                 hsize
+               128))))
 
   (make-local-variable 'eshell-history-file-name)
   (or eshell-history-file-name
@@ -551,8 +556,8 @@ See also `eshell-read-history'."
          (forward-char))
        (setq posb (cdr posb)
              pose (cdr pose))
-       (assert (= (length posb) (length args)))
-       (assert (<= (length posb) (length pose))))
+       (cl-assert (= (length posb) (length args)))
+       (cl-assert (<= (length posb) (length pose))))
       (setq hist (buffer-substring-no-properties begin end))
       (let ((b posb) (e pose))
        (while b
@@ -562,7 +567,7 @@ See also `eshell-read-history'."
          (setq b (cdr b)
                e (cdr e))))
       (setq textargs (cdr textargs))
-      (assert (= (length textargs) (length args)))
+      (cl-assert (= (length textargs) (length args)))
       (list textargs posb pose))))
 
 (defun eshell-expand-history-references (beg end)
@@ -609,7 +614,7 @@ See also `eshell-read-history'."
                                           history))))
                 (setq index (1- index)))
               (let ((fhist (list t)))
-                ;; uniqify the list, but preserve the order
+                ;; uniquify the list, but preserve the order
                 (while history
                   (unless (member (car history) fhist)
                     (nconc fhist (list (car history))))