jrblevin / markdown-mode

Emacs Markdown Mode
http://jblevins.org/projects/markdown-mode/
GNU General Public License v3.0
875 stars 160 forks source link

Add option markdown-need-active-region #812

Closed snan closed 7 months ago

snan commented 8 months ago

This has been driving me crazy since I got used to working on just normal regions the old-fashioned way.

syohex commented 7 months ago

I understand your opinion. However I think this is not a natural emacs way and no one uses this option except you. Please override use-region-p or region-active-p by yourself as below. You could control behaviors other than markdown-mode by this way.

(defun use-region-p ()
  (and (or (bound-and-true-p markdown-mode) (region-active-p)) ;; customize as you like
       (or (> (region-end) (region-beginning))
           (and use-empty-active-region
                (not (eq (car-safe last-input-event) 'down-mouse-1))
        (not (mouse-movement-p last-input-event))))))

;; or
(defun region-active-p ()
  (and mark-active
       (progn (cl-assert (mark)) t)))
snan commented 7 months ago

Setting mark with C-SPC, moving the pointer to operate the region, and then doing something in the region is not a natural Emacs way?! But that's how every other mode works. comment-region, rot13-region, eval-region, shell-command-on-region, the only mode that does not work this way is markdown-mode and it used to work that way in the past.

snan commented 7 months ago

The reason markdown-mode got its new unusual behavior was so that the same commands would work for word-at-point and for the region itself. That's the benefit of doing it the "active regions only" way. For me personally that benefit is cool but definitively not worth it.

That's why I made it a setting. I don't even know how you are using it as is, do you all have transient mark on or what?

snan commented 7 months ago

Some packages like vertico have this (or (use-region-p) (not transient-mark-mode)), that's maybe a better idea than a new option.

trentbuck commented 7 months ago

A bit of context:

AIUI use-region-p works well iff the user has transient-mark-mode enabled. It was disabled by default until GNU Emacs 23 (about 16 years ago). Having (transient-mark-mode -1) is not so much "unnatural" as "traditional" -- or perhaps "legacy" ;-) I don't know how reasonable it is to put (defun use-region-p nil t) next to (transient-mark-mode -1).

https://www.gnu.org/software/emacs/manual/html_node/emacs/Disabled-Transient-Mark.html https://git.savannah.gnu.org/cgit/emacs.git/tree/etc/NEWS.23#n1013