From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Miles Bader Newsgroups: gmane.emacs.devel Subject: recommended techniques for "temporary highlighting"? Date: Sat, 14 Oct 2017 11:12:37 +0900 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1507962901 28344 195.159.176.226 (14 Oct 2017 06:35:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 14 Oct 2017 06:35:01 +0000 (UTC) To: Emacs-Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 14 08:34:54 2017 Return-path: Envelope-to: ged-emacs-devel@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 1e3G29-0006Fz-IX for ged-emacs-devel@m.gmane.org; Sat, 14 Oct 2017 08:34:53 +0200 Original-Received: from localhost ([::1]:52966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3G2G-0002FB-NY for ged-emacs-devel@m.gmane.org; Sat, 14 Oct 2017 02:35:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3Bx3-00063q-FD for emacs-devel@gnu.org; Fri, 13 Oct 2017 22:13:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3Bx2-0002gw-GW for emacs-devel@gnu.org; Fri, 13 Oct 2017 22:13:21 -0400 Original-Received: from mail-ua0-x230.google.com ([2607:f8b0:400c:c08::230]:56848) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e3Bx2-0002gN-Bc for emacs-devel@gnu.org; Fri, 13 Oct 2017 22:13:20 -0400 Original-Received: by mail-ua0-x230.google.com with SMTP id n22so6476227uaj.13 for ; Fri, 13 Oct 2017 19:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=iuCAchDqOgt11eP1H1v2iVaVORE/7PVfSOelWa4YXNs=; b=XQ9HApP1X5s2WVYdkqnLPXm8eruyo2Y5PCRdRTNksfodq66XSyFEbh+MBrY44YkUMx GRk3LteIKq5FpjkzA6NMkVktm7Xqvnou/IOutA0CRZJFQC9Irwo024N2Fvu/fw2RqOJr e9Z5t5XwQL+c7DppY6rVaZO0ifBXNjTOsLmWvKRlIPgarwABngver2VXhjzdZmYcdMHz lr7XdgdL0WNHVohYnj7BeoiwNime4eeF9a92oJddxEDEHcu08IVDspfAyibjBmtoyNVy P6Arywx+zTqcKNF162IoWgG1Hc6vxFjUNBMc1vz86h5buAW+QIzgM1SHfyJ41gPLCVfj EwLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=iuCAchDqOgt11eP1H1v2iVaVORE/7PVfSOelWa4YXNs=; b=IKvoJOs7SDXvq2yX47ldHAiPsw0y0u7CfhzPYg7Rwc6kYDWKn/hgPnazBFom11Xyh5 bWBhweqWyGFCU2+jR4c/PaeOpO+qgX3haepX8g+joDvPbLZkJLwTIjfKXGCE6gEJk7bI PZObrRChrMVM9w14g3xMDuOqm+u5AiVehKyp9ht3ZB6Bdw4pwxZlNp9iHbF72MHtMIp9 6Mw4Sogkk/Bg2rKflGnfGJEiGlh1wrPmEglfUDqkDPR8A4fDo7wHbp5oy4++OTDA/HzN FK1dGouChjDtzapk2eTGwHusoLTkCvHX7MALi52/OVOFjtgaAKh8AfY+QIM/xNA0uAyB L3Ew== X-Gm-Message-State: AMCzsaVk0L9Efn4fj7M3EIFZJL6U78uKZXdZH0p1KDjUAQ6Dlt0J6bSw 4TYL8S17zTF8DNu+b9u1mHYFr9jU1mA+dr1GL+lj/EF+ X-Google-Smtp-Source: AOwi7QAHhemmR3EcDirLFOf8mOLapbS6ezKKIwAmzXtB9IX2L4a6sSlREmBVPyRBfAE3CAou1zoaYRT+BJB3NBfdNvQ= X-Received: by 10.176.71.78 with SMTP id i14mr2798053uac.13.1507947198214; Fri, 13 Oct 2017 19:13:18 -0700 (PDT) Original-Received: by 10.176.6.104 with HTTP; Fri, 13 Oct 2017 19:12:37 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400c:c08::230 X-Mailman-Approved-At: Sat, 14 Oct 2017 02:34:22 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:219477 Archived-At: Hi all, I wrote some code for dictionary lookup that looks up the maximal Chinese word/phrase following point, displays the definition, and moves point past the term found. Chinese has no word boundaries, so I found it very useful to highlight the actual word looked up to make it clear to the user exactly what text was used. What I'm wondering is: What's the best way to do this sort of temporary highlighting? I've tried several different methods far: (1) Setting a temporary active region: ;; [This code copied from `handle-shift-selection' in Emacs ;; simple.el; maybe a function to this should be added?] (unless (and mark-active (eq (car-safe transient-mark-mode) 'only)) (setq-local transient-mark-mode (cons 'only (unless (eq transient-mark-mode 'lambda) transient-mark-mode)))) ;; The documentation warns against using set-mark directly, but ;; push-mark seems to have other weird side-effects: in particular, ;; it suppresses the above call to forward-char...(???) (set-mark start-pos) ;; Display the returned dictionary entry. (message "%s" definition))) (2) Using an explicit overlay (`cedict-lookup-term-highlight-overlay' below) and deleting it after 'sit-for': (move-overlay cedict-lookup-term-highlight-overlay start-pos longest-pos (current-buffer)) ;; Display the returned dictionary entry. (message "%s" definition) (sit-for 5) (delete-overlay cedict-lookup-term-highlight-overlay)) Technique (1) made me uncomfortable because it affects the region when the user may well not want that, and seems to be using internal mechanism it probably shouldn't be using. Technique (2) is maybe better, but the practice of nominally handing control back to the user while actually sitting inside sit-for feels a little dodgy to me. I'd kinda rather the command be done when it looks like it's done, with the highlight state just sort of disappearing automagically as happens with (1). Any thoughts as to what the best way to do this sort of thing is? Thanks, -miles -- Cat is power. Cat is peace.