Package: emacs;
Reported by: Tino Calancha <tino.calancha <at> gmail.com>
Date: Wed, 19 Jul 2017 03:23:02 UTC
Severity: minor
Found in version 26.0.50
Done: Tino Calancha <tino.calancha <at> gmail.com>
Bug is archived. No further changes may be made.
View this message in rfc822 format
From: help-debbugs <at> gnu.org (GNU bug Tracking System) To: Tino Calancha <tino.calancha <at> gmail.com> Subject: bug#27762: closed (Re: bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons) Date: Tue, 01 Aug 2017 15:09:03 +0000
[Message part 1 (text/plain, inline)]
Your bug report #27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 27762 <at> debbugs.gnu.org. -- 27762: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=27762 GNU Bug Tracking System Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com> To: 27762-done <at> debbugs.gnu.org Subject: Re: bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons Date: Wed, 02 Aug 2017 00:08:02 +0900Eli Zaretskii <eliz <at> gnu.org> writes: >> From: Tino Calancha <tino.calancha <at> gmail.com> >> Cc: 27762 <at> debbugs.gnu.org >> Date: Tue, 01 Aug 2017 16:01:17 +0900 >> >> Eli Zaretskii <eliz <at> gnu.org> writes: >> >> > Looks OK, but why this complicated code: >> > >> >> + (when-let* ((col-diff (- (point) (point-at-bol))) >> >> + (higher (> col-diff target))) >> >> + (setq target col-diff))) >> >> + (and (/= first target) target)))) >> > >> > Doesn't current-column do its job in this case? >> That is to work regardless on the `dired-hide-details-mode' value. >> If we use `current-column' we are in trouble. > > Then (a) please mention this issue in a comment before this fragment, > and (b) please don't call the variable "column", because it's > confusing. a) The comment is right before the while loop. b) Done. Pushed into master as commit f74164a845eff579635da0a1267514ef9d040ad2
[Message part 3 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com> To: bug-gnu-emacs <at> gnu.org Subject: 26.0.50; ls-lisp: misalignment when dired-directory is a cons Date: Wed, 19 Jul 2017 12:21:58 +0900There 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 <tino.calancha <at> gmail.com> 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 <tino.calancha <at> gmail.com> 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
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.