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: Wed, 19 Jul 2017 12:21:58 +0900 Message-ID: <87wp75yuuh.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1500434603 3983 195.159.176.226 (19 Jul 2017 03:23:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Jul 2017 03:23:23 +0000 (UTC) To: 27762@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 19 05:23:17 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 1dXfZy-0000Vp-E6 for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Jul 2017 05:23:14 +0200 Original-Received: from localhost ([::1]:59598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXfa2-0008Fr-Cq for geb-bug-gnu-emacs@m.gmane.org; Tue, 18 Jul 2017 23:23:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXfZr-0008Dc-UZ for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2017 23:23:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXfZm-0005p7-UR for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2017 23:23:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44380) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dXfZm-0005p3-Qr for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2017 23:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dXfZm-0000Ko-IK for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2017 23:23: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: Wed, 19 Jul 2017 03:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27762 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15004345411188 (code B ref -1); Wed, 19 Jul 2017 03:23:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Jul 2017 03:22:21 +0000 Original-Received: from localhost ([127.0.0.1]:47057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXfZ6-0000J6-UR for submit@debbugs.gnu.org; Tue, 18 Jul 2017 23:22:21 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33748) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXfZ5-0000Is-9Y for submit@debbugs.gnu.org; Tue, 18 Jul 2017 23:22:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXfYy-0005Vx-SW for submit@debbugs.gnu.org; Tue, 18 Jul 2017 23:22:14 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:46155) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXfYy-0005Vt-Oo for submit@debbugs.gnu.org; Tue, 18 Jul 2017 23:22:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXfYw-0007lk-QB for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2017 23:22:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXfYr-0005Ue-QP for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2017 23:22:10 -0400 Original-Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]:36277) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dXfYr-0005UO-Hl for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2017 23:22:05 -0400 Original-Received: by mail-pf0-x230.google.com with SMTP id o88so14175845pfk.3 for ; Tue, 18 Jul 2017 20:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=ejOD8HItn4bfS3mgjFXlWyEVlsxRHcOuS2S//W8bplg=; b=VQ2199OUpFIHetpHsy3a9q6FxmwNbx8v3Kx+mzNMmWewxAQM4ZlJ5P5uSXYD7WBcQH qlbXHvs9CMFcWVJXgAJEwqGN8jT4Yd1oRUbI3JXd4RUgSTqQtbCBzBILv/wyYsJ+MUK1 4qMfbap5JW5GVdcb1wgor+tmQos6F1xdm53sYfPBoGKTG8ZbmhLp5Njvvaj8Reyexjt0 Zih0//n4YP2IgvbXDMTtuoFC6RX72o1OnOOlok7BGO4jPXowbA3G+q35izldwCdHM9BE F4gNsYRpOLKyNzvUJ9/alBHAI/H1ixf1h/bmTmg4qCTpfH2uSv7zZh9i+GKsPvVlNm73 frWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=ejOD8HItn4bfS3mgjFXlWyEVlsxRHcOuS2S//W8bplg=; b=QqrU5uXXPXDaBCmdn7a37FIOxh4FrPIDGr3vkkg/1pBrlBUqT65QPL5qXbi5ZXeNKe IsFnX/O/zS3ycfMehatZS2t55aeI8asJ24ADZYbQoBXFjLSoqmNmHHRD8IvmsaFgkMTv uHuHBqYBXiMOSwGExQldDDs1PgEz0iBBkmtmTqrvl3OUoMxEERzNwT+gMoVUp2kHp9nC RQvDD83OaqPC/a5/j7pn5yfshMt7yckwGmQR653CJueS1CtHc2ABfNrf8dLKIYnaRRl1 7tb2ucOt3lC6EmazD8qM7YRavf6GFAyqQQvZxTfElHuj9P5LXfDwR1RkrPOY+73Lh1xH abgw== X-Gm-Message-State: AIVw113V/qmHWjuzQY5DXqzEmIo/gy5Wb2XqAFsV8ZzBfAZhWTzcbC/B Ai6Gm1R+3bkpEk40 X-Received: by 10.99.175.12 with SMTP id w12mr846760pge.250.1500434522660; Tue, 18 Jul 2017 20:22:02 -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 v17sm10054542pgn.4.2017.07.18.20.22.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Jul 2017 20:22:02 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:134736 Archived-At: There are some misalignment on Dired buffers when using 'ls-lisp' and 'dired-directory' is a cons. I) emacs -Q -l ls-lisp -eval '(setq ls-lisp-use-insert-directory-program nil)' Eval this form: (let* ((dir source-directory) (default-directory dir) (files (mapcar (lambda (f) (concat "src/" f)) (directory-files (expand-file-name "src") nil "\\.*\\.c\\'")))) (dired (nconc (list dir) files))) ;; Note some lines have an additional space in front; the space must ;; be added in the size column. The first patch solves this problem. II) Now suppose we want to list the same files _but_ we want that "cyge32.c" appears the first. emacs -Q -l ls-lisp -eval '(setq ls-lisp-use-insert-directory-program nil)' Eval this form: (let* ((dir source-directory) (default-directory dir) (files (mapcar (lambda (f) (concat "src/" f)) (cons "cygw32.c" (delete "cygw32.c" (directory-files (expand-file-name "src") nil "\\.*\\.c\\'")))))) (dired (nconc (list dir) files))) ;; Note how the first file looks misaligned. --8<-----------------------------cut here---------------start------------->8--- commit b1889776b4fc808036da259b588365e85cf52324 Author: Tino Calancha Date: Wed Jul 19 11:16:13 2017 +0900 * lisp/dired.el (dired-align-file): Add the spaces in size column. diff --git a/lisp/dired.el b/lisp/dired.el index 4fb4fe78f8..f4941e0d91 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1153,7 +1153,14 @@ dired-align-file (setq file-col (+ spaces file-col)) (if (> file-col other-col) (setq spaces (- spaces (- file-col other-col)))) - (insert-char ?\s spaces) + ;; Add the spaces in front of the file size. + (when (search-forward-regexp directory-listing-before-filename-regexp nil t) + (goto-char (match-beginning 0)) + ;; If size is in human readable units, then we should skip + ;; '.' and letters (units) as well. + (search-backward-regexp "[[:space:]]" nil t) + (skip-chars-forward "[:space:]") + (insert-char ?\s spaces)) ;; Let's just make really sure we did not mess up. (unless (save-excursion (eq (dired-move-to-filename) (marker-position file))) commit 16baaf7df330309be6490b115c513371c0660aef Author: Tino Calancha Date: Wed Jul 19 11:52:30 2017 +0900 ls-lisp: Fix dired format when dired-directory is a cons * lisp/ls-lisp.el (ls-lisp-obtain-formats): New defun extracted from ls-lisp-insert-directory. * lisp/dired.el (dired-readin-insert): Call it if 'dired-directory' is a cons and we are using ls-lisp. (ls-lisp-use-insert-directory-program): Move declaration before use this var. diff --git a/lisp/dired.el b/lisp/dired.el index f4941e0d91..95f438e912 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1035,15 +1035,20 @@ dired-readin ;; Subroutines of dired-readin +(defvar ls-lisp-use-insert-directory-program) +(declare-function ls-lisp-obtain-formats "ls-lisp" (alist file-list switches)) (defun dired-readin-insert () ;; Insert listing for the specified dir (and maybe file list) ;; already in dired-directory, assuming a clean buffer. (let (dir file-list) - (if (consp dired-directory) + (cond ((consp dired-directory) + (when (and (featurep 'ls-lisp) + (null ls-lisp-use-insert-directory-program)) + (ls-lisp-obtain-formats nil (cdr dired-directory) nil)) (setq dir (car dired-directory) - file-list (cdr dired-directory)) - (setq dir dired-directory - file-list nil)) + file-list (cdr dired-directory))) + (t (setq dir dired-directory + file-list nil))) (setq dir (expand-file-name dir)) (if (and (equal "" (file-name-nondirectory dir)) (not file-list)) @@ -1171,7 +1176,6 @@ dired-align-file (set-marker file nil))))) -(defvar ls-lisp-use-insert-directory-program) (defun dired-check-switches (switches short &optional long) "Return non-nil if the string SWITCHES matches LONG or SHORT format." diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index b368efbbc9..391afd16bd 100644 --- a/lisp/ls-lisp.el +++ b/lisp/ls-lisp.el @@ -338,6 +338,46 @@ ls-lisp--insert-directory (insert " available " available))))))))) (advice-add 'insert-directory :around #'ls-lisp--insert-directory) +(defun ls-lisp-obtain-formats (alist file-list switches) + (let ((file-alist (or alist + (mapcar (lambda (f) + (nconc (list f) (file-attributes f))) file-list))) + (sum 0) + (max-uid-len 0) + (max-gid-len 0) + (max-file-size 0) + ;; do all bindings here for speed + total-line files elt short file-size attr + fuid fgid uid-len gid-len) + (dolist (elt file-alist) + (setq attr (cdr elt) + fuid (nth 2 attr) + uid-len (if (stringp fuid) (string-width fuid) + (length (format "%d" fuid))) + fgid (nth 3 attr) + gid-len (if (stringp fgid) (string-width fgid) + (length (format "%d" fgid))) + file-size (nth 7 attr)) + (if (> uid-len max-uid-len) + (setq max-uid-len uid-len)) + (if (> gid-len max-gid-len) + (setq max-gid-len gid-len)) + (if (> file-size max-file-size) + (setq max-file-size file-size))) + (setq ls-lisp-uid-d-fmt (format " %%-%dd" max-uid-len)) + (setq ls-lisp-uid-s-fmt (format " %%-%ds" max-uid-len)) + (setq ls-lisp-gid-d-fmt (format " %%-%dd" max-gid-len)) + (setq ls-lisp-gid-s-fmt (format " %%-%ds" max-gid-len)) + (setq ls-lisp-filesize-d-fmt + (format " %%%dd" (length (format "%.0f" max-file-size)))) + (setq ls-lisp-filesize-f-fmt + (format " %%%d.0f" (length (format "%.0f" max-file-size)))) + (if (memq ?s switches) + (setq ls-lisp-filesize-b-fmt + (format "%%%d.0f " + (length (format "%.0f" + (fceiling + (/ max-file-size 1024.0))))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) "Insert directory listing for FILE, formatted according to SWITCHES. @@ -381,35 +421,7 @@ ls-lisp-insert-directory ;; Find the appropriate format for displaying uid, gid, and ;; file size, by finding the longest strings among all the ;; files we are about to display. - (dolist (elt file-alist) - (setq attr (cdr elt) - fuid (nth 2 attr) - uid-len (if (stringp fuid) (string-width fuid) - (length (format "%d" fuid))) - fgid (nth 3 attr) - gid-len (if (stringp fgid) (string-width fgid) - (length (format "%d" fgid))) - file-size (nth 7 attr)) - (if (> uid-len max-uid-len) - (setq max-uid-len uid-len)) - (if (> gid-len max-gid-len) - (setq max-gid-len gid-len)) - (if (> file-size max-file-size) - (setq max-file-size file-size))) - (setq ls-lisp-uid-d-fmt (format " %%-%dd" max-uid-len)) - (setq ls-lisp-uid-s-fmt (format " %%-%ds" max-uid-len)) - (setq ls-lisp-gid-d-fmt (format " %%-%dd" max-gid-len)) - (setq ls-lisp-gid-s-fmt (format " %%-%ds" max-gid-len)) - (setq ls-lisp-filesize-d-fmt - (format " %%%dd" (length (format "%.0f" max-file-size)))) - (setq ls-lisp-filesize-f-fmt - (format " %%%d.0f" (length (format "%.0f" max-file-size)))) - (if (memq ?s switches) - (setq ls-lisp-filesize-b-fmt - (format "%%%d.0f " - (length (format "%.0f" - (fceiling - (/ max-file-size 1024.0))))))) + (ls-lisp-obtain-formats file-alist nil switches) (setq files file-alist) (while files ; long (-l) format (setq elt (car files) --8<-----------------------------cut here---------------end--------------->8--- The second patch seems to fix this problem. In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-07-18 Repository revision: be79366410703a788c3c8ce7951e89bc9dfdac88