emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ibuffer as default


From: Stefan Monnier
Subject: Re: Ibuffer as default
Date: Tue, 11 Mar 2003 14:13:58 -0500

> > I recently changed it to work better, especially for relatively
> > default cases like emacs -nw and Emacs under X with a left-sided
> > scrollbar and left-sided fringe (before it just used one space char
> > regardless).  But it seems doomed to lose given unusual settings.  Is
> > there a straight-forward way to cons up pixel-perfect spacing, say as
> > a display property ?
> 
> Yeah, given the popularity of using it for showing aligned stuff, there
> definitively should at least be an option for the header-line to start
> exactly at the text's left edge.  This could even be something as simple
> as a boolean variable I think, or a magic `%' escape in
> header-line-format.

Agreed.
BTW, I suspect that the `spaces' calculation should ideally
be enhanced to take into account window margins rather than only
scrollbars and fringes.... clearly this is a nightmare and should
be solved in a cleaner way.

> Stefan's problem (different font) seems a lot harder though...

How 'bout the patch below ?
Note that it doesn't address the problem of the leading space
being different in different frames and that it wouldn't be
able to use a % magic thingy either.


        Stefan


--- buff-menu.el.~1.60.~        Mon Mar 10 17:59:02 2003
+++ buff-menu.el        Mon Mar 10 18:49:43 2003
@@ -547,6 +547,9 @@
                       ? )
          size))
 
+(defvar Buffer-menu-header-line nil)
+(put 'Buffer-menu-header-line 'risky-local-variable t)
+
 (defun list-buffers-noselect (&optional files-only)
   "Create and return a buffer with a list of names of existing buffers.
 The buffer is named `*Buffer List*'.
@@ -557,9 +560,31 @@
   (let* ((old-buffer (current-buffer))
         (standard-output standard-output)
         (mode-end (make-string (- Buffer-menu-mode-width 2) ? ))
-        (header (concat "CRM " (Buffer-menu-buffer+size "Buffer" "Size")
+        (header (concat (propertize "CRM " 'face 'fixed-pitch)
+                        (Buffer-menu-buffer+size "Buffer" "Size")
                         "  Mode" mode-end "File\n"))
         list desired-point name file mode)
+    (when Buffer-menu-use-header-line
+      (let ((spaces
+            (/ (+ 0.0 (or (frame-parameter nil 'left-fringe) 0)
+                  (or (if (eq (frame-parameter nil 'vertical-scroll-bars)
+                              'left)
+                          (frame-parameter nil 'scroll-bar-width))
+                      0))
+               (frame-char-width)))
+           (pos 0))
+       ;; Turn spaces in the header into stretch specs so they work
+       ;; regardless of the header-line face.
+       (while (string-match "[ \t]+" header pos)
+         (setq pos (match-end 0))
+         (put-text-property (match-beginning 0) pos 'display
+                            ;; Assume fixed-size chars
+                            (list 'space :align-to (+ spaces pos))
+                            header))
+       ;; Add the leading space
+       (setq header (concat (propertize (make-string (floor spaces) ? )
+                                        'display (list 'space :width spaces))
+                            header))))
     (save-excursion
       (set-buffer (get-buffer-create "*Buffer List*"))
       (setq buffer-read-only nil)
@@ -639,15 +664,7 @@
        (princ "\n"))
       (Buffer-menu-mode)
       (when Buffer-menu-use-header-line
-       (let ((spaces
-              (/ (+ (or (frame-parameter nil 'left-fringe) 0)
-                    (or (if (eq (frame-parameter nil 'vertical-scroll-bars)
-                                'left)
-                            (frame-parameter nil 'scroll-bar-width))
-                        0))
-                 (frame-char-width))))
-         (set (make-local-variable 'Buffer-menu-header-line)
-              (concat (make-string spaces ? ) header)))
+       (set (make-local-variable 'Buffer-menu-header-line) header)
        (setq header-line-format 'Buffer-menu-header-line))
       ;; DESIRED-POINT doesn't have to be set; it is not when the
       ;; current buffer is not displayed for some reason.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]