diff options
| author | Tom Dalziel <33435574+tomdl89@users.noreply.github.com> | 2022-01-04 17:11:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-04 17:11:07 +0100 |
| commit | b5c6950f65e2cde92bd978ec2bc98e67820d91a0 (patch) | |
| tree | 8e9e7c8177a2f8c12df55f5b24c1816e78152257 | |
| parent | 89153b8bd2daaa9c1bbdce9d7ab1f0c4ee24b8e2 (diff) | |
Add gM `evil-percentage-of-line` (#1562)
| -rw-r--r-- | evil-commands.el | 9 | ||||
| -rw-r--r-- | evil-maps.el | 1 | ||||
| -rw-r--r-- | evil-tests.el | 12 |
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) |
