X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/3ba6b2ee6aa77f5a05dc91e8a46ac559f352fee7..7cef3569a3d872ea5be07a529b68910bf1d8b790:/lisp/eshell/esh-util.el diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index 01699d8ed8..8218e91ddc 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el @@ -1,7 +1,6 @@ ;;; esh-util.el --- general utilities -;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, -;; 2008, 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 1999-2012 Free Software Foundation, Inc. ;; Author: John Wiegley @@ -82,7 +81,7 @@ Setting this to nil is offered as an aid to debugging only." Numeric form is tested using the regular expression `eshell-number-regexp'. -NOTE: If you find that numeric conversions are intefering with the +NOTE: If you find that numeric conversions are interfering with the specification of filenames (for example, in calling `find-file', or some other Lisp function that deals with files, not numbers), add the following in your .emacs file: @@ -139,27 +138,15 @@ function `string-to-number'." (memq system-type '(ms-dos windows-nt))) (defmacro eshell-condition-case (tag form &rest handlers) - "Like `condition-case', but only if `eshell-pass-through-errors' is nil." + "If `eshell-handle-errors' is non-nil, this is `condition-case'. +Otherwise, evaluates FORM with no error handling." + (declare (indent 2)) (if eshell-handle-errors `(condition-case ,tag ,form ,@handlers) form)) -(put 'eshell-condition-case 'lisp-indent-function 2) - -(defmacro eshell-deftest (module name label &rest forms) - (if (and (fboundp 'cl-compiling-file) (cl-compiling-file)) - nil - (let ((fsym (intern (concat "eshell-test--" (symbol-name name))))) - `(eval-when-compile - (ignore - (defun ,fsym () ,label - (eshell-run-test (quote ,module) (quote ,fsym) ,label - (quote (progn ,@forms))))))))) - -(put 'eshell-deftest 'lisp-indent-function 2) - (defun eshell-find-delimiter (open close &optional bound reverse-p backslash-p) "From point, find the CLOSE delimiter corresponding to OPEN. @@ -286,21 +273,22 @@ Prepend remote identification of `default-directory', if any." (setq text (replace-match " " t t text))) text)) -;; FIXME this is just dolist. (defmacro eshell-for (for-var for-list &rest forms) - "Iterate through a list" + "Iterate through a list." + (declare (indent 2)) `(let ((list-iter ,for-list)) (while list-iter (let ((,for-var (car list-iter))) ,@forms) (setq list-iter (cdr list-iter))))) -(put 'eshell-for 'lisp-indent-function 2) + +(make-obsolete 'eshell-for 'dolist "24.1") (defun eshell-flatten-list (args) "Flatten any lists within ARGS, so that there are no sublists." (let ((new-list (list t))) - (eshell-for a args + (dolist (a args) (if (and (listp a) (listp (cdr a))) (nconc new-list (eshell-flatten-list a)) @@ -341,20 +329,6 @@ Prepend remote identification of `default-directory', if any." "Flatten and stringify all of the ARGS into a single string." (mapconcat 'eshell-stringify (eshell-flatten-list args) " ")) -;; the next two are from GNUS, and really should be made part of Emacs -;; some day -(defsubst eshell-time-less-p (t1 t2) - "Say whether time T1 is less than time T2." - (or (< (car t1) (car t2)) - (and (= (car t1) (car t2)) - (< (nth 1 t1) (nth 1 t2))))) - -(defsubst eshell-time-to-seconds (time) - "Convert TIME to a floating point number." - (+ (* (car time) 65536.0) - (cadr time) - (/ (or (car (cdr (cdr time))) 0) 1000000.0))) - (defsubst eshell-directory-files (regexp &optional directory) "Return a list of files in the given DIRECTORY matching REGEXP." (directory-files (or directory default-directory) @@ -420,7 +394,7 @@ list." (unless (listp entries) (setq entries (list entries) listified t)) - (eshell-for entry entries + (dolist (entry entries) (unless (and exclude (string-match exclude entry)) (setq p predicates valid (null p)) (while p @@ -468,7 +442,7 @@ list." "Read the contents of /etc/passwd for user names." (if (or (not (symbol-value result-var)) (not (symbol-value timestamp-var)) - (eshell-time-less-p + (time-less-p (symbol-value timestamp-var) (nth 5 (file-attributes file)))) (progn @@ -509,7 +483,7 @@ list." (insert-file-contents eshell-hosts-file) (goto-char (point-min)) (while (re-search-forward - "^\\(\\S-+\\)\\s-+\\(\\S-+\\)\\(\\s-*\\(\\S-+\\)\\)?" nil t) + "^\\([^#[:space:]]+\\)\\s-+\\(\\S-+\\)\\(\\s-*\\(\\S-+\\)\\)?" nil t) (if (match-string 1) (add-to-list 'hosts (match-string 1))) (if (match-string 2) @@ -522,7 +496,7 @@ list." "Read the contents of /etc/passwd for user names." (if (or (not (symbol-value result-var)) (not (symbol-value timestamp-var)) - (eshell-time-less-p + (time-less-p (symbol-value timestamp-var) (nth 5 (file-attributes file)))) (progn @@ -536,17 +510,18 @@ list." (eshell-read-hosts eshell-hosts-file 'eshell-host-names 'eshell-host-timestamp))) -(unless (fboundp 'subst-char-in-string) - (defun subst-char-in-string (fromchar tochar string &optional inplace) - "Replace FROMCHAR with TOCHAR in STRING each time it occurs. +(and (featurep 'xemacs) + (not (fboundp 'subst-char-in-string)) + (defun subst-char-in-string (fromchar tochar string &optional inplace) + "Replace FROMCHAR with TOCHAR in STRING each time it occurs. Unless optional argument INPLACE is non-nil, return a new string." - (let ((i (length string)) - (newstr (if inplace string (copy-sequence string)))) - (while (> i 0) - (setq i (1- i)) - (if (eq (aref newstr i) fromchar) - (aset newstr i tochar))) - newstr))) + (let ((i (length string)) + (newstr (if inplace string (copy-sequence string)))) + (while (> i 0) + (setq i (1- i)) + (if (eq (aref newstr i) fromchar) + (aset newstr i tochar))) + newstr))) (defsubst eshell-copy-environment () "Return an unrelated copy of `process-environment'." @@ -586,8 +561,9 @@ Unless optional argument INPLACE is non-nil, return a new string." (substring string 0 sublen) string))) -(unless (fboundp 'directory-files-and-attributes) - (defun directory-files-and-attributes (directory &optional full match nosort id-format) +(and (featurep 'xemacs) + (not (fboundp 'directory-files-and-attributes)) + (defun directory-files-and-attributes (directory &optional full match nosort id-format) "Return a list of names of files and their attributes in DIRECTORY. There are three optional arguments: If FULL is non-nil, return absolute file names. Otherwise return names @@ -599,7 +575,7 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable. (mapcar (function (lambda (file) - (cons file (eshell-file-attributes (expand-file-name file directory))))) + (cons file (eshell-file-attributes (expand-file-name file directory))))) (directory-files directory full match nosort))))) (defvar ange-cache)