From: Jim Porter Date: Sat, 26 Mar 2022 22:12:48 +0000 (-0700) Subject: Don't use 'eshell-convert' when all we want is a number X-Git-Tag: emacs-29.0.90~1931^2~870 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=283c419f9a3d8ecf2721c24d9c593a1a5f1b12a2;p=emacs.git Don't use 'eshell-convert' when all we want is a number * lisp/eshell/em-hist.el (eshell/history): Use 'string-to-number' instead of 'eshell-convert'. * lisp/eshell/em-basic.el (eshell/umask): Simplify implementation and be more careful about parsing numeric umasks to set. --- diff --git a/lisp/eshell/em-basic.el b/lisp/eshell/em-basic.el index ba868cee59e..448b6787ee7 100644 --- a/lisp/eshell/em-basic.el +++ b/lisp/eshell/em-basic.el @@ -155,39 +155,37 @@ or `eshell-printn' for display." "umask" args '((?S "symbolic" nil symbolic-p "display umask symbolically") (?h "help" nil nil "display this usage message") + :preserve-args :usage "[-S] [mode]") - (if (or (not args) symbolic-p) - (let ((modstr - (concat "000" - (format "%o" - (logand (lognot (default-file-modes)) - 511))))) - (setq modstr (substring modstr (- (length modstr) 3))) - (when symbolic-p - (let ((mode (default-file-modes))) - (setq modstr - (format - "u=%s,g=%s,o=%s" - (concat (and (= (logand mode 64) 64) "r") - (and (= (logand mode 128) 128) "w") - (and (= (logand mode 256) 256) "x")) - (concat (and (= (logand mode 8) 8) "r") - (and (= (logand mode 16) 16) "w") - (and (= (logand mode 32) 32) "x")) - (concat (and (= (logand mode 1) 1) "r") - (and (= (logand mode 2) 2) "w") - (and (= (logand mode 4) 4) "x")))))) - (eshell-printn modstr)) - (setcar args (eshell-convert (car args))) - (if (numberp (car args)) - (set-default-file-modes - (- 511 (car (read-from-string - (concat "?\\" (number-to-string (car args))))))) - (error "Setting umask symbolically is not yet implemented")) + (cond + (symbolic-p + (let ((mode (default-file-modes))) + (eshell-printn + (format "u=%s,g=%s,o=%s" + (concat (and (= (logand mode 64) 64) "r") + (and (= (logand mode 128) 128) "w") + (and (= (logand mode 256) 256) "x")) + (concat (and (= (logand mode 8) 8) "r") + (and (= (logand mode 16) 16) "w") + (and (= (logand mode 32) 32) "x")) + (concat (and (= (logand mode 1) 1) "r") + (and (= (logand mode 2) 2) "w") + (and (= (logand mode 4) 4) "x")))))) + ((not args) + (eshell-printn (format "%03o" (logand (lognot (default-file-modes)) + #o777)))) + (t + (when (stringp (car args)) + (if (string-match "^[0-7]+$" (car args)) + (setcar args (string-to-number (car args) 8)) + (error "Setting umask symbolically is not yet implemented"))) + (set-default-file-modes (- #o777 (car args))) (eshell-print - "Warning: umask changed for all new files created by Emacs.\n")) + "Warning: umask changed for all new files created by Emacs.\n"))) nil)) +(put 'eshell/umask 'eshell-no-numeric-conversions t) + (provide 'em-basic) ;; Local Variables: diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index 16abf044899..a18127a547a 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -341,7 +341,7 @@ unless a different file is specified on the command line.") (error "No history")) (let (length file) (when (and args (string-match "^[0-9]+$" (car args))) - (setq length (min (eshell-convert (car args)) + (setq length (min (string-to-number (car args)) (ring-length eshell-history-ring)) args (cdr args))) (and length