summaryrefslogtreecommitdiff
path: root/lisp/dired-x.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-12-03 17:01:30 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-12-03 17:22:59 +0100
commit52b2ffd83b95c2bd974f23f71860a5ea123e3b02 (patch)
treeac33efff5bb0ead939c35934408d1261a32309da /lisp/dired-x.el
parent20124d78e7b5a063a37eeecce06f4d42f0cf08ed (diff)
downloademacs-52b2ffd83b95c2bd974f23f71860a5ea123e3b02.tar.gz
Improve how dired-mark-sexp interprets file sizes in non-C locales
* lisp/dired-x.el (dired-x--string-to-number): Try to understand localised numbers (with "." separators or the like) (bug#23373).
Diffstat (limited to 'lisp/dired-x.el')
-rw-r--r--lisp/dired-x.el22
1 files changed, 15 insertions, 7 deletions
diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index 855e58e16c1..38d8a954a83 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -1265,13 +1265,21 @@ sure that a trailing letter in STR is one of BKkMGTPEZY."
(let* ((val (string-to-number str))
(u (unless (zerop val)
(aref str (1- (length str))))))
- (when (and u (> u ?9))
- (when (= u ?k)
- (setq u ?K))
- (let ((units '(?B ?K ?M ?G ?T ?P ?E ?Z ?Y)))
- (while (and units (/= (pop units) u))
- (setq val (* 1024.0 val)))))
- val))
+ ;; If we don't have a unit at the end, but we have some
+ ;; non-numeric strings in the string, then the string may be
+ ;; something like "4.134" or "4,134" meant to represent 4134
+ ;; (seen in some locales).
+ (if (and u
+ (<= ?0 u ?9)
+ (string-match-p "[^0-9]" str))
+ (string-to-number (replace-regexp-in-string "[^0-9]+" "" str))
+ (when (and u (> u ?9))
+ (when (= u ?k)
+ (setq u ?K))
+ (let ((units '(?B ?K ?M ?G ?T ?P ?E ?Z ?Y)))
+ (while (and units (/= (pop units) u))
+ (setq val (* 1024.0 val)))))
+ val)))
(defun dired-mark-sexp (predicate &optional unflag-p)
"Mark files for which PREDICATE returns non-nil.