Skip to content

Commit

Permalink
Always ark entire objects in composable-mark-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed May 19, 2016
1 parent 3397b35 commit 447969d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
@@ -1,6 +1,8 @@
# Changes

- master
- Mark commands marks from beginning to end when used inside
composable-mark-mode. For instance `C-SPC w` marks entire word
- Properly detect prefix arguments in Emacs >= 25.1
- Fix breakage of mark popping with C-u C-SPC
- Fix error when object mode entered trough composable-mark-mode for
Expand Down
38 changes: 20 additions & 18 deletions composable-mark.el
Expand Up @@ -26,18 +26,6 @@

;;; Code:

(defun composable-mark-line (arg)
"Mark ARG lines."
(interactive "p")
(beginning-of-line)
(push-mark
(save-excursion
(when (region-active-p)
(goto-char (mark)))
(forward-line arg)
(point))
nil t))

(defun composable-mark-join (arg)
"Mark the whitespace seperating lines.
Between the line above if ARG is negative otherwise below."
Expand All @@ -55,13 +43,21 @@ Between the line above if ARG is negative otherwise below."

(defun composable--mark-with-forward (forward arg)
"Mark a region based on a FORWARD movement and ARG.
The movement must move backwards with negative arguments."
(let* ((amount (if arg (prefix-numeric-value arg)
(if (< (mark) (point)) -1 1)))
(dir (/ amount (abs amount))))
(when (not (region-active-p))
The movement must mark backwards with negative arguments."
(let* ((amount (if arg
(prefix-numeric-value arg)
(if (< (mark) (point)) -1 1)))
(dir (/ amount (abs amount)))
(empty-sel (and (region-active-p) (= (mark) (point)))))
(when (or (not (region-active-p))
empty-sel)
(funcall forward dir)
(funcall forward (- dir)))
(funcall forward (- dir))
(when empty-sel
(goto-char
(funcall (if (< 0 amount) 'min 'max)
(mark)
(point)))))
(push-mark
(save-excursion
(when (region-active-p)
Expand All @@ -70,6 +66,12 @@ The movement must move backwards with negative arguments."
(point))
nil t)))

(defun composable-mark-line (arg)
"Mark ARG lines.
Supports negative argument and repeating."
(interactive "P")
(composable--mark-with-forward 'forward-line arg))

(defun composable-mark-word (arg)
"Mark ARG words.
Supports negative arguments and repeating."
Expand Down
6 changes: 6 additions & 0 deletions features/composable.feature
Expand Up @@ -153,6 +153,12 @@ Feature: composable
"""

Scenario: Mark word
When I insert "first second third"
And I place the cursor after "sec"
And I press "C-SPC w"
Then the region should be "second"

Scenario: Mark three words forward
When I insert "first second third fourth fifth"
And I place the cursor before "second"
Expand Down

0 comments on commit 447969d

Please sign in to comment.