1

When a function is called on a region, I want a visual indication of affected area (a blink for ex.). Say, I've written a function upcasing previous word, and after evaluation I immediately get the result (and that's good) but I also want region highlighted for a sec. How could it be implemented?

Also I even can't get the region remain highlighted after the evaluation. (setq mark-active t) doesn't seem to work at all. Mark is forced to deactivate after interactive function or what?

(defun upcase-previous-WORD ()
  (interactive)
  (set-mark (point))
  (forward-whitespace -1)
  (call-interactively
     'upcase-region)
  (exchange-point-and-mark)
  (setq mark-active t)))
Drew
  • 75,699
  • 9
  • 109
  • 225
A.King
  • 53
  • 3
  • I don't know if this could be of any help, but you could have a look at how library [volatile-highlights](https://github.com/k-talo/volatile-highlights.el) adds visual highlights to some operations such as `yank` and `delete-region` and see if some of the code there can help you. – Manuel Uberti Nov 08 '19 at 17:31
  • 3
    Possible duplicate of [Keep region activated upon completion of my command](https://emacs.stackexchange.com/questions/19275/keep-region-activated-upon-completion-of-my-command) – Drew Nov 08 '19 at 18:12

1 Answers1

1

[ I'll answer the second question. ]

Yes, Emacs resets mark-active to nil automatically after executing a command which modified the buffer (or more specifically, after executing a command which set deactivate-mark to a non-nil value). To prevent that you can use (setq deactivate-mark nil) in your function (after performing the buffer modification).

Stefan
  • 26,154
  • 3
  • 46
  • 84