all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#27762: 26.0.50; ls-lisp: misalignment when dired-directory is a cons
@ 2017-07-19  3:21 Tino Calancha
  2017-07-19 17:04 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Tino Calancha @ 2017-07-19  3:21 UTC (permalink / raw)
  To: 27762


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





^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-08-01 15:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.