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

surrounding lines region with empty lines #67

Closed
blaenk opened this issue Feb 5, 2016 · 6 comments
Closed

surrounding lines region with empty lines #67

blaenk opened this issue Feb 5, 2016 · 6 comments

Comments

@blaenk
Copy link

blaenk commented Feb 5, 2016

I would absolutely love to be able to do something like V-S-RET, that is, select some lines, press the surround operator and then give it an argument of RET so that it surrounds the lines with empty lines. I find myself doing this sometimes to space logically-grouped chunks of code. Doing this via the surround bindings feels the most natural way to do this, so I'm wondering if there's a way.

I tried doing it out of the box but it instead added little ^M markers, which I guess is essentially two lines, or something.

Before:

  (use-package evil-surround
    :config ;; point is here
    (global-evil-surround-mode 1))

After:

  (use-package evil-surround
    ^M
    :config
    ^M
    (global-evil-surround-mode 1))

Expected:

  (use-package evil-surround

    :config

    (global-evil-surround-mode 1))

So next I tried to add my own surround pair (btw ^M is the effect of C-v RET):

(push '(?^M . ("\n" . "\n")) evil-surround-pairs-alist)

But then I end up getting two lines instead of one, and the second one that appears on the bottom is indented, and the previously-following non-whitespace line is unindented.

Before:

  (use-package evil-surround
    :config ;; point is here
    (push '(?^M . ("\n" . "\n")) evil-surround-pairs-alist)
    (global-evil-surround-mode 1))

After V-S-RET:

  (use-package evil-surround


    :config

    ;; intended to here; the other empty lines are properly unindented. notice next is incorrectly unindented
(push '(?^M . ("\n" . "\n")) evil-surround-pairs-alist)
    (global-evil-surround-mode 1))

Perhaps this is outside of the scope of evil-surround. I would love it if I could use these bindings though. If this isn't possible via evil-surround, could I perhaps hook on my own function that does this to some evil-surround map so that I can trigger it when I press S and RET?

@blaenk
Copy link
Author

blaenk commented Feb 24, 2016

Any thoughts? I keep wishing I could do this 😄

@timcharper
Copy link
Collaborator

Try using an empty string for your surround pairs?

@blaenk
Copy link
Author

blaenk commented Feb 25, 2016

That takes care of the problem of it "inserting" two lines on each side. The problems that remain are:

  1. the empty line on the bottom of the surrounded text isn't actually empty; the original indentation of the line that got "shifted" down remains
  2. that line that got "shifted" down is now unindented

Before (intention is to surround the evil-surround-pairs-alist line with empty lines):

(use-package evil-surround
  :config
  (setq-default
   evil-surround-pairs-alist
   (cons '(?
 . ("" . "")) evil-surround-pairs-alist))
  (global-evil-surround-mode 1))

After:

(use-package evil-surround
  :config
  (setq-default

   evil-surround-pairs-alist
   ;; whitespace up to this point
(cons '(?
 . ("" . "")) evil-surround-pairs-alist))
  (global-evil-surround-mode 1))

In other words, the result is as if the point were placed in between the indentation and the first non-whitespace character of the line under the surrounded text, i.e. where the | appears here right before the (cons:

(use-package evil-surround
  :config
  (setq-default
   evil-surround-pairs-alist
   |(cons '(?
 . ("" . "")) evil-surround-pairs-alist))
  (global-evil-surround-mode 1))

Then it's as if one were to press RET so that (cons was now on the next line, unindented.

Perhaps this ability requires special casing?

@blaenk
Copy link
Author

blaenk commented Feb 25, 2016

I would take a shot at implementing it myself as its own separate function, but I'd love to be able to do it on the evil-surround map, so that I can do e.g. V-S-RET, i.e. bind RET on the evil-surround map. Would that be possible? Then I could take it from there (getting the selected region, etc.).

@blaenk
Copy link
Author

blaenk commented Feb 25, 2016

Yeah it seems to me like it's due to indentation logic, which is the correct thing to do in most cases, but perhaps not in this case.

@blaenk
Copy link
Author

blaenk commented Mar 22, 2016

Fixed by #73

@blaenk blaenk closed this as completed Mar 22, 2016
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