purcell / whole-line-or-region

In Emacs, operate on current line if no region is active
114 stars 12 forks source link

Incompatibility with smartparens-strict-mode #17

Open Gallipo opened 3 years ago

Gallipo commented 3 years ago

Hi, I love WLOR, unfortunately I also love smartparens-strict-mode which remaps 'kill-region' too. Since 'chaining' remaps is impossible they do not work together (and I wouldn't want the standard-kill-commands to be active in sp-strict). I try to simulate the WLOR-kind-of-behavior (but with the sp-kill-… functions) in sp-strict-mode with the code below, which works but isn't as sophisticated as WLOR especially when it comes to yanking.

Would it make sense to integrate something like this into WLOR?

(defun sp-kill-whole-line-or-region ()
  "kill region, or whole line with the sp-kill… functions"
  (interactive)
  (if (region-active-p)
      (sp-kill-region (region-beginning) (region-end))
    (sp-kill-whole-line))
  )
(define-key smartparens-strict-mode-map [remap kill-region] nil)
(define-key smartparens-strict-mode-map [remap kill-region] 'sp-kill-whole-line-or-region)
purcell commented 3 years ago

Yeah, I have the same issues in paredit-mode and haven't figured out the best way to tackle it.

I don't particularly think paredit- or smartparens-specific workarounds belong in whole-line-or-region itself though. Generally a "base" editing package like wlor shouldn't need to know about all sorts of other packages that might interact with it: this does however make me wonder if there's a common pattern that wlor could support, e.g. pairing together a user-defined kill-region command with a kill-whole-line function, so that instead of wlor recalculating the extended region, it would call the kill-whole-line function with an arg.

Honestly all of this stuff gets very complex very quickly, with lots of edge cases in the tests, so my main focus is getting all the edge cases right for the base functionality, and I haven't even managed that yet. :D

Gallipo commented 3 years ago

Yeah your right, this is a complex problem and not high priority.

dakra commented 3 years ago

I just happen to see this here now. I made a PR to smartparens to solve it a while ago. But as you can see in the discussion of https://github.com/Fuco1/smartparens/pull/1047 It didn't land in smartparens and it's easily fixed with defining your own function:

(defun whole-line-or-region-sp-kill-region (prefix)
  "Call `sp-kill-region' on region or PREFIX whole lines."
  (interactive "*p")
  (whole-line-or-region-wrap-beg-end 'sp-kill-region prefix))