From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: master 6e5d79c048: Display show-paren-context-when-offscreen in child frame Date: Mon, 07 Feb 2022 16:45:06 +0100 Message-ID: <87y22m8yth.fsf@gnu.org> References: <164414267475.11015.16458968298391656164@vcs2.savannah.gnu.org> <20220206101755.0EC03C002F9@vcs2.savannah.gnu.org> <871r0f7k6u.fsf@gnus.org> <87czjzlb1h.fsf@yahoo.com> <877da79p7y.fsf@gnu.org> <86leym6bxa.fsf@gnu.org> <8735kuah78.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7957"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.7; emacs 29.0.50 Cc: Po Lu , Arash Esbati , Lars Ingebrigtsen , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Feb 07 16:49:43 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nH6Gt-0001ri-1A for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Feb 2022 16:49:43 +0100 Original-Received: from localhost ([::1]:53516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH6Gr-0007jZ-Gk for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Feb 2022 10:49:41 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH6DZ-000479-MN for emacs-devel@gnu.org; Mon, 07 Feb 2022 10:46:17 -0500 Original-Received: from [2001:470:142:3::e] (port=55230 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH6DX-0003Xe-NJ; Mon, 07 Feb 2022 10:46:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:From:References: to; bh=LAln8Rm4X3xuH6wcv/1FOSyvQymM/MAC6W0ja3Z5kH4=; b=l+HKYjViswU51jSYwZoymc fVu61hfKBV5vDwAVdzcy0lo0YWFYnFHzbT7kurofk2KBLGDCBMlPotiwpBBy8PYsanB5z5KYQ0tps iPSm3s/DMLzv5/ctmXcCM4mujOQ/0kjdpNX/uRDHmEK9yzblcMiNC++PP56L9cHzyCgYg9KV5bpCF xjxQbXN3CkKBWQ9SpPd88BhOPmHTzAfP7nPvP7+TUQPgjxZ6mk+fx2EEmaooVVIBVJrVq1pEoi5Dz k2oXcdJklPpL6YamA4BIUntDPwFdj7HqKbWvjIRYW5Z64wS4TFQQs4sCOSXu1+WkZ3HdRIGwx8thb hA8rK7a8ZU0g==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:47793) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nH6DO-000447-ME; Mon, 07 Feb 2022 10:46:14 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 3335E27C0054; Mon, 7 Feb 2022 10:46:06 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 07 Feb 2022 10:46:06 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrheehgdejkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenmh hishhsihhnghcuvffquchfihgvlhguucdlfedtmdenucfjughrpehffgfhufffjgfkgggt sehmtderredtredtnecuhfhrohhmpefvrghsshhilhhoucfjohhrnhcuoehtshguhhesgh hnuhdrohhrgheqnecuggftrfgrthhtvghrnhepvdefueefteehheeileehhfdtjeeftedv hfethffgteejgfdtudfhiedugfeufedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepthhhohhrnhdomhgvshhmthhprghuthhhphgvrhhsohhn rghlihhthidqkeeijeefkeejkeegqdeifeehvdelkedqthhsughhpeepghhnuhdrohhrgh esfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 7 Feb 2022 10:46:05 -0500 (EST) In-reply-to: <8735kuah78.fsf@gnu.org> X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:286054 Archived-At: --=-=-= Content-Type: text/plain Tassilo Horn writes: > Here's a patch As always, I've forgotten to attach the patch. So here it is. > which implements both showing the context in an overlay and in the > header-line in addition to the already pushed child-frame approach > (just set show-paren-context-when-offscreen to either 'child-frame, > 'overlay, or 'header-line for comparison). > > In the overlay and header-line cases, I replace newlines in the context > string with spaces so that the context always only takes one line. > (Note to self: probably that should be cut to window-width, too, so that > you don't get continuation lines which would cause the buffer text to > "bounce down and back up again".) > > The overlay approach has the problem that the context text isn't > outstanding visually. With the child-frame approach, one can customize > the child-frame-border face's :background to get a nice and outstanding > look. Is there a way to make the context text a bit more outstanding? > Since it's a buffer-substring, it's usually font-locked already and that > should be kept, of course. > > The header-line approach has the problem that the text "bounces" because > usually there is no header-line, so its toggled on and off again. But > at least, the context text is immediately distinguishable. > > So all in all, I still like the child-frame approach best but have no > problem with offering the other options as well. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Show-show-paren-context-in-overlay-or-header-line.patch >From e92a8d062cca54152bd816bdf88dad0bade87120 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Mon, 7 Feb 2022 15:05:14 +0100 Subject: [PATCH] Show show-paren context in overlay or header-line --- lisp/paren.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/lisp/paren.el b/lisp/paren.el index 6de4364b4f..e0a8d6fc24 100644 --- a/lisp/paren.el +++ b/lisp/paren.el @@ -368,6 +368,51 @@ show-paren--show-context-in-child-frame (add-hook 'post-command-hook #'show-paren--delete-context-child-frame)))) +(defvar-local show-paren--context-overlay nil) + +(defun show-paren--delete-context-overlay () + (when show-paren--context-overlay + (delete-overlay show-paren--context-overlay) + (setq show-paren--context-overlay nil)) + (remove-hook 'post-command-hook #'show-paren--delete-overlays + 'local)) + +(defun show-paren--show-context-in-overlay (text) + "Show TEXT in an overlay at the top-left of the current window." + ;; FIXME: This works pretty well but the overlay text is not + ;; outstanding at all. It's good that it's the font-locked string + ;; but it would be good if we could place a :box or :background face + ;; attribute, too. + (setq text (replace-regexp-in-string "\n" " " text)) + (show-paren--delete-context-overlay) + (let* ((beg (window-start)) + (end (save-excursion + (goto-char beg) + (line-end-position)))) + (setq show-paren--context-overlay (make-overlay beg end))) + (overlay-put show-paren--context-overlay 'display text) + (add-hook 'post-command-hook #'show-paren--delete-context-overlay + nil 'local)) + +(defvar-local show-paren--orig-header-line-format nil) + +(defun show-paren--restore-orig-header-line-format () + (setq header-line-format show-paren--orig-header-line-format) + (remove-hook 'post-command-hook + #'show-paren--restore-orig-header-line-format + 'local)) + +(defun show-paren--show-context-in-header-line (text) + "Show TEXT in the header-line." + ;; FIXME: This bounces the buffer one line down which is a bit + ;; annoying. Can we do anything about it? + (setq text (replace-regexp-in-string "\n" " " text)) + (setq show-paren--orig-header-line-format header-line-format) + (setq header-line-format text) + (add-hook 'post-command-hook + #'show-paren--restore-orig-header-line-format + nil 'local)) + (defun show-paren-function () "Highlight the parentheses until the next input arrives." (let ((data (and show-paren-mode (funcall show-paren-data-function)))) @@ -438,12 +483,21 @@ show-paren-function (let ((open-paren-line-string (blink-paren-open-paren-line-string openparen)) (message-log-max nil)) - (if (and (eq show-paren-context-when-offscreen - 'child-frame) - (display-graphic-p)) - (show-paren--show-context-in-child-frame - open-paren-line-string) - (minibuffer-message "Matches %s" open-paren-line-string))))) + (cond ((and (eq show-paren-context-when-offscreen + 'child-frame) + (display-graphic-p)) + (show-paren--show-context-in-child-frame + open-paren-line-string)) + ((eq show-paren-context-when-offscreen + 'overlay) + (show-paren--show-context-in-overlay + open-paren-line-string)) + ((eq show-paren-context-when-offscreen + 'header-line) + (show-paren--show-context-in-header-line + open-paren-line-string)) + (show-paren-context-when-offscreen + (minibuffer-message "Matches %s" open-paren-line-string)))))) ;; Always set the overlay face, since it varies. (overlay-put show-paren--overlay 'priority show-paren-priority) (overlay-put show-paren--overlay 'face face)))))) -- 2.35.1 --=-=-=--