unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: 27762@debbugs.gnu.org
Subject: bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons
Date: Wed, 19 Jul 2017 12:21:58 +0900	[thread overview]
Message-ID: <87wp75yuuh.fsf@calancha-pc> (raw)


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 <tino.calancha@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@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





             reply	other threads:[~2017-07-19  3:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-19  3:21 Tino Calancha [this message]
2017-07-19 17:04 ` bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons Eli Zaretskii
2017-07-20  3:45   ` Tino Calancha
2017-07-21  4:55     ` Tino Calancha
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wp75yuuh.fsf@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=27762@debbugs.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).