From 7820b28f318a34ba4bf9e6adb316a6ba31f14e77 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Wed, 29 Apr 1998 05:06:46 +0000 Subject: [PATCH] (dired-sort-toggle): Handle spaces in dired-actual-switches. --- lisp/dired.el | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lisp/dired.el b/lisp/dired.el index c8f6c6de60e..d6168e5f290 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2389,16 +2389,22 @@ With a prefix argument you can edit the current listing switches instead." ;; Toggle between sort by date/name. Reverts the buffer. (setq dired-actual-switches (let (case-fold-search) - (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")))) + (if (string-match " " dired-actual-switches) + ;; New toggle scheme: add/remove a trailing " -t" + (if (string-match " -t\\'" dired-actual-switches) + (dired-replace-in-string " -t\\'" "" dired-actual-switches) + (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"))))) (dired-sort-set-modeline) (revert-buffer)) -- 2.39.2