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

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

[nongnu] elpa/evil-matchit 4fe67764e2 059/244: extra commands to delete/


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 4fe67764e2 059/244: extra commands to delete/select items v1.4.3
Date: Thu, 6 Jan 2022 02:58:49 -0500 (EST)

branch: elpa/evil-matchit
commit 4fe67764e263d691c607305b07ac749f4511f29d
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>

    extra commands to delete/select items v1.4.3
---
 README.org          | 14 ++++++-----
 evil-matchit-pkg.el |  2 +-
 evil-matchit.el     | 71 ++++++++++++++++++++++++++++++++++++++++++++---------
 3 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/README.org b/README.org
index 8be1466935..a03d12b2b9 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v1.4.2)
+* evil-matchit (v1.4.3)
 
 Vim [[http://www.vim.org/scripts/script.php?script_id=39][matchit.vim]] by 
Benji Fisher ported into Emacs.
 
@@ -56,12 +56,14 @@ Text object "%" is also created. It roughly equal the 
region when you press "%"
 
 Inner text object or outer object is the same thing in evil-matchit.
 
-Press "va%" or "vi%" to select line(s) wrapped by tags.
+Press "va%" or "vi%" to select line(s) wrapped by tags. `M-x 
evilmi-select-items` does the same thing.
 
-Press "da%" or "di%" to delete line(s) wrapped by tags.
+Press "da%" or "di%" to delete line(s) wrapped by tags. `M-x 
evilmi-delete-items` does the same thing.
 
 All commands support numeric argument like "3%", "5va%" or "9da%"
 
+Please note "3%"  will jump to a line *3 percentage down the file*. It's the 
default behavior in original evil-mode . You can `(setq 
evilmi-may-jump-by-percentage nil)` to turn off this feature. Then "3%" will 
*jump 3 times*.
+
 * Advanced tips
 ** Support more major modes
 Let's use html tag matching as an example.
@@ -76,15 +78,15 @@ Let's say you want a new major-mode "my-mode" to do the 
html tag matching. Easy.
 
 Further explanation: "evilmi-html-get-tag" and "evilmi-html-jump" are existing 
APIs which are defined in evil-matchit-html.el. The above line means that in 
my-mode, use "evilmi-html-get-tag" to find open/closed tag in current line and 
use "evilmi-html-jump" to jump to matched closed/open tag.
 
-** mixed languages in one html template file can be supported
-Say you embed python language in a html file. You can match both html tags and 
python statement by inserting below code into your ~/.emacs:
+** Mixed languages in one html template file is supported
+If you embed python language in a html file. You can match both html tags and 
python statement by inserting below code into your ~/.emacs:
 #+BEGIN_SRC elisp
 (plist-put evilmi-plugins web-mode
            '((evilmi-python-get-tag evilmi-python-jump)
              (evilmi-html-get-tag evilmi-html-jump)
              ))
 #+END_SRC
-** re-define keybinding
+** Re-define keybinding
 You can define your own key bindings instead using evil-matchit default key 
binding.
 
 All you need to do is to define function evilmi-customize-keybinding before 
turning on evil-mathcit-mode:
diff --git a/evil-matchit-pkg.el b/evil-matchit-pkg.el
index dd43af024e..73ad3fc7e2 100644
--- a/evil-matchit-pkg.el
+++ b/evil-matchit-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-matchit" "1.4.2"
+(define-package "evil-matchit" "1.4.3"
                 "Vim matchit ported into Emacs (requires EVIL)")
diff --git a/evil-matchit.el b/evil-matchit.el
index b4b230428b..373190aca6 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -4,7 +4,7 @@
 
 ;; Author: Chen Bin <chenbin.sh@gmail.com>
 ;; URL: http://github.com/redguardtoo/evil-matchit
-;; Version: 1.4.2
+;; Version: 1.4.3
 ;; Keywords: matchit vim evil
 ;; Package-Requires: ((evil "1.0.7"))
 ;;
@@ -40,8 +40,12 @@
 (require 'evil)
 
 (defvar evilmi-plugins '(emacs-lisp-mode
-                         ((evilmi-simple-get-tag evilmi-simple-jump))
-                         ))
+                         ((evilmi-simple-get-tag evilmi-simple-jump)))
+  "The table to define which algorithm to use and when to to jump items")
+
+(defvar evilmi-may-jump-by-percentage t
+  "Simulate evil-jump-item behaviour. For example, press 50% to jump to 50 
percentage in buffer.
+If this flag is nil, then 50 means jump 50 times.")
 
 (defun evilmi--operate-on-item (NUM &optional FUNC)
   (let ((plugin (plist-get evilmi-plugins major-mode))
@@ -72,8 +76,7 @@
       (setq where-to-jump-in-theory (point))
       )
     where-to-jump-in-theory
-    )
-  )
+    ))
 
 (defun evilmi--push-mark (rlt)
     (push-mark (nth 0 rlt) t t)
@@ -159,9 +162,7 @@
         '(ruby-mode))
   )
 
-(evil-define-text-object evilmi-text-object (&optional NUM begin end type)
-  "text object describing the region selected when you press % from 
evil-matchit"
-  :type line
+(defun evilmi--region-to-select-or-delete (NUM)
   (let (where-to-jump-in-theory b e)
     (save-excursion
       (setq where-to-jump-in-theory (evilmi--operate-on-item NUM 
'evilmi--push-mark))
@@ -173,22 +174,70 @@
         (setq b (line-beginning-position))
         ;; 1+ because the line feed
         ))
-    (evil-range b e 'line)))
+    (list b e)))
+
+(evil-define-text-object evilmi-text-object (&optional NUM begin end type)
+  "text object describing the region selected when you press % from 
evil-matchit"
+  :type line
+  (let (selected-region)
+    (setq selected-region (evilmi--region-to-select-or-delete NUM))
+    (evil-range (car selected-region) (cadr selected-region) 'line)))
 
 (define-key evil-inner-text-objects-map "%" 'evilmi-text-object)
 (define-key evil-outer-text-objects-map "%" 'evilmi-text-object)
 
+;;;###autoload
+(defun evilmi-select-items (&optional NUM)
+  "Select items/tags and the region between them"
+  (interactive "p")
+  (let (selected-region)
+    (setq selected-region (evilmi--region-to-select-or-delete NUM))
+    (when selected-region
+      (evilmi--push-mark selected-region)
+      (goto-char (cadr selected-region)))
+    ))
+
+;;;###autoload
+(defun evilmi-delete-items (&optional NUM)
+  "Delete items/tags and the region between them"
+  (interactive "p")
+  (let (selected-region)
+    (setq selected-region (evilmi--region-to-select-or-delete NUM))
+    ;; 1+ because the line feed
+    (kill-region (car selected-region) (1+ (cadr selected-region)))
+    ))
+
+;;;###autoload
+(defun evilmi-jump-to-percentage (NUM)
+  "Re-implementation of evil's similar functionality"
+  (interactive "P")
+  (let (dst)
+    (when (and NUM (> NUM 0))
+      (setq dst (let ((size (- (point-max) (point-min))))
+                  (+ (point-min)
+                     (if (> size 80000)
+                         (* NUM (/ size 100))
+                       (/ (* NUM size) 100)))))
+      (cond
+       ((< dst (point-min))
+        (setq dst (point-min)))
+       ((> dst (point-max))
+        (setq dst (point-max))))
+      (goto-char dst)
+      (back-to-indentation))))
+
 ;;;###autoload
 (defun evilmi-jump-items (&optional NUM)
   "jump between item/tag(s)"
   (interactive "P")
   (cond
-   (NUM (evil-jump-item NUM))
+   ((and evilmi-may-jump-by-percentage NUM)
+    (evilmi-jump-to-percentage NUM))
    (t (evilmi--operate-on-item NUM))
    ))
 
 ;;;###autoload
-(defun evilmi-version() (interactive) (message "1.4.2"))
+(defun evilmi-version() (interactive) (message "1.4.3"))
 
 ;;;###autoload
 (define-minor-mode evil-matchit-mode



reply via email to

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