Commit f74164a8 authored by Tino Calancha's avatar Tino Calancha
Browse files

Fix misalignment in Dired when dired-directory is a cons

* lisp/dired.el (dired--need-align-p, dired--align-all-files):
New defuns.
(dired-internal-noselect): Call dired--align-all-files when
dired-directory is a cons (Bug#27762).
* test/lisp/dired-tests.el (dired-test-bug27762): Test should pass.
parent 21375a29
......@@ -34,6 +34,7 @@
;;; Code:
(eval-when-compile (require 'subr-x))
;; When bootstrapping dired-loaddefs has not been generated.
(require 'dired-loaddefs nil t)
......@@ -871,6 +872,46 @@ periodically reverts at specified time intervals."
:group 'dired
:version "23.2")
(defun dired--need-align-p ()
"Return non-nil if some file names are misaligned.
The return value is the target column for the file names."
(save-excursion
(goto-char (point-min))
(dired-goto-next-file)
;; Use point difference instead of `current-column', because
;; the former works when `dired-hide-details-mode' is enabled.
(let* ((first (- (point) (point-at-bol)))
(target first))
(while (and (not (eobp))
(progn
(forward-line)
(dired-move-to-filename)))
(when-let* ((distance (- (point) (point-at-bol)))
(higher (> distance target)))
(setq target distance)))
(and (/= first target) target))))
(defun dired--align-all-files ()
"Align all files adding spaces in front of the size column."
(let ((target (dired--need-align-p))
(regexp directory-listing-before-filename-regexp))
(when target
(save-excursion
(goto-char (point-min))
(dired-goto-next-file)
(while (dired-move-to-filename)
;; Use point difference instead of `current-column', because
;; the former works when `dired-hide-details-mode' is enabled.
(let ((distance (- target (- (point) (point-at-bol))))
(inhibit-read-only t))
(unless (zerop distance)
(re-search-backward regexp nil t)
(goto-char (match-beginning 0))
(search-backward-regexp "[[:space:]]" nil t)
(skip-chars-forward "[:space:]")
(insert-char ?\s distance 'inherit))
(forward-line)))))))
(defun dired-internal-noselect (dir-or-list &optional switches mode)
;; If DIR-OR-LIST is a string and there is an existing dired buffer
;; for it, just leave buffer as it is (don't even call dired-revert).
......@@ -940,6 +981,8 @@ periodically reverts at specified time intervals."
(if failed (kill-buffer buffer))))
(goto-char (point-min))
(dired-initial-position dirname))
(when (consp dired-directory)
(dired--align-all-files))
(set-buffer old-buf)
buffer))
......
......@@ -260,7 +260,6 @@
(ert-deftest dired-test-bug27762 ()
"Test for http://debbugs.gnu.org/27762 ."
:expected-result :failed
(require 'ls-lisp)
(let* ((dir source-directory)
(default-directory dir)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment