[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r101356: Improve ls date switch parsi
From: |
Chong Yidong |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r101356: Improve ls date switch parsing in Dired (Bug#6987). |
Date: |
Sun, 05 Sep 2010 17:28:50 -0400 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 101356
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sun 2010-09-05 17:28:50 -0400
message:
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.
modified:
lisp/ChangeLog
lisp/dired.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2010-09-05 19:03:20 +0000
+++ b/lisp/ChangeLog 2010-09-05 21:28:50 +0000
@@ -1,5 +1,9 @@
2010-09-05 Chong Yidong <address@hidden>
+ * dired.el (dired-ls-sorting-switches, dired-sort-by-name-regexp):
+ Improve regexps (Bug#6987).
+ (dired-sort-toggle): Search more robustly for -t flag.
+
* files.el (get-free-disk-space): Search more robustly for
"available" column. Suggested by Ehud Karni
<address@hidden>.
=== modified file 'lisp/dired.el'
--- a/lisp/dired.el 2010-08-29 16:17:13 +0000
+++ b/lisp/dired.el 2010-09-05 21:28:50 +0000
@@ -3249,12 +3249,16 @@
format, use `\\[universal-argument] \\[dired]'.")
(defvar dired-sort-by-date-regexp
- (concat "^-[^" dired-ls-sorting-switches
- "]*t[^" dired-ls-sorting-switches "]*$")
+ (concat "\\(\\`\\| \\)-[^- ]*t"
+ ;; `dired-ls-sorting-switches' after -t overrides -t.
+ "[^ " dired-ls-sorting-switches "]*"
+ "\\(\\(\\`\\| +\\)\\(--[^ ]+\\|-[^- t"
+ dired-ls-sorting-switches "]+\\)\\)* *$")
"Regexp recognized by Dired to set `by date' mode.")
(defvar dired-sort-by-name-regexp
- (concat "^-[^t" dired-ls-sorting-switches "]+$")
+ (concat "\\`\\(\\(\\`\\| +\\)\\(--[^ ]+\\|"
+ "-[^- t" dired-ls-sorting-switches "]+\\)\\)* *$")
"Regexp recognized by Dired to set `by name' mode.")
(defvar dired-sort-inhibit nil
@@ -3280,8 +3284,8 @@
(force-mode-line-update)))
(defun dired-sort-toggle-or-edit (&optional arg)
- "Toggle between sort by date/name and refresh the dired buffer.
-With a prefix argument you can edit the current listing switches instead."
+ "Toggle sorting by date, and refresh the Dired buffer.
+With a prefix argument, edit the current listing switches instead."
(interactive "P")
(when dired-sort-inhibit
(error "Cannot sort this dired buffer"))
@@ -3292,24 +3296,24 @@
(defun dired-sort-toggle ()
;; Toggle between sort by date/name. Reverts the buffer.
- (setq dired-actual-switches
- (let (case-fold-search)
- (if (string-match " " dired-actual-switches)
- ;; New toggle scheme: add/remove a trailing " -t"
- (if (string-match " -t\\'" dired-actual-switches)
- (substring dired-actual-switches 0 (match-beginning 0))
- (concat dired-actual-switches " -t"))
- ;; old toggle scheme: look for some 't' switch and add/remove it
- (concat
- "-l"
- (dired-replace-in-string (concat "[-lt"
- dired-ls-sorting-switches "]")
- ""
- dired-actual-switches)
- (if (string-match (concat "[t" dired-ls-sorting-switches "]")
- dired-actual-switches)
- ""
- "t")))))
+ (let ((sorting-by-date (string-match dired-sort-by-date-regexp
+ dired-actual-switches))
+ ;; Regexp for finding (possibly embedded) -t switches.
+ (switch-regexp "\\(\\`\\| \\)-\\([a-su-zA-Z]*\\)\\(t\\)\\([^ ]*\\)")
+ case-fold-search)
+ ;; Remove the -t switch.
+ (while (string-match switch-regexp dired-actual-switches)
+ (if (and (equal (match-string 2 dired-actual-switches) "")
+ (equal (match-string 4 dired-actual-switches) ""))
+ ;; Remove a stand-alone -t switch.
+ (setq dired-actual-switches
+ (replace-match "" t t dired-actual-switches))
+ ;; Remove a switch of the form -XtY for some X and Y.
+ (setq dired-actual-switches
+ (replace-match "" t t dired-actual-switches 3))))
+ ;; Now, if we weren't sorting by date before, add the -t switch.
+ (unless sorting-by-date
+ (setq dired-actual-switches (concat dired-actual-switches " -t"))))
(dired-sort-set-modeline)
(revert-buffer))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r101356: Improve ls date switch parsing in Dired (Bug#6987).,
Chong Yidong <=