1

I like transient-mark-mode and I like that it is activated by default. But there are a few specific buffers where I'd like to deactivate it. Unfortunately, that minor mode is either on or off globally, so you can't have it in some buffers and not in some others.

It seems that a possible workaround would be to void the highlighting face on a buffer local basis. What are the involved variables? Anybody has done this?

Or is there a better workaround?

  • I have successfully been using transient-mark-mode in a buffer-local manner for the past few years, but I cannot remember all of the reasons why I made those modifications. It may behoove you to specify an example of what it is that you are trying to achieve .... perhaps I would be able to remember more with a cup of coffee and a frame of reference ...; and/or, perhaps other forum participants may also be able to provide you with some solutions I am unaware of. – lawlist May 5 at 5:50
  • @lawlist: In a nutshell, I'd like to have transient-mark-mode activated in some buffers and not activated in some some other buffers, e.g., on for C & Emacs-Lisp buffers but not for Dired or shell-mode buffers. – phs May 5 at 6:16
  • I'd be curious to know what are the modes where you want it disabled and why. – Stefan May 6 at 13:15
  • @Stefan: Am ashamed to tell but here it is. I'm sometimes using legacy code for some dumb old in-house major-mode. And the legacy code does not properly deactive the mark after its searches and replaces, which I find visually annoying. Ironically, if I were feeling like debugging the old code, I would find transient-mark-mode a great help with spotting when and where the mark is messed up with. – phs May 7 at 6:42
  • @phs: There's no shame in using old code, obviously. Thanks for the explanation. – Stefan May 7 at 13:13
1

Barely tested, but try this:

(transient-mark-mode 0)

(define-minor-mode local-transient-mark-mode
  "Toggle `transient-mark-mode' (see which) for the current buffer."
  :variable transient-mark-mode)

(make-variable-buffer-local 'transient-mark-mode)

(add-hook 'emacs-lisp-mode-hook #'local-transient-mark-mode)
  • Great !!! And obvious in hindsight. I never thought that it was enough to change the status of transient-mark-mode and make it buffer-local. – phs May 7 at 6:34
  • It very much depends upon the implementation of the global mode in question, as global modes have a wide range of implementations. In this particular case, the transient-mark-mode command really only exists for the purpose of setting that variable, and everything else happens elsewhere based on the variable's value; so making the variable buffer-local does appear to do the trick. – phils May 7 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.