emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 283c419f9a 2/2: Don't use 'eshell-convert' when all we want is a


From: Lars Ingebrigtsen
Subject: master 283c419f9a 2/2: Don't use 'eshell-convert' when all we want is a number
Date: Tue, 29 Mar 2022 10:52:00 -0400 (EDT)

branch: master
commit 283c419f9a3d8ecf2721c24d9c593a1a5f1b12a2
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 lisp/eshell/em-basic.el | 56 ++++++++++++++++++++++++-------------------------
 lisp/eshell/em-hist.el  |  2 +-
 2 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/lisp/eshell/em-basic.el b/lisp/eshell/em-basic.el
index ba868cee59..448b6787ee 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 16abf04489..a18127a547 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]