From: Tino Calancha <tino.calancha@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 27762@debbugs.gnu.org
Subject: bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons
Date: Fri, 21 Jul 2017 13:55:26 +0900 [thread overview]
Message-ID: <87d18uz8w1.fsf@calancha-pc> (raw)
In-Reply-To: <87lgnjzs8d.fsf@calancha-pc> (Tino Calancha's message of "Thu, 20 Jul 2017 12:45:22 +0900")
> With emacs -Q:
>
> (let* ((dir (expand-file-name "src" source-directory))
> (default-directory dir))
> (dired (list dir "cygw32.c" "alloc.c" "w32xfns.c" "xdisp.c")) ; Wrong aligment.
> ;; Following just fix the first file, but xdisp.c keeps misaligned.
> (dired-goto-file (expand-file-name "cygw32.c"))
> (forward-line 0)
> (let ((inhibit-read-only t))
> (dired-align-file (point) (point-max))))
>
>
> Note that when i eval the previous form GNU 'ls' is used, and i see misalignment.
> I would expect `dired-align-file' fix this problem, but i doesn't.
>
> *) Since this is not specific of `ls-lisp', one alternative fix could
> be to run `dired-align-file' at the end of `dired-internal-noselect'
> when `dired-directory' is a cons.
>
> **) First, we must fix `dired-lign-file', which is not doing its job
> in the snippet above.
Eli, how do you think about following patch?
--8<-----------------------------cut here---------------start------------->8---
commit 458fe93358594cf7338180b6feb54eb37d28ed21
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Fri Jul 21 13:50:56 2017 +0900
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.
diff --git a/lisp/dired.el b/lisp/dired.el
index 9d500a9f52..371af15f79 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 @@ dired-auto-revert-buffer
: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* ((col-diff (- (point) (point-at-bol)))
+ (higher (> col-diff target)))
+ (setq target col-diff)))
+ (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)
+ (let ((col-diff (- target (- (point) (point-at-bol))))
+ (inhibit-read-only t)
+ props)
+ (unless (zerop col-diff)
+ (re-search-backward regexp nil t)
+ (goto-char (match-beginning 0))
+ (search-backward-regexp "[[:space:]]" nil t)
+ (setq props (text-properties-at (1- (point))))
+ (skip-chars-forward "[:space:]")
+ (insert (apply #'propertize (make-string col-diff ?\s) props)))
+ (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).
@@ -939,6 +980,8 @@ dired-internal-noselect
(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))
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index bd1816172e..d5f999aab6 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -147,7 +147,6 @@
(ert-deftest dired-test-bug27762 ()
"Test for http://debbugs.gnu.org/27762 ."
- :expected-result :failed
(let* ((dir source-directory)
(default-directory dir)
(files (mapcar (lambda (f) (concat "src/" f))
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-07-21
Repository revision: 1d559e384b467b3f74e8b78695f124b561c884d9
next prev parent reply other threads:[~2017-07-21 4:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-19 3:21 bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons Tino Calancha
2017-07-19 17:04 ` Eli Zaretskii
2017-07-20 3:45 ` Tino Calancha
2017-07-21 4:55 ` Tino Calancha [this message]
2017-07-29 8:09 ` Eli Zaretskii
2017-08-01 7:01 ` Tino Calancha
2017-08-01 13:46 ` Eli Zaretskii
2017-08-01 15:08 ` Tino Calancha
2017-08-01 15:43 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d18uz8w1.fsf@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=27762@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.