Skip to content

Commit

Permalink
Handle longlines mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
rejeep committed Apr 12, 2013
1 parent a87ed14 commit 6d1584f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
30 changes: 20 additions & 10 deletions drag-stuff.el
Expand Up @@ -85,23 +85,33 @@
(list drag-stuff-modifier))))
(vector (append mod (list key)))))

(defmacro drag-stuff--execute (&rest body)
"Execute BODY without conflicting modes."
`(let ((auto-fill-function nil)
(electric-indent-mode nil)
(longlines-mode-active
(and (boundp 'longlines-mode) longlines-mode)))
(when longlines-mode-active
(longlines-mode -1))
,@body
(when longlines-mode-active
(longlines-mode 1))))

(defun drag-stuff-up (arg)
"Drag stuff ARG lines up."
(interactive "p")
(let ((auto-fill-function nil)
(electric-indent-mode nil))
(if mark-active
(drag-stuff-lines-up (- arg))
(drag-stuff-line-up (- arg)))))
(drag-stuff--execute
(if mark-active
(drag-stuff-lines-up (- arg))
(drag-stuff-line-up (- arg)))))

(defun drag-stuff-down (arg)
"Drag stuff ARG lines down."
(interactive "p")
(let ((auto-fill-function nil)
(electric-indent-mode nil))
(if mark-active
(drag-stuff-lines-down arg)
(drag-stuff-line-down arg))))
(drag-stuff--execute
(if mark-active
(drag-stuff-lines-down arg)
(drag-stuff-line-down arg))))

(defun drag-stuff-right (arg)
"Drag stuff ARG lines to the right."
Expand Down
46 changes: 46 additions & 0 deletions features/conflicting-modes.feature
Expand Up @@ -47,3 +47,49 @@ Feature: Drag Stuff
| direction | line |
| down | 2 |
| up | 3 |

Scenario: Longlines mode down
Given I insert:
"""
Move me down please
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tristique sollicitudin massa, ut porta diam pellentesque et. Sed porttitor tempor egestas. Morbi accumsan quam sed elit auctor nec interdum mi tincidunt.
"""
And I turn on drag-stuff
And I turn on longlines-mode
And I drag line "1" down
Then I should see:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tristique
sollicitudin massa, ut porta diam pellentesque et. Sed porttitor
tempor egestas. Morbi accumsan quam sed elit auctor nec interdum mi
tincidunt.
Move me down please
"""

Scenario: Longlines mode up
Given I insert:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tristique sollicitudin massa, ut porta diam pellentesque et. Sed porttitor tempor egestas. Morbi accumsan quam sed elit auctor nec interdum mi tincidunt.
Move me down please
"""
And I turn on drag-stuff
And I turn on longlines-mode
And I drag line "5" up
Then I should see:
"""
Move me down please
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tristique
sollicitudin massa, ut porta diam pellentesque et. Sed porttitor
tempor egestas. Morbi accumsan quam sed elit auctor nec interdum mi
tincidunt.
"""

Scenario: Do not activate longlines if not previously active
Given I insert:
"""
Lorem
Ipsum
"""
And I turn on drag-stuff
And I drag line "1" down
Then longlines-mode should not be active
1 change: 1 addition & 0 deletions features/support/env.el
Expand Up @@ -29,6 +29,7 @@

(auto-fill-mode -1)
(electric-indent-mode -1)
(longlines-mode -1)

;; Remove all bindings
(dolist (direction '(up down left right))
Expand Down

4 comments on commit 6d1584f

@swsnr
Copy link

@swsnr swsnr commented on 6d1584f Apr 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you care to also add support for visual-lines-mode? longlines-mode is obsolete in Emacs trunk.

@rejeep
Copy link
Owner Author

@rejeep rejeep commented on 6d1584f Apr 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work ok in with visual-line-mode enabled. No?

@swsnr
Copy link

@swsnr swsnr commented on 6d1584f Apr 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't try it honestly. I just saw this changeset, and wondered whether visual-line-mode would need explicit support, too. If it doesn't, I am just fine :)

@rejeep
Copy link
Owner Author

@rejeep rejeep commented on 6d1584f Apr 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked fine for some reason.. :)

Please sign in to comment.