unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* recommended techniques for "temporary highlighting"?
@ 2017-10-14  2:12 Miles Bader
  2017-10-14  6:58 ` Helmut Eller
  2017-10-14  7:23 ` Eli Zaretskii
  0 siblings, 2 replies; 3+ messages in thread
From: Miles Bader @ 2017-10-14  2:12 UTC (permalink / raw)
  To: Emacs-Devel

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: recommended techniques for "temporary highlighting"?
  2017-10-14  2:12 recommended techniques for "temporary highlighting"? Miles Bader
@ 2017-10-14  6:58 ` Helmut Eller
  2017-10-14  7:23 ` Eli Zaretskii
  1 sibling, 0 replies; 3+ messages in thread
From: Helmut Eller @ 2017-10-14  6:58 UTC (permalink / raw)
  To: emacs-devel

On Sat, Oct 14 2017, Miles Bader wrote:

> Any thoughts as to what the best way to do this sort of thing is?

I'd use technique (2) and clear the overloay in a timer, similar to
`pulse-momentary-highlight-region` does it.

Helmut




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: recommended techniques for "temporary highlighting"?
  2017-10-14  2:12 recommended techniques for "temporary highlighting"? Miles Bader
  2017-10-14  6:58 ` Helmut Eller
@ 2017-10-14  7:23 ` Eli Zaretskii
  1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2017-10-14  7:23 UTC (permalink / raw)
  To: Miles Bader; +Cc: emacs-devel

> From: Miles Bader <snogglethorpe@gmail.com>
> Date: Sat, 14 Oct 2017 11:12:37 +0900
> 
> What I'm wondering is:  What's the best way to do this sort of
> temporary highlighting?

Did you look at pulse.el?  We use it in Grep and in M-., for example.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-14  7:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-14  2:12 recommended techniques for "temporary highlighting"? Miles Bader
2017-10-14  6:58 ` Helmut Eller
2017-10-14  7:23 ` Eli Zaretskii

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).