aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2010-09-05 17:28:50 -0400
committerChong Yidong2010-09-05 17:28:50 -0400
commit8d76af4ad04f4dd45cb89acef46091c68b7548da (patch)
treef98afd8194376d9d6ac441607570520734c252e4
parent93a596e11b4b10e99636fce9eae2bcdf45e20c17 (diff)
downloademacs-8d76af4ad04f4dd45cb89acef46091c68b7548da.tar.gz
emacs-8d76af4ad04f4dd45cb89acef46091c68b7548da.zip
Improve ls date switch parsing in Dired (Bug#6987).
* dired.el (dired-ls-sorting-switches, dired-sort-by-name-regexp): Improve regexps (Bug#6987). (dired-sort-toggle): Search more robustly for -t flag.
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/dired.el50
2 files changed, 31 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 026b05a7231..81061db8759 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12010-09-05 Chong Yidong <cyd@stupidchicken.com> 12010-09-05 Chong Yidong <cyd@stupidchicken.com>
2 2
3 * dired.el (dired-ls-sorting-switches, dired-sort-by-name-regexp):
4 Improve regexps (Bug#6987).
5 (dired-sort-toggle): Search more robustly for -t flag.
6
3 * files.el (get-free-disk-space): Search more robustly for 7 * files.el (get-free-disk-space): Search more robustly for
4 "available" column. Suggested by Ehud Karni 8 "available" column. Suggested by Ehud Karni
5 <ehud@unix.mvs.co.il>. 9 <ehud@unix.mvs.co.il>.
diff --git a/lisp/dired.el b/lisp/dired.el
index ecc3b5bd47e..3fdb82ca7d3 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3249,12 +3249,16 @@ variable `dired-listing-switches'. To temporarily override the listing
3249format, use `\\[universal-argument] \\[dired]'.") 3249format, use `\\[universal-argument] \\[dired]'.")
3250 3250
3251(defvar dired-sort-by-date-regexp 3251(defvar dired-sort-by-date-regexp
3252 (concat "^-[^" dired-ls-sorting-switches 3252 (concat "\\(\\`\\| \\)-[^- ]*t"
3253 "]*t[^" dired-ls-sorting-switches "]*$") 3253 ;; `dired-ls-sorting-switches' after -t overrides -t.
3254 "[^ " dired-ls-sorting-switches "]*"
3255 "\\(\\(\\`\\| +\\)\\(--[^ ]+\\|-[^- t"
3256 dired-ls-sorting-switches "]+\\)\\)* *$")
3254 "Regexp recognized by Dired to set `by date' mode.") 3257 "Regexp recognized by Dired to set `by date' mode.")
3255 3258
3256(defvar dired-sort-by-name-regexp 3259(defvar dired-sort-by-name-regexp
3257 (concat "^-[^t" dired-ls-sorting-switches "]+$") 3260 (concat "\\`\\(\\(\\`\\| +\\)\\(--[^ ]+\\|"
3261 "-[^- t" dired-ls-sorting-switches "]+\\)\\)* *$")
3258 "Regexp recognized by Dired to set `by name' mode.") 3262 "Regexp recognized by Dired to set `by name' mode.")
3259 3263
3260(defvar dired-sort-inhibit nil 3264(defvar dired-sort-inhibit nil
@@ -3280,8 +3284,8 @@ The idea is to set this buffer-locally in special dired buffers.")
3280 (force-mode-line-update))) 3284 (force-mode-line-update)))
3281 3285
3282(defun dired-sort-toggle-or-edit (&optional arg) 3286(defun dired-sort-toggle-or-edit (&optional arg)
3283 "Toggle between sort by date/name and refresh the dired buffer. 3287 "Toggle sorting by date, and refresh the Dired buffer.
3284With a prefix argument you can edit the current listing switches instead." 3288With a prefix argument, edit the current listing switches instead."
3285 (interactive "P") 3289 (interactive "P")
3286 (when dired-sort-inhibit 3290 (when dired-sort-inhibit
3287 (error "Cannot sort this dired buffer")) 3291 (error "Cannot sort this dired buffer"))
@@ -3292,24 +3296,24 @@ With a prefix argument you can edit the current listing switches instead."
3292 3296
3293(defun dired-sort-toggle () 3297(defun dired-sort-toggle ()
3294 ;; Toggle between sort by date/name. Reverts the buffer. 3298 ;; Toggle between sort by date/name. Reverts the buffer.
3295 (setq dired-actual-switches 3299 (let ((sorting-by-date (string-match dired-sort-by-date-regexp
3296 (let (case-fold-search) 3300 dired-actual-switches))
3297 (if (string-match " " dired-actual-switches) 3301 ;; Regexp for finding (possibly embedded) -t switches.
3298 ;; New toggle scheme: add/remove a trailing " -t" 3302 (switch-regexp "\\(\\`\\| \\)-\\([a-su-zA-Z]*\\)\\(t\\)\\([^ ]*\\)")
3299 (if (string-match " -t\\'" dired-actual-switches) 3303 case-fold-search)
3300 (substring dired-actual-switches 0 (match-beginning 0)) 3304 ;; Remove the -t switch.
3301 (concat dired-actual-switches " -t")) 3305 (while (string-match switch-regexp dired-actual-switches)
3302 ;; old toggle scheme: look for some 't' switch and add/remove it 3306 (if (and (equal (match-string 2 dired-actual-switches) "")
3303 (concat 3307 (equal (match-string 4 dired-actual-switches) ""))
3304 "-l" 3308 ;; Remove a stand-alone -t switch.
3305 (dired-replace-in-string (concat "[-lt" 3309 (setq dired-actual-switches
3306 dired-ls-sorting-switches "]") 3310 (replace-match "" t t dired-actual-switches))
3307 "" 3311 ;; Remove a switch of the form -XtY for some X and Y.
3308 dired-actual-switches) 3312 (setq dired-actual-switches
3309 (if (string-match (concat "[t" dired-ls-sorting-switches "]") 3313 (replace-match "" t t dired-actual-switches 3))))
3310 dired-actual-switches) 3314 ;; Now, if we weren't sorting by date before, add the -t switch.
3311 "" 3315 (unless sorting-by-date
3312 "t"))))) 3316 (setq dired-actual-switches (concat dired-actual-switches " -t"))))
3313 (dired-sort-set-modeline) 3317 (dired-sort-set-modeline)
3314 (revert-buffer)) 3318 (revert-buffer))
3315 3319