diff options
author | Tino Calancha <tino.calancha@gmail.com> | 2017-08-02 00:01:45 +0900 |
---|---|---|
committer | Tino Calancha <tino.calancha@gmail.com> | 2017-08-02 00:01:45 +0900 |
commit | f74164a845eff579635da0a1267514ef9d040ad2 (patch) | |
tree | f5004f907dd54043d7188714161a4bb2f447f07e /lisp | |
parent | 21375a29ac9700810b90a34bd9825b1ca8f0c8e6 (diff) | |
download | emacs-f74164a845eff579635da0a1267514ef9d040ad2.tar.gz emacs-f74164a845eff579635da0a1267514ef9d040ad2.tar.bz2 emacs-f74164a845eff579635da0a1267514ef9d040ad2.zip |
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.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/dired.el | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index c502dd8a509..4f8f615a34b 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -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)) |