From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Is there a way to hightlight region permanently? Date: Sun, 2 Jul 2017 07:52:43 -0700 (PDT) Message-ID: <71d925e4-ba3c-47a3-8b54-b527cdd45c82@default> References: <87eftzrxwn.fsf@jane> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1499007204 4433 195.159.176.226 (2 Jul 2017 14:53:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Jul 2017 14:53:24 +0000 (UTC) To: Marcin Borkowski , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 02 16:53:20 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRgFP-0000ZZ-Um for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Jul 2017 16:53:16 +0200 Original-Received: from localhost ([::1]:58279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRgFT-0007rt-Gi for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Jul 2017 10:53:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRgF3-0007rn-0o for help-gnu-emacs@gnu.org; Sun, 02 Jul 2017 10:52:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRgEz-0003Lt-UB for help-gnu-emacs@gnu.org; Sun, 02 Jul 2017 10:52:53 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:25697) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dRgEz-0003JA-Jg for help-gnu-emacs@gnu.org; Sun, 02 Jul 2017 10:52:49 -0400 Original-Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v62Eqj2P013760 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Jul 2017 14:52:45 GMT Original-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v62EqjGf009006 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Jul 2017 14:52:45 GMT Original-Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v62EqhPb022125; Sun, 2 Jul 2017 14:52:44 GMT In-Reply-To: <87eftzrxwn.fsf@jane> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6770.5000 (x86)] X-Source-IP: userv0022.oracle.com [156.151.31.74] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 156.151.31.81 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:113633 Archived-At: > I'd like to have something like `highlight-regexp' and > `unhighlight-regexp', but for the current region. I.e., > something that stays highlighted after I move point > and/or mark, and whose highlighting I can easily turn > off when no longer needed. >=20 > Any hints? Or should I just code that myself? 1. You can easily do what you ask, using library `highlight.el'. https://www.emacswiki.org/emacs/HighlightLibrary https://www.emacswiki.org/emacs/download/highlight.el You say "permanently" in your Subject line, but it sounds like you just want to highlight the text in the region and have that highlighting persist during the current Emacs session, or until you remove it. For that, all you need is command `hlt-highlight-region', bound by default to `C-x X h r'. [All of the library commands are bound on prefix key `C-x X', the `h' is for "highlight" (`u' is for "unhighlight"), and the `r' is for "region". You can bind commands to keys individually or use a different prefix key.] There are lots of other, related commands, including, for example, `hlt-highlight-regexp-region' (`C-x X h x'). The single command `hlt-highlight' (`C-x X h h' - I bind it to `C-x C-y' also) gives you the behaviors of multiple commands all rolled into one, determined by a prefix arg: * No prefix arg - highlight all text in region/buffer * Plain prefix arg (`C-u') or zero prefix arg (`C-0'): UNhighlight all * Positive prefix arg (`C-1'): highlight regexp matches * Negative prefix arg (`C--'): UNhighlight regexp matches All of the highlighting and unhighlighting commands can use text property `face', `font-lock-face', or `mouse-face'. All of them can use an overlay property instead of, or in addition to, a text property. The default behavior is to use overlay highlighting. All of the commands let you choose whether the highlighting is controlled by font-lock or is independent of font-lock. You can highlight zones of text defined by their limits. You can act across multiple buffers: highlighting, unhighlighting, swapping one face for another, etc. You can copy and yank text properties from one bit of text to another. You can temporarily hide or show text that you have highlighted. If you did really want to save your highlighting permanently, i.e., have it persist between Emacs sessions, you can do that too. This bit of doc describes permanent/persistent highlighting: https://www.emacswiki.org/emacs/HighlightLibrary#PermanentHighlighting 2. As Stephen Berman suggested, a simple way to highlight text and have that highlighting stay put while you move point, is to use the secondary selection. Vanilla Emacs lets you use the secondary selection only using the mouse. That's probably one reason that few Emacs users use it or even know about it. You really need ways to create it (selecting text) and yank it using the keyboard. Library `second-sel.el' can help. https://emacswiki.org/emacs/SecondarySelection#second-sel.el https://www.emacswiki.org/emacs/download/second-sel.el There are lots of things you can do with the secondary selection, and there are lots of ways to create or move it. In particular, you can create it from the active region, using command `primary-to-secondary'. But the most versatile command, which I bind to `C-M-y', is this one: `secondary-yank|select|move|swap'. By default it yanks the secondary selection at point. With a prefix arg it interacts with the active region: Zero: Select secondary as region. > 0: Move secondary to region. < 0: Swap region and secondary.