emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil b5c6950f65: Add gM `evil-percentage-of-line` (#1562)


From: ELPA Syncer
Subject: [nongnu] elpa/evil b5c6950f65: Add gM `evil-percentage-of-line` (#1562)
Date: Tue, 4 Jan 2022 11:58:09 -0500 (EST)

branch: elpa/evil
commit b5c6950f65e2cde92bd978ec2bc98e67820d91a0
Author: Tom Dalziel <33435574+tomdl89@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Add gM `evil-percentage-of-line` (#1562)
---
 evil-commands.el |  9 +++++++++
 evil-maps.el     |  1 +
 evil-tests.el    | 12 ++++++++++++
 3 files changed, 22 insertions(+)

diff --git a/evil-commands.el b/evil-commands.el
index f296b93e97..f75f685388 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 10ee826b92..de6d3d9b0b 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 609f7dd85a..28cde32296 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]