From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons Date: Fri, 21 Jul 2017 13:55:26 +0900 Message-ID: <87d18uz8w1.fsf@calancha-pc> References: <87wp75yuuh.fsf@calancha-pc> <83vamobboe.fsf@gnu.org> <87lgnjzs8d.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1500612975 19215 195.159.176.226 (21 Jul 2017 04:56:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 21 Jul 2017 04:56:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 27762@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 21 06:56:09 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYPyy-0004U6-Hq for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Jul 2017 06:56:08 +0200 Original-Received: from localhost ([::1]:41039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYPz2-0000ox-7g for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Jul 2017 00:56:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYPyw-0000or-BR for bug-gnu-emacs@gnu.org; Fri, 21 Jul 2017 00:56:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYPyt-0006CK-99 for bug-gnu-emacs@gnu.org; Fri, 21 Jul 2017 00:56:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dYPyt-0006Bd-6M for bug-gnu-emacs@gnu.org; Fri, 21 Jul 2017 00:56:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dYPys-0005q7-7j for bug-gnu-emacs@gnu.org; Fri, 21 Jul 2017 00:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 21 Jul 2017 04:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27762 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27762-submit@debbugs.gnu.org id=B27762.150061295122431 (code B ref 27762); Fri, 21 Jul 2017 04:56:02 +0000 Original-Received: (at 27762) by debbugs.gnu.org; 21 Jul 2017 04:55:51 +0000 Original-Received: from localhost ([127.0.0.1]:50258 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYPyf-0005ph-Vw for submit@debbugs.gnu.org; Fri, 21 Jul 2017 00:55:50 -0400 Original-Received: from mail-pg0-f41.google.com ([74.125.83.41]:37942) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYPyd-0005pU-U1 for 27762@debbugs.gnu.org; Fri, 21 Jul 2017 00:55:48 -0400 Original-Received: by mail-pg0-f41.google.com with SMTP id s4so23617950pgr.5 for <27762@debbugs.gnu.org>; Thu, 20 Jul 2017 21:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=ghOo81Df2Jc/o7yXhlT8F8IrLnd9TwYpiNbxpT59u3w=; b=hPhJevQWqzWud7lpGrvDAhzjsD2v/3y8MvcD12+1yYyzI2sD7FuAhsPhC0cvVWeWkp 4j1yXdzCQ4Y2JInvU/7y0rnBotGfD9pltNuN1Qa63X4kxQzci5Uyf8ynrzFLnaie/1So dit156qNRjm0i+zoG0+jc7T2wVwQFT3UyRWIS5BKFeKn4LChiSTJzIu6PnFfUPHUC1H5 uBnS0vQAnkApSbDk1RzoKuNKR+XRiyCMZKrP3ldz9wP5k47EDxd5Po58rAZ53oLpndA7 L10bXSZ0eMqlde9bQpzPa69s4oz/yPDXQpQ15Fi4HgyaxCrcA64QMrZgSj2Z8boAotsF T90g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=ghOo81Df2Jc/o7yXhlT8F8IrLnd9TwYpiNbxpT59u3w=; b=LkCQp8kN1odJyhb9UFZ2kV71zX0x8gvmC2ro3HRUtiUcffAyOYvyjDNK6ySmQfL4QI owHcm9Ox7W9TVMXus6A+mhDKU2JNMFYMOo5c1W/tRYmeGHKzuzJh8zfUOtNgSmOEP/9w O5RJn6w/xkgTmh3yZo/755Sdw2oWO8txxtGH2+JrdC2ln8PM9fZ85izy8ULeat2sVms6 RYZtqIqbNb/9pMyEwo5IoIA5NDzlaEJXubnwwAJgBvvenm3TyPKeZ8EomF8Ptdj5DXCw J2dPZOwTjdahYhFamqvacnwgtcVyuoiAIpz8FY8WLFZ/imQms7w0oh2dlXBLVB/MDE/H Kd4A== X-Gm-Message-State: AIVw112m7Gi9FberpaWtApbJ+Zdj6fHGrtGm1ay94UOmphGEDAqjWe87 4OXVjmtWPF7a7ylZ X-Received: by 10.98.33.148 with SMTP id o20mr6069995pfj.89.1500612941526; Thu, 20 Jul 2017 21:55:41 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id q79sm6302731pfi.99.2017.07.20.21.55.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jul 2017 21:55:40 -0700 (PDT) In-Reply-To: <87lgnjzs8d.fsf@calancha-pc> (Tino Calancha's message of "Thu, 20 Jul 2017 12:45:22 +0900") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134812 Archived-At: > 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 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