Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make C-SPC SPC start a er/expand-region #3

Open
mattiasb opened this issue Sep 4, 2015 · 6 comments
Open

Make C-SPC SPC start a er/expand-region #3

mattiasb opened this issue Sep 4, 2015 · 6 comments

Comments

@mattiasb
Copy link

mattiasb commented Sep 4, 2015

Hi!

I have a little feature request for you. I'd like to have C-SPC SPC (with no mark set) trigger er/expand-region in addition to the current behaviour of C-SPC C-SPC with the marked region on a single line.

The reason I want this is that with er/expand-region you enter a mode (of sorts) that lets you continually hit SPC to enlarge the marked region. It would feel a lot more natural to just have to hit C-SPC SPC SPC SPC to enlarge it three times instead of the current C-SPC C-SPC SPC SPC.

The current effect of C-SPC SPC (with no mark) is basically just a SPACE character so this shouldn't interfere with anyone's regular work flow.

What do you think?

Finally I'd like to say that it's a great package you've made. I've tried it out for a little while now and really love it, it makes the use of expand-region and multiple-cursors feel much more accessible.

@glucas
Copy link

glucas commented Dec 9, 2016

Here's a diff that seems to work: when there is no region, set the mark and then set a temporary map with SPC bound to expand-region.

+++ #<buffer smart-region.el>
@@ -70,7 +70,13 @@
    ;;region not exist
    ((not (region-active-p))
     (setq this-command 'set-mark-command)
-    (call-interactively 'set-mark-command))
+    (call-interactively 'set-mark-command)
+    (er/set-temporary-overlay-map
+     (let ((map (make-sparse-keymap)))
+       (define-key map (kbd "<SPC>") 'er/expand-region)
+       map)
+       t)) 
+
    ;;region exist & single line
    ((= (line-number-at-pos) (line-number-at-pos (mark)))
     ;;(setq this-command 'er/expand-region)

@mattiasb
Copy link
Author

Awesome! I will test this as soon as I get the time! :)

@mattiasb
Copy link
Author

Tried this out now, much later (sorry for that).

Unfortunately there seems to be a bug where if you expand the region and press C-g to abort C-SPC no longer sets the mark. If you try to set the mark with C-SPC one- or two times then it starts working again.

My guess is that the temporary overlay keymap should be disabled when expand-region is aborted but isn't?

@glucas
Copy link

glucas commented Mar 18, 2017

I think this is actually an issue with expand-region: see https://github.com/magnars/expand-region.el/issues/220. There is a patch submitted but it has not been merged yet.

From the discussion on that issue, you can disable shift-select-mode as a workaround.

@glucas
Copy link

glucas commented Mar 18, 2017

One minor tweak (not related to the issue mentioned above):

-    (call-interactively 'set-mark-command))
+    (call-interactively 'set-mark-command)
+    (set-transient-map
+     (let ((map (make-sparse-keymap)))
+       (define-key map (kbd "<SPC>") 'er/expand-region)
+       map))) 

We should probably use set-transient-map because set-temporary-overlay-map is marked obsolete since Emacs 24.4. Also we can drop the t argument to keep the transient map active, because expand-region will manage its own transient map once activated.

@mattiasb
Copy link
Author

Ah, disabling shift-select-mode worked fine, thanks! Weird that I didn't experience this before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants