aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--evil-commands.el9
-rw-r--r--evil-maps.el1
-rw-r--r--evil-tests.el12
3 files changed, 22 insertions, 0 deletions
diff --git a/evil-commands.el b/evil-commands.el
index f296b93..f75f685 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -235,6 +235,15 @@ move COUNT - 1 screen lines downward first."
-1
(/ (with-no-warnings (window-body-width)) 2)))))
+(evil-define-motion evil-percentage-of-line (count)
+ "Move the cursor to COUNT % of the width of the current line.
+If no COUNT is given, default to 50%."
+ :type exclusive
+ (let ((line-length (- (line-end-position)
+ (line-beginning-position)
+ (if evil-move-beyond-eol -1 0))))
+ (move-to-column (truncate (* line-length (/ (or count 50) 100.0))))))
+
(evil-define-motion evil-first-non-blank ()
"Move the cursor to the first non-blank character of the current line."
:type exclusive
diff --git a/evil-maps.el b/evil-maps.el
index 10ee826..de6d3d9 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -216,6 +216,7 @@
(define-key evil-motion-state-map "g^" 'evil-first-non-blank-of-visual-line)
(define-key evil-motion-state-map (vconcat "g" [home]) 'evil-first-non-blank-of-visual-line)
(define-key evil-motion-state-map "gm" 'evil-middle-of-visual-line)
+(define-key evil-motion-state-map "gM" 'evil-percentage-of-line)
(define-key evil-motion-state-map "go" 'evil-goto-char)
(define-key evil-motion-state-map "g$" 'evil-end-of-visual-line)
(define-key evil-motion-state-map (vconcat "g" [end]) 'evil-end-of-visual-line)
diff --git a/evil-tests.el b/evil-tests.el
index 609f7dd..28cde32 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -3346,6 +3346,18 @@ Below some empty line"
\[]
Below some empty line")))
+(ert-deftest evil-test-percentage-of-line ()
+ "Test `evil-percentage-of-line' motion"
+ :tags '(evil motion)
+ (evil-test-buffer
+ "[0]123456789"
+ ("gM")
+ "01234[5]6789"
+ ("10gM")
+ "0[1]23456789"
+ ("85gM")
+ "01234567[8]9"))
+
(ert-deftest evil-test-first-non-blank ()
"Test `evil-first-non-blank' motion"
:tags '(evil motion)