unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Miles Bader <snogglethorpe@gmail.com>
To: Emacs-Devel <emacs-devel@gnu.org>
Subject: recommended techniques for "temporary highlighting"?
Date: Sat, 14 Oct 2017 11:12:37 +0900	[thread overview]
Message-ID: <CADCnXoZq6wDzZN_YpB=RMyhZSWFrvpQjaE5UUGBLM5rwbKrF4g@mail.gmail.com> (raw)

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.



             reply	other threads:[~2017-10-14  2:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-14  2:12 Miles Bader [this message]
2017-10-14  6:58 ` recommended techniques for "temporary highlighting"? Helmut Eller
2017-10-14  7:23 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADCnXoZq6wDzZN_YpB=RMyhZSWFrvpQjaE5UUGBLM5rwbKrF4g@mail.gmail.com' \
    --to=snogglethorpe@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).