branch: externals/ebdb commit 60f7c0410164fa01d9298ec937d87602f8a615dd Author: Eric Abrahamsen <e...@ericabrahamsen.net> Commit: Eric Abrahamsen <e...@ericabrahamsen.net>
Rework Gnus/Message window configuration customization, bump version The fundamental problem was that EBDB shouldn't have been taking over window configuration for Gnus and message-mode. The current implementation provides sane defaults with no config, plus the option to better integrate with Gnus' own window configuration system. * ebdb-gnus.el (ebdb-gnus-window-configuration): Change behavior of option. (ebdb-insinuate-gnus): Only add the option value to ebdb-window-to-buffer if it's a symbol. * ebdb-message.el (ebdb-message-window-configuration, ebdb-insinuate-mail): Do the same for message. (ebdb-message-reply-yank-window-config): Obsolete. * ebdb.info: Document. * ebdb.el: Bump version to 0.6.23. * ebdb-com.el (ebdb-pop-up-window): Refactor to more completely short-circuit if the buffer is already displayed. Gnus will have already popped up the window by now, so do a minimum of work. --- ebdb-com.el | 89 +++++++++++++++++++++++----------------------- ebdb-gnus.el | 50 ++++++++++++-------------- ebdb-message.el | 65 +++++++++++++--------------------- ebdb.el | 2 +- ebdb.info | 107 +++++++++++++++++++++++++++++++++----------------------- ebdb.org | 30 ++++++++++++++-- ebdb.texi | 30 ++++++++++++++-- 7 files changed, 209 insertions(+), 164 deletions(-) diff --git a/ebdb-com.el b/ebdb-com.el index 636cb5f..8a9a38b 100644 --- a/ebdb-com.el +++ b/ebdb-com.el @@ -1200,52 +1200,49 @@ popped up from." (let* ((buf (get-buffer buf)) (split-window (car-safe pop)) (buffer-window (get-buffer-window buf t)) - (direction (or (nth 2 pop) - (if (> (window-total-width split-window) - (window-total-height split-window)) - 'right - 'below))) - (size (cond ((null pop) - nil) - ((integerp (cadr pop)) - (cadr pop)) - ((or (floatp (cadr pop)) (floatp ebdb-default-window-size)) - (let ((flt (or (cadr pop) ebdb-default-window-size))) - (round (* (if (memq direction '(left right)) - (window-total-width split-window) - (window-total-height split-window)) - (- 1 flt))))) - ((integerp ebdb-default-window-size) - ebdb-default-window-size)))) - - (cond (buffer-window - ;; It's already visible, re-use it. - (when select - (select-window buffer-window))) - ((not (or split-window size)) - ;; Not splitting, but buffer isn't visible, just take up - ;; the whole window. - (pop-to-buffer-same-window buf) - (setq buffer-window (get-buffer-window buf t))) - (t - ;; Otherwise split. - (setq - buffer-window - ;; If the window we're splitting is an atomic window, - ;; maybe make our buffer part of the atom. - (if (and ebdb-join-atomic-windows - (window-atom-root split-window)) - (display-buffer-in-atom-window - buf `((window . ,split-window) - (side . ,direction) - ,(if (eq direction 'below) - `(window-height . ,size) - `(window-width . ,size)))) - (split-window - split-window size direction))) - (set-window-buffer buffer-window buf))) - (display-buffer-record-window 'window buffer-window buf) - (set-window-prev-buffers buffer-window nil) + direction size) + ;; It's already visible, re-use it and we're done. + (unless buffer-window + (setq direction (or (nth 2 pop) + (if (> (window-total-width split-window) + (window-total-height split-window)) + 'right + 'below)) + size (cond ((null pop) + nil) + ((integerp (cadr pop)) + (cadr pop)) + ((or (floatp (cadr pop)) (floatp ebdb-default-window-size)) + (let ((flt (or (cadr pop) ebdb-default-window-size))) + (round (* (if (memq direction '(left right)) + (window-total-width split-window) + (window-total-height split-window)) + (- 1 flt))))) + ((integerp ebdb-default-window-size) + ebdb-default-window-size))) + (if (not (or split-window size)) + ;; Not splitting, but buffer isn't visible, just take up + ;; the whole window. + (pop-to-buffer-same-window buf) + (setq buffer-window (get-buffer-window buf t)) + ;; Otherwise split. + (setq + buffer-window + ;; If the window we're splitting is an atomic window, + ;; maybe make our buffer part of the atom. + (if (and ebdb-join-atomic-windows + (window-atom-root split-window)) + (display-buffer-in-atom-window + buf `((window . ,split-window) + (side . ,direction) + ,(if (eq direction 'below) + `(window-height . ,size) + `(window-width . ,size)))) + (split-window + split-window size direction)))) + (set-window-buffer buffer-window buf) + (display-buffer-record-window 'window buffer-window buf) + (set-window-prev-buffers buffer-window nil)) (when select (select-window buffer-window)))) diff --git a/ebdb-gnus.el b/ebdb-gnus.el index 8daa768..6e61bc0 100644 --- a/ebdb-gnus.el +++ b/ebdb-gnus.el @@ -50,26 +50,21 @@ Size should be specified as a float between 0 and 1. Defaults to the value of `ebdb-default-window-size'." :type 'float) -(defcustom ebdb-gnus-window-configuration - `(article - ,(cond - (gnus-use-trees - `(vertical 1.0 - (summary 0.25 point) - (tree 0.25) - (horizontal 1.0 - (article 1.0) - (ebdb-gnus ,ebdb-gnus-window-size)))) - (t - `(vertical 1.0 - (summary 0.25 point) - (horizontal 1.0 - (article 1.0) - (ebdb-gnus ,ebdb-gnus-window-size)))))) - "Gnus window configuration to include EBDB. -By default, this adds the *EBDB-Gnus* window to the right of the -article buffer, taking up 40% of the horizontal space." - :type 'list) +(defcustom ebdb-gnus-window-configuration nil + "Symbol that names EBDB's Gnus window config. +This option is nil by default, meaning Gnus will pop up the +*EBDB-Gnus* window next to the *Article* buffer, with a +width/height of `ebdb-gnus-window-size'. + +If more control is required, set this to a symbol name. This +symbol will be entered into the `gnus-window-to-buffer' alist, +and can be used as an entry in more complex Gnus buffer/window +configurations. + +Note that this should be a different symbol from that used in +Message-mode article composition window config." + :type '(choice (const :tag nil) + (symbol :tag "Window config name"))) (defcustom ebdb-gnus-post-style-function (lambda (_rec _mail) nil) @@ -248,14 +243,6 @@ Note that `( is the backquote, NOT the quote '(." (defsubst ebdb-gnus-buffer-name () (format "*%s-Gnus*" ebdb-buffer-name)) -;; Tell Gnus how to display the *EBDB-Gnus* buffer. -(add-hook 'ebdb-after-load-hook - (lambda () - (with-eval-after-load "gnus-win" - (when ebdb-mua-pop-up - (add-to-list 'gnus-window-to-buffer - `(ebdb-gnus . ,(ebdb-gnus-buffer-name))) - (gnus-add-configuration ebdb-gnus-window-configuration))))) (cl-defmethod ebdb-make-buffer-name (&context (major-mode gnus-summary-mode)) "Produce a EBDB buffer name associated with Gnus." @@ -357,6 +344,13 @@ composed to a certain record." (define-key gnus-summary-mode-map ";" ebdb-mua-keymap) (define-key gnus-article-mode-map ";" ebdb-mua-keymap) + ;; If the user has set this to a symbol, it needs to be added to + ;; Gnus' `gnus-window-to-buffer' list. + (when ebdb-gnus-window-configuration + (add-to-list 'gnus-window-to-buffer + (cons ebdb-gnus-window-configuration + (ebdb-gnus-buffer-name)))) + ;; Versions of Gnus with the gnus-search.el library allow us to ;; perform contact auto-completion within search queries. (when (boundp 'gnus-search-contact-tables) diff --git a/ebdb-message.el b/ebdb-message.el index 77c6466..f230864 100644 --- a/ebdb-message.el +++ b/ebdb-message.el @@ -51,25 +51,26 @@ Size should be specified as a float between 0 and 1. Defaults to the value of `ebdb-default-window-size'." :type 'float) -(defcustom ebdb-message-reply-window-config - `(reply - (horizontal 1.0 - (message 1.0 point) - (ebdb-message ,ebdb-message-window-size))) - "Message reply window configuration to show EBDB. -See Gnus' manual for details." +(defcustom ebdb-message-window-configuration nil + "Symbol that names EBDB's Message reply window config. +This option is nil by default, meaning Gnus will pop up the +*EBDB-Message* buffer next to the message composition buffer, +with width/height of `ebdb-message-window-size'. + +If more control is required, set this to a symbol name. This +symbol will be entered into the `gnus-window-to-buffer' alist, +and can be used as an entry in more complex Gnus buffer/window +configurations. + +Note that this should be a different symbol from that used in +Gnus's article-reading config." :group 'ebdb-mua-message - :type 'list) - -(defcustom ebdb-message-reply-yank-window-config - `(reply-yank - (horizontal 1.0 - (message 1.0 point) - (ebdb-message ,ebdb-message-window-size))) - "Message reply-yank window configuration to show EBDB. -See Gnus' manual for details." - :group 'ebdb-mua-message - :type 'list) + :type '(choice (const nil) + (symbol :tag "Window config name"))) + +(make-obsolete-variable 'ebdb-message-reply-yank-window-config + 'ebdb-message-window-configuration + "0.6.23") ;; Suggestions welcome: What are good keybindings for the following ;; commands that do not collide with existing bindings? @@ -157,6 +158,12 @@ Also fires when postponing a draft." nil t))) ('nil nil) (_ (define-key mail-mode-map "\M-\t" 'ebdb-complete-mail))) + + (when ebdb-message-window-configuration + (add-to-list 'gnus-window-to-buffer + (cons ebdb-message-window-configuration + (ebdb-message-buffer-name)))) + (ebdb-undisplay-records)) (defun ebdb-message-auto-update () @@ -170,27 +177,5 @@ Also fires when postponing a draft." (add-hook 'message-send-hook 'ebdb-message-auto-update) (add-hook 'mail-send-hook 'ebdb-message-auto-update) -;; Slightly convoluted, but does it the "right way". The -;; `message-header-setup-hook' creates and populates the -;; *EBDB-Message* buffer after the message-mode buffer is created. -;; The gnus window configuration stanza makes sure it's displayed -;; after the message buffer is set up. -(add-hook 'ebdb-after-load-hook - (lambda () - (with-eval-after-load "gnus-win" - ;; Display only because we're going to be (possibly) - ;; prompted for creation again when the message is sent. - (add-hook 'message-header-setup-hook #'ebdb-message-display-only) - - (when ebdb-mua-pop-up - (add-to-list 'gnus-window-to-buffer - `(ebdb-message . ,(ebdb-message-buffer-name))) - - (gnus-add-configuration - ebdb-message-reply-window-config) - - (gnus-add-configuration - ebdb-message-reply-yank-window-config))))) - (provide 'ebdb-message) ;;; ebdb-message.el ends here diff --git a/ebdb.el b/ebdb.el index 4fe87fb..22a76fa 100644 --- a/ebdb.el +++ b/ebdb.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2016-2020 Free Software Foundation, Inc. -;; Version: 0.6.22 +;; Version: 0.6.23 ;; Package-Requires: ((emacs "25.1") (cl-lib "0.5") (seq "2.15")) ;; Maintainer: Eric Abrahamsen <e...@ericabrahamsen.net> diff --git a/ebdb.info b/ebdb.info index 79eca58..b727b36 100644 --- a/ebdb.info +++ b/ebdb.info @@ -698,9 +698,28 @@ controlling the window size of pop-up buffers. Each option is named as ‘ebdb-<MUA>-window-size’, and each defaults to ‘ebdb-default-window-size’. - Beyond this, there are no other user customization options -controlling the layout of MUA pop-up buffers. Further customization -will likely be added in the future: please complain to the author. + The Gnus and Message MUAs have their own special window configuration +system (*Note (Gnus)Window Layout::). If you’re not making special use +of that system, EBDB will default to taking up a percentage of the +article and message composition windows. If you are using that system +for more control, you use the ‘ebdb-gnus-window-configuration’ and +‘ebdb-message-window-configuration’ options to do so. They should be +set to two arbitrary (but distinct) symbols, which will be added to the +‘gnus-window-to-buffer’ alist, and can be used in +‘gnus-add-configuration’ calls, for example: + + (gnus-add-configuration + '(article + (vertical 1.0 + (summary 0.25 point) + (horizontal 1.0 + (article 1.0) + (ebdb-gnus 0.4))))) + + Because Gnus and Message use separate EBDB buffers for record update +and display, the two options must be separate, and used in the +appropriate article-display vs message-composition window +configurations. File: ebdb.info, Node: Auto-Updating Records, Next: Noticing and Automatic Rules, Prev: Pop-up Buffers, Up: Display and Updating @@ -2485,6 +2504,7 @@ File: ebdb.info, Node: Index, Prev: Hacking EBDB, Up: Top * ebdb-gnus-auto-update-p: Auto-Updating Records. (line 48) * ebdb-gnus-post-style-function: Posting Styles. (line 13) +* ebdb-gnus-window-configuration: Pop-up Buffers. (line 42) * ebdb-hash-extra-predicates: Fast Lookups. (line 30) * ebdb-hashtable: Fast Lookups. (line 10) * ebdb-help: The Basics of ebdb-mode. @@ -2520,6 +2540,7 @@ File: ebdb.info, Node: Index, Prev: Hacking EBDB, Up: Top (line 48) * ebdb-message-clean-name-function: Sender name display. (line 14) * ebdb-message-mail-as-name: Sender name display. (line 18) +* ebdb-message-window-configuration: Pop-up Buffers. (line 42) * ebdb-mhe-auto-update-p: Auto-Updating Records. (line 48) * ebdb-migrate-from-bbdb: Record Migration. (line 6) @@ -2748,46 +2769,46 @@ Node: MUA Interaction21076 Node: Loading MUA Code21629 Node: Display and Updating22342 Node: Pop-up Buffers23108 -Node: Auto-Updating Records25106 -Node: Noticing and Automatic Rules29900 -Node: Interactive Commands31722 -Node: EBDB and MUA summary buffers34196 -Node: Sender name display34714 -Node: Summary buffer marks35941 -Node: Mail Address Completion37120 -Node: A Note on Completion39629 -Node: Specific MUAs40252 -Node: Gnus40400 -Node: Posting Styles40622 -Node: EBDB Buffers42178 -Node: Searching43389 -Node: Changing Search Behavior45103 -Node: The Basics of ebdb-mode46350 -Node: Customizing Record Display50698 -Node: Marking55018 -Node: Exporting/Formatting55445 -Node: Completion56380 -Node: Snarfing57176 -Node: Internationalization59193 -Node: Diary Integration61894 -Node: Mail Aliases62759 -Node: vCard Support63473 -Node: Org Integration63972 -Node: Citing Records65870 -Node: Hacking EBDB66628 -Node: Field Classes69221 -Node: Init and Delete Methods72402 -Node: Manipulating Field Data Programmatically73926 -Node: The Labeled Field Class75638 -Node: The Singleton Field Class76509 -Node: Actions76947 -Node: Custom Field Searching77619 -Node: Fast Lookups80486 -Node: Formatting in the EBDB Buffer82296 -Node: Writing Internationalization Libraries84372 -Node: Writing Integration For New MUAs88788 -Node: Article snarfing92236 -Node: Index92954 +Node: Auto-Updating Records25958 +Node: Noticing and Automatic Rules30752 +Node: Interactive Commands32574 +Node: EBDB and MUA summary buffers35048 +Node: Sender name display35566 +Node: Summary buffer marks36793 +Node: Mail Address Completion37972 +Node: A Note on Completion40481 +Node: Specific MUAs41104 +Node: Gnus41252 +Node: Posting Styles41474 +Node: EBDB Buffers43030 +Node: Searching44241 +Node: Changing Search Behavior45955 +Node: The Basics of ebdb-mode47202 +Node: Customizing Record Display51550 +Node: Marking55870 +Node: Exporting/Formatting56297 +Node: Completion57232 +Node: Snarfing58028 +Node: Internationalization60045 +Node: Diary Integration62746 +Node: Mail Aliases63611 +Node: vCard Support64325 +Node: Org Integration64824 +Node: Citing Records66722 +Node: Hacking EBDB67480 +Node: Field Classes70073 +Node: Init and Delete Methods73254 +Node: Manipulating Field Data Programmatically74778 +Node: The Labeled Field Class76490 +Node: The Singleton Field Class77361 +Node: Actions77799 +Node: Custom Field Searching78471 +Node: Fast Lookups81338 +Node: Formatting in the EBDB Buffer83148 +Node: Writing Internationalization Libraries85224 +Node: Writing Integration For New MUAs89640 +Node: Article snarfing93088 +Node: Index93806 End Tag Table diff --git a/ebdb.org b/ebdb.org index c096f07..6db0225 100644 --- a/ebdb.org +++ b/ebdb.org @@ -513,9 +513,33 @@ the window size of pop-up buffers. Each option is named as ~ebdb-<MUA>-window-size~, and each defaults to ~ebdb-default-window-size~. -Beyond this, there are no other user customization options controlling -the layout of MUA pop-up buffers. Further customization will likely -be added in the future: please complain to the author. +#+VINDEX: ebdb-gnus-window-configuration +#+VINDEX: ebdb-message-window-configuration +The Gnus and Message MUAs have their own special window +configuration system (@@texinfo:@xref{Window Layout,,,Gnus}@@). If +you're not making special use of that system, EBDB will default to +taking up a percentage of the article and message composition +windows. If you are using that system for more control, you use the +~ebdb-gnus-window-configuration~ and +~ebdb-message-window-configuration~ options to do so. They should be +set to two arbitrary (but distinct) symbols, which will be added to +the ~gnus-window-to-buffer~ alist, and can be used in +~gnus-add-configuration~ calls, for example: + +#+begin_src elisp + (gnus-add-configuration + '(article + (vertical 1.0 + (summary 0.25 point) + (horizontal 1.0 + (article 1.0) + (ebdb-gnus 0.4))))) +#+end_src + +Because Gnus and Message use separate EBDB buffers for record update +and display, the two options must be separate, and used in the +appropriate article-display vs message-composition window +configurations. *** Auto-Updating Records EBDB can automatically update the name and mail addresses of records based on information in an MUA message. The first and most important diff --git a/ebdb.texi b/ebdb.texi index c563f56..fa44a31 100644 --- a/ebdb.texi +++ b/ebdb.texi @@ -733,9 +733,33 @@ the window size of pop-up buffers. Each option is named as @code{ebdb-<MUA>-window-size}, and each defaults to @code{ebdb-default-window-size}. -Beyond this, there are no other user customization options controlling -the layout of MUA pop-up buffers. Further customization will likely -be added in the future: please complain to the author. +@vindex ebdb-gnus-window-configuration +@vindex ebdb-message-window-configuration +The Gnus and Message MUAs have their own special window +configuration system (@xref{Window Layout,,,Gnus}). If +you're not making special use of that system, EBDB will default to +taking up a percentage of the article and message composition +windows. If you are using that system for more control, you use the +@code{ebdb-gnus-window-configuration} and +@code{ebdb-message-window-configuration} options to do so. They should be +set to two arbitrary (but distinct) symbols, which will be added to +the @code{gnus-window-to-buffer} alist, and can be used in +@code{gnus-add-configuration} calls, for example: + +@lisp +(gnus-add-configuration + '(article + (vertical 1.0 + (summary 0.25 point) + (horizontal 1.0 + (article 1.0) + (ebdb-gnus 0.4))))) +@end lisp + +Because Gnus and Message use separate EBDB buffers for record update +and display, the two options must be separate, and used in the +appropriate article-display vs message-composition window +configurations. @node Auto-Updating Records @subsection Auto-Updating Records