From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.bugs Subject: bug#21649: 25.0.50; [PATCH] Allow M-x man to reuse an existing window Date: Tue, 01 Mar 2016 16:49:07 +0100 Message-ID: <861t7unqq4.fsf@members.fsf.org> References: <86r3l09t3u.fsf@members.fsf.org> <86y4f6v2r2.fsf@members.fsf.org> <561E1736.7070706@gmx.at> <86wpufc8n8.fsf@members.fsf.org> <56290200.1000700@gmx.at> <86bnbqd80z.fsf@members.fsf.org> <5629E96C.3090307@gmx.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1456847905 11741 80.91.229.3 (1 Mar 2016 15:58:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Mar 2016 15:58:25 +0000 (UTC) Cc: "21649@debbugs.gnu.org" <21649@debbugs.gnu.org> To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Mar 01 16:58:14 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aamgg-0006Rz-7n for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Mar 2016 16:58:14 +0100 Original-Received: from localhost ([::1]:50524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aamgf-00078K-NG for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Mar 2016 10:58:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aamYr-0001Cf-80 for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 10:50:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aamYk-0003U2-NJ for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 10:50:09 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59339) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aamYk-0003Tr-IO for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 10:50:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aamYk-0006K2-5o for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 10:50:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Richard Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Mar 2016 15:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21649 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 21649-submit@debbugs.gnu.org id=B21649.145684735124234 (code B ref 21649); Tue, 01 Mar 2016 15:50:02 +0000 Original-Received: (at 21649) by debbugs.gnu.org; 1 Mar 2016 15:49:11 +0000 Original-Received: from localhost ([127.0.0.1]:56466 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aamXu-0006In-Pj for submit@debbugs.gnu.org; Tue, 01 Mar 2016 10:49:11 -0500 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:38337) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aamXs-0006Ie-Vj for 21649@debbugs.gnu.org; Tue, 01 Mar 2016 10:49:09 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsAEAPi41VakD4Ux/2dsb2JhbABehHmmVwMBAQEGkT6EB4YTAoIVAQEBAQEBZSeEQQEBAQQjVhAIAxEDAQIKIQICDwE/CAYTiAoDErBwjxsBAQEBAQEEAQEBAQETCIVKhQKCOoIbgmCBOgWXDo9ChESCdIVejkxig2U7LohBAQEB Original-Received: from pno-math-49.ulb.ac.be (HELO Aurora) ([164.15.133.49]) by smtp.ulb.ac.be with ESMTP; 01 Mar 2016 16:49:07 +0100 User-agent: mu4e 0.9.17; emacs 25.0.50.2 In-reply-to: <5629E96C.3090307@gmx.at> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:114241 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit martin rudalics writes: > (2) Allow to specify the desired (parent) mode via an ALIST ‘mode’ > entry. As value we could allow a single mode or a list of modes. Then > a window showing a buffer in the same mode as the buffer we want to > display should maybe given preference to a window showing a buffer in > another mode, derived from the same parent mode. If a same-mode-window > exists on another and a derived-mode-window exists on the selected > frame, one of these should be given preference consistently. Well, it took a bit of time but here I am ! Could you please review the following patch ? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-new-function-display-buffer-reuse-mode-window.patch >From 1623ed372ffce726c4f5b20ca2f333a9e5ba6f92 Mon Sep 17 00:00:00 2001 From: Nicolas Richard Date: Tue, 1 Mar 2016 12:33:05 +0100 Subject: [PATCH] Add new function display-buffer-reuse-mode-window * lisp/window.el (display-buffer-reuse-mode-window): New function. * doc/lispref/windows.texi (Display Action Functions): Document it. --- doc/lispref/windows.texi | 17 ++++++++++++ lisp/window.el | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 7186791..c52bf0e 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -2395,6 +2395,23 @@ Display Action Functions entry (@pxref{Choosing Window Options}), raises that frame if necessary. @end defun +@defun display-buffer-reuse-mode-window buffer alist +This function tries to display @var{buffer} by finding a window +that is displaying a buffer in a given mode. + +If @var{alist} contains a @code{mode} entry, its value is a major mode +(a symbol) or a list of major modes. If @var{alist} contains no +@code{mode} entry, the current major mode of @var{buffer} is used. A +window is a candidate if it displays a buffer that derives from one of +the given modes. + +The behaviour is also controlled by entries for +@code{inhibit-same-window}, @code{reusable-frames} and +@code{inhibit-switch-frame} as is done in the function +@code{display-buffer-reuse-window}. + +@end defun + @defun display-buffer-pop-up-frame buffer alist This function creates a new frame, and displays the buffer in that frame's window. It actually performs the frame creation by calling diff --git a/lisp/window.el b/lisp/window.el index 620f4ed..4586994 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -6721,6 +6721,74 @@ display-buffer-reuse-window (unless (cdr (assq 'inhibit-switch-frame alist)) (window--maybe-raise-frame (window-frame window))))))) +(defun display-buffer-reuse-mode-window (buffer alist) + "Return a window based on the mode of the buffer it displays. +Display BUFFER in the returned window. Return nil if no usable +window is found. + +If ALIST contains a `mode' entry, its value is a major mode (a +symbol) or a list of modes. A window is a candidate if it +displays a buffer that derives from one of the given modes. When +ALIST contains no `mode' entry, the current major mode of BUFFER +is used. + +The behaviour is also controlled by entries for +`inhibit-same-window', `reusable-frames' and +`inhibit-switch-frame' as is done in the function +`display-buffer-reuse-window'." + (let* ((alist-entry (assq 'reusable-frames alist)) + (alist-mode-entry (assq 'mode alist)) + (frames (cond (alist-entry (cdr alist-entry)) + ((if (eq pop-up-frames 'graphic-only) + (display-graphic-p) + pop-up-frames) + 0) + (display-buffer-reuse-frames 0) + (t (last-nonminibuffer-frame)))) + (inhibit-same-window-p (cdr (assq 'inhibit-same-window alist))) + (windows (window-list-1 nil 'nomini frames)) + (buffer-mode (with-current-buffer buffer major-mode)) + (allowed-modes (if alist-mode-entry + (cdr alist-mode-entry) + buffer-mode)) + (curwin (selected-window)) + (curframe (selected-frame))) + (unless (listp allowed-modes) + (setq allowed-modes (list allowed-modes))) + (let (same-mode-same-frame + same-mode-other-frame + derived-mode-same-frame + derived-mode-other-frame) + (dolist (window windows) + (let ((window-mode (with-current-buffer + (window-buffer window) + major-mode)) + mode? frame?) + (setq mode? + (cond ((memq window-mode allowed-modes) + 'same) + ((let ((major-mode window-mode)) + (derived-mode-p allowed-modes)) + 'derived))) + (when (and mode? + (not (and inhibit-same-window-p + (eq window curwin)))) + (if (eq curframe (window-frame window)) + (if (eq mode? 'same) + (push window same-mode-same-frame) + (push window derived-mode-same-frame)) + (if (eq mode? 'same) + (push window same-mode-other-frame) + (push window derived-mode-other-frame)))))) + (let ((window (first (nconc same-mode-same-frame + same-mode-other-frame + derived-mode-same-frame + derived-mode-other-frame)))) + (when (window-live-p window) + (prog1 (window--display-buffer buffer window 'reuse alist) + (unless (cdr (assq 'inhibit-switch-frame alist)) + (window--maybe-raise-frame (window-frame window))))))))) + (defun display-buffer--special-action (buffer) "Return special display action for BUFFER, if any. If `special-display-p' returns non-nil for BUFFER, return an -- 2.4.5 --=-=-= Content-Type: text/plain -- Nicolas. --=-=-=--