here is the complete patch:
basically, I sacrifice the failed attempt to only split the mua windows
for the sake of robustness.

diff --git a/ChangeLog b/ChangeLog
index 6bbbe47..29b211c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-12-29  Sam Steingold  <s...@gnu.org>
+       * lisp/bbdb.el (bbdb-display-records)
+       (bbdb-display-records-internal): Do not accept horiz-p.
+       (bbdb-tallest-window): Extract from `bbdb-pop-up-window'.
+       (bbdb-pop-up-window): Do not accept horiz-p; always split the
+       tallest window when possible, whether horizontally or vertically.
+       * lisp/bbdb-mua.el (bbdb-mua-auto-update):
+       Do not pass horiz-p to `bbdb-display-records-internal'.
+
 2011-12-28  Sam Steingold  <s...@gnu.org>
        * lisp/bbdb.el (bbdb-pop-up-window):
        Shrink the vertical *BBDB* window when possible.
diff --git a/lisp/bbdb-mua.el b/lisp/bbdb-mua.el
index e0059a1..2f93b6f 100644
--- a/lisp/bbdb-mua.el
+++ b/lisp/bbdb-mua.el
@@ -786,22 +786,11 @@ See `bbdb-mua-display-records' and friends for 
interactive commands."
          (records (bbdb-mua-update-records header-class
                                            (or update-p
                                                bbdb-mua-auto-update-p))))
-    (if bbdb-message-pop-up
-        (let* ((mua (bbdb-mua))
-               (mode (cond ((eq mua 'vm) 'vm-mode)
-                           ((eq mua 'gnus) 'gnus-article-mode)
-                           ((eq mua 'rmail) 'rmail-mode)
-                           ((eq mua 'mh) 'mh-folder-mode)
-                           ((eq mua 'message) 'message-mode)
-                           ((eq mua 'mail) 'mail-mode))))
-          (if records
-              (bbdb-display-records-internal
-               records nil nil nil
-               `(lambda (window)
-                  (with-current-buffer (window-buffer window)
-                    (eq major-mode ',mode))))
-            ;; If there are no records, empty the BBDB window.
-            (bbdb-undisplay-records))))
+    (when bbdb-message-pop-up
+      (if records
+          (bbdb-display-records-internal records)
+        ;; If there are no records, empty the BBDB window.
+        (bbdb-undisplay-records)))
     records))
 
 ;; Should the following be replaced by a minor mode??
diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index 87f6c9f..ab6ace2 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -2801,7 +2801,7 @@ Move point to the end of the inserted record."
       (put-text-property beg (point) 'bbdb-record-number number))))
 
 (defun bbdb-display-records (&optional records layout append
-                                       select horiz-p electric-p)
+                                       select electric-p)
   "Display RECORDS using LAYOUT."
   (interactive (list (bbdb-completing-read-records "Display records: ")
                      (bbdb-layout-prefix)))
@@ -2812,14 +2812,13 @@ Move point to the end of the inserted record."
         (progn
           (define-key bbdb-mode-map " " 'bbdb-electric-done)
           (bbdb-electric-display-records records))
-      (bbdb-display-records-internal records layout append select horiz-p)
+      (bbdb-display-records-internal records layout append select)
       ;; do not smash keybinding if they invoked `bbdb-display'
       ;; from inside an electric loop.
       (unless bbdb-inside-electric-display
         (define-key bbdb-mode-map " " 'undefined)))))
 
-(defun bbdb-display-records-internal (records &optional layout append
-                                              select horiz-p)
+(defun bbdb-display-records-internal (records &optional layout append select)
   "Low-level function overlooking the setup of the *BBDB* buffer."
   (if (bbdb-append-display-p) (setq append t))
 
@@ -2852,7 +2851,7 @@ Move point to the end of the inserted record."
             (set (make-local-variable 'bbdb-buffer-name) new-name)))))
 
     (unless (get-buffer-window bbdb-buffer-name)
-      (bbdb-pop-up-window select horiz-p))
+      (bbdb-pop-up-window select))
     (set-buffer bbdb-buffer-name) ;; *BBDB*
 
     ;; If we're appending RECORDS to the ones already displayed,
@@ -2982,40 +2981,43 @@ The *BBDB* buffer must be current when this is called."
 
 
 
+(defun bbdb-tallest-window ()
+  "Find the tallest window."
+  (let ((tallest-window (selected-window)))
+    (dolist (window (window-list) tallest-window)
+      (when (> (window-height window) (window-height tallest-window))
+        (setq tallest-window window)))))
+
 ;;; window configuration hackery
-(defun bbdb-pop-up-window (&optional select horiz-p)
+(defun bbdb-pop-up-window (&optional select)
   "Find the largest window on the screen, and split it, displaying the
 *BBDB* buffer in the bottom `bbdb-pop-up-window-size' lines (unless
 the *BBDB* buffer is already visible, in which case do nothing.)
 Select this window if SELECT is non-nil.
 
-If `bbdb-message-pop-up' is 'horiz, and the first window matching
-HORIZ-P is sufficiently wide (> 112 columns) then the window
+If `bbdb-message-pop-up' is 'horiz, and the tallest window
+is sufficiently wide (see bbdb-horiz-pop-up-window-size) then the window
 will be split vertically rather than horizontally."
   (cond (;; We already have a BBDB window so that nothing needs to be done
          (get-buffer-window bbdb-buffer-name))
 
         ;; try horizontal split
         ((and (eq bbdb-message-pop-up 'horiz)
-              horiz-p
               (>= (frame-width) (car bbdb-horiz-pop-up-window-size))
               (let ((cbuffer (current-buffer))
-                    (window-list (window-list))
                     (selected-window (selected-window))
                     (b-width (cdr bbdb-horiz-pop-up-window-size))
-                    (search t) window)
-                (while (and (setq window (pop window-list))
-                            (setq search (funcall horiz-p window))))
-                (unless (or search (<= (window-width window)
-                                       (car bbdb-horiz-pop-up-window-size)))
-                  (select-window window)
+                    (tallest-window (bbdb-tallest-window)))
+                (when (> (window-width tallest-window)
+                         (car bbdb-horiz-pop-up-window-size))
+                  (select-window tallest-window)
                   (condition-case nil ; `split-window-horizontally' might fail
                       (progn
                         (split-window-horizontally
                          (if (integerp b-width)
-                             (- (window-width window) b-width)
-                           (round (* (- 1 b-width) (window-width window)))))
-                        (select-window (next-window window))
+                             (- (window-width tallest-window) b-width)
+                           (round (* (- 1 b-width) (window-width 
tallest-window)))))
+                        (select-window (next-window tallest-window))
                         (let (pop-up-windows)
                           (switch-to-buffer (get-buffer-create 
bbdb-buffer-name)))
                         (unless select
@@ -3025,13 +3027,9 @@ will be split vertically rather than horizontally."
                     (error nil))))))
 
         (t ;; vertical split
-         (let* ((cbuffer (current-buffer))
-                (selected-window (selected-window))
-                (tallest-window selected-window))
-           ;; find the tallest window...
-           (dolist (window (window-list))
-             (if (> (window-height window) (window-height tallest-window))
-                 (setq tallest-window window)))
+         (let ((cbuffer (current-buffer))
+               (selected-window (selected-window))
+               (tallest-window (bbdb-tallest-window)))
            (select-window tallest-window)   ; select it and split it...
            (if (eql bbdb-pop-up-window-size 1.0)
                ;; select `bbdb-buffer-name'

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://camera.org http://palestinefacts.org http://mideasttruth.com
http://dhimmi.com http://thereligionofpeace.com http://www.memritv.org
If you think big enough, you'll never have to do it.


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Reply via email to