[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit 62cef4f91a 077/244: replace evil-jump-items v
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit 62cef4f91a 077/244: replace evil-jump-items v2.0 |
Date: |
Thu, 6 Jan 2022 02:58:51 -0500 (EST) |
branch: elpa/evil-matchit
commit 62cef4f91a813a03d6d2df35fe4727757e94e530
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
replace evil-jump-items v2.0
- minimum dependency on evil-mode
- jump between ends of string
- string could be user defined
---
README.org | 21 ++++-
evil-matchit-javascript.el | 2 +-
evil-matchit-pkg.el | 2 +-
evil-matchit-simple.el | 11 +--
evil-matchit.el | 192 +++++++++++++++++++++++++++++++++++++++++----
pkg.sh | 2 +-
6 files changed, 205 insertions(+), 25 deletions(-)
diff --git a/README.org b/README.org
index 8d1cdefe79..86a34f9a26 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v1.5.2)
+* evil-matchit (v2.0)
Vim [[http://www.vim.org/scripts/script.php?script_id=39][matchit.vim]] by
Benji Fisher ported into Emacs.
@@ -53,7 +53,9 @@ Insert below code into your ~/.emacs:
Alternatively, you can enable evil-matchit-mode along a major mode by adding
`turn-on-evil-matchit-mode' to the mode hook.
* Usage
-Press "%" to jump inside between tags in evil-normal-mode. Please note
evil-matchit is smart enough to *detect the beginning of tag automatically*.
+Press "%" to jump inside between tag pair in normal mode or visual mode.
Please note evil-matchit is smart enough to *detect the beginning of tag
automatically*.
+
+Tag pair could be open/closed html tag, or character pair like "{}" "[]" "()",
or the single/double quote(s) at the two ends of the string.
Inner/outer text object "%" is also created. It roughly equal the region when
you press "%" from evil-matchit.
@@ -98,9 +100,22 @@ All you need to do is to define function
evilmi-customize-keybinding before turn
(global-evil-matchit-mode 1)
#+END_SRC
+** Jump between the two end of the "string"
+Please note the definition of "string" could be *customized* by user.
+
+For example, in C code, the comment is wrapped by "/". So we could regard C
comment as some kind of string.
+
+Here is the setup to jump between the two ends of the C comment:
+#+begin_src elisp
+(setq evilmi-quote-chars (string-to-list "'\"/"))
+#+end_src
+** Don't ignore the comments when jumping
+#+begin_src elisp
+(setq evilmi-ignore-comments nil)
+#+end_src
+
** Match case sensitive tags?
It's decided by the Emacs global variable "case-fold-search". You need not
care about it because the major mode will set this flag automatically.
-
* Developer guide
** Write Emacs Lisp to support new language
Simple. You only need define two functions and tell evil-matchit in which
major-mode they should be used.
diff --git a/evil-matchit-javascript.el b/evil-matchit-javascript.el
index 524e671ff3..e97687763b 100644
--- a/evil-matchit-javascript.el
+++ b/evil-matchit-javascript.el
@@ -74,7 +74,7 @@
(defun evilmi-javascript-jump (rlt NUM)
(let (cur-line)
(when rlt
- (evil-jump-item)
+ (evilmi--simple-jump)
(setq cur-line (buffer-substring-no-properties
(line-beginning-position)
diff --git a/evil-matchit-pkg.el b/evil-matchit-pkg.el
index bd1aa8c8a1..38024bc899 100644
--- a/evil-matchit-pkg.el
+++ b/evil-matchit-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-matchit" "1.5.2"
+(define-package "evil-matchit" "2.0"
"Vim matchit ported into Emacs (requires EVIL)")
diff --git a/evil-matchit-simple.el b/evil-matchit-simple.el
index 5da3e45c04..04940ee227 100644
--- a/evil-matchit-simple.el
+++ b/evil-matchit-simple.el
@@ -2,6 +2,7 @@
;; Copyright (C) 2014 Chen Bin <chenbin.sh@gmail.com>
+
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; This file is not part of GNU Emacs.
@@ -47,6 +48,7 @@
;;;###autoload
(defun evilmi-simple-get-tag ()
(let (p
+ ch
forward-line-num
rlt
(cur-line (buffer-substring-no-properties
@@ -54,10 +56,10 @@
(tag-chars (string-to-list "{[(}}])")))
;; Only handle open tag
+ (setq ch (evilmi--get-char-under-cursor))
(cond
;; In evil-visual-state, the (preceding-char) is actually the character
under cursor
- ((and (not (memq (following-char) tag-chars))
- (not (memq (preceding-char) tag-chars)))
+ ((not (memq ch tag-chars))
(if (setq forward-line-num (evilmi--simple-find-open-brace cur-line))
(when forward-line-num
(setq p (line-beginning-position))
@@ -67,7 +69,7 @@
(setq rlt (list p))
)))
(t
- ;; use evil's own evil-jump-item
+ ;; use evil's own evilmi--simple-jump
(setq rlt (list (point)))))
rlt))
@@ -75,8 +77,7 @@
(defun evilmi-simple-jump (rlt NUM)
(let (cur-line)
(when rlt
- (evil-jump-item)
-
+ (evilmi--simple-jump)
(setq cur-line (buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))
diff --git a/evil-matchit.el b/evil-matchit.el
index 480b650387..d436ace94f 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -1,10 +1,10 @@
;;; evil-matchit.el --- Vim matchit ported to Evil
-;; Copyright (C) 2014 Chen Bin
+;; Copyright (C) 2014,2015 Chen Bin
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-matchit
-;; Version: 1.5.2
+;; Version: 2.0
;; Keywords: matchit vim evil
;; Package-Requires: ((evil "1.0.7"))
;;
@@ -42,12 +42,177 @@
(defvar evilmi-plugins '(emacs-lisp-mode
((evilmi-simple-get-tag evilmi-simple-jump)))
- "The table to define which algorithm to use and when to to jump items")
+ "The table to define which algorithm to use and when 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.")
+
+(defvar evilmi-ignore-comments t "Ignore comments when mathing")
+
+(defvar evilmi-forward-chars (string-to-list "[{("))
+(defvar evilmi-backward-chars (string-to-list "]})"))
+(defvar evilmi-quote-chars (string-to-list "'\"/"))
+(defvar evilmi-debug nil)
+
+(defun evilmi--get-char-at-position (pos)
+ (let (ch)
+ ;; evil load
+ (setq ch (char-after pos))
+ (if evilmi-debug (message "evilmi-debug called. Return: %s" (string ch)))
+ ch))
+
+(defun evilmi--get-char-under-cursor ()
+ "Return: (previous-character current-character position)"
+ (let (ch p)
+ (cond
+ ;; evil load
+ ((eq evil-state 'visual)
+ ;; (preceding-char) (following-char) are written in C
+ (setq ch (preceding-char))
+ (setq p (- (point) 1)))
+ (t
+ (setq ch (following-char))
+ (setq p (point))))
+ (if evilmi-debug (message "evilmi--get-char-under-cursor called. Return:
(%d %s)" ch p))
+ (list ch p)))
+
+(defun evilmi--is-jump-forward ()
+ "Return: (forward-direction font-face-under-cursor character-under-cursor)
+If font-face-under-cursor is NOT nil, the quoted string is being processed"
+ (let (tmp
+ p
+ ff
+ ch
+ rlt)
+ (setq tmp (evilmi--get-char-under-cursor))
+ (setq ch (car tmp))
+ (setq p (cadr tmp))
+ (cond
+ ((memq ch evilmi-forward-chars)
+ (setq rlt t))
+ ((memq ch evilmi-backward-chars)
+ (setq rlt nil))
+ ((memq ch evilmi-quote-chars)
+ (setq ff (get-text-property p 'face))
+ (setq rlt (eq ff (get-text-property (+ 1 p) 'face))))
+ (t (setq rlt t)))
+
+ (if evilmi-debug (message "evilmi--is-jump-forward called. Return: (%s %s
%s)"
+ rlt ff (string ch)))
+
+ (list rlt ff ch)))
+
+(defun evilmi--scan-sexps (is-forward)
+ (let (rlt
+ start-pos
+ (arg (if is-forward 1 -1)))
+ (cond
+ ((eq evil-state 'visual)
+ (setq start-pos (if is-forward (- (point) 1)
+ (point))))
+ (t
+ ;; normal state and other state
+ (setq start-pos (if is-forward (point) (+ 1 (point))))
+ ))
+ (setq rlt (scan-sexps start-pos arg))
+ (if evilmi-debug (message "evilmi--scan-sexps called. Return: %s" rlt))
+ rlt))
+
+(defun evilmi--adjust-quote-jumpto (is-forward pos)
+ (let (rlt)
+ (if (eq evil-state 'visual)
+ (setq rlt (if is-forward (- pos 1) pos (+ 1 pos)))
+ (setq rlt (if is-forward pos (+ 1 pos))))
+ (if evilmi-debug (message "evilmi--adjust-quote-jumpto called. Return: %s"
rlt))
+ rlt))
+
+(defun evilmi--above-the-other-quote-char (ch pos ff delta)
+ (and (= ch (evilmi--get-char-at-position (- pos delta)))
+ (not (eq ff (get-text-property pos 'face)))))
+
+(defun evilmi--find-the-other-quote-char (ff is-forward ch)
+"The end character under cursor has different font-face from ff"
+ (let (rlt
+ pos
+ (got nil)
+ (delta (if is-forward 1 -1))
+ (end (if is-forward (point-max) (point-min))))
+ (setq pos (+ delta (point)))
+ (while (not got)
+ (if (or (= pos end)
+ (evilmi--above-the-other-quote-char ch pos ff delta))
+ (progn
+ (setq rlt (evilmi--adjust-quote-jumpto is-forward pos))
+ (setq got t))
+ (setq pos (+ delta pos))))
+ (if evilmi-debug (message "evilmi--find-the-other-quote-char called
Return: %s" rlt))
+ rlt))
+
+(defun evilmi--adjust-jumpto (is-forward rlt)
+ (cond
+ ((eq evil-state 'visual)
+ (if is-forward (setq rlt (+ rlt 1)))
+ )
+ (t
+ (if is-forward (setq rlt (- rlt 1)))))
+ (if evilmi-debug (message "evilmi--adjust-jumpto called. Return: %s" rlt))
+ rlt)
+
+;; @see
http://emacs.stackexchange.com/questions/13222/a-elisp-function-to-jump-between-matched-pair
+(defun evilmi--find-position-to-jump (ff is-forward ch)
+ "Non-nil ff means jumping between quotes"
+ (let (rlt)
+ (if ff (setq rlt (evilmi--find-the-other-quote-char ff is-forward ch))
+ (setq rlt (evilmi--scan-sexps is-forward)))
+ (setq rlt (evilmi--adjust-jumpto is-forward rlt))
+ (if evilmi-debug (message "evilmi--find-position-to-jump called. Return:
%s" rlt))
+ rlt))
+
+(defun evilmi--tweak-selected-region-finally (ff jump-forward)
+ (if (eq evil-state 'visual)
+ (cond
+ (jump-forward
+ ;; if ff is non-nil, I control the jump flow from character level,
+ ;; so hack to workaround scan-sexps is NOT necessary
+ (unless ff
+ (evil-backward-char)))
+ (t
+ (exchange-point-and-mark)
+ (evil-forward-char)
+ (exchange-point-and-mark)))
+ ))
+
+(defun evilmi--simple-jump ()
+ "Alternative for evil-jump-item"
+ ;; parse-sexp-ignore-comments is used
+ (interactive)
+ (let ((old-flag parse-sexp-ignore-comments)
+ tmp
+ ch
+ jumpto
+ ff
+ jump-forward)
+ (setq tmp (evilmi--is-jump-forward))
+ (setq jump-forward (car tmp))
+ ;; if ff is not nil, it's jump between quotes
+ ;; so we should not use (scan-sexps)
+ (setq ff (nth 1 tmp))
+ (setq ch (nth 2 tmp))
+
+ (unless evilmi-ignore-comments
+ (setq parse-sexp-ignore-comments nil))
+
+ ;; need pass the char
+ (setq jumpto (evilmi--find-position-to-jump ff jump-forward ch))
+ (goto-char jumpto)
+ (evilmi--tweak-selected-region-finally ff jump-forward)
+
+ (unless evilmi-ignore-comments
+ (setq parse-sexp-ignore-comments old-flag))
+ ))
+
(defun evilmi--operate-on-item (NUM &optional FUNC)
(let ((plugin (plist-get evilmi-plugins major-mode))
rlt
@@ -68,20 +233,18 @@ If this flag is nil, then 50 means jump 50 times.")
;; jump only once if the jump is successful
(setq jumped t)
))
- plugin
- ))
+ plugin))
(when (not jumped)
(if FUNC (funcall FUNC (list (point))))
- (evil-jump-item)
- (setq where-to-jump-in-theory (point))
- )
- where-to-jump-in-theory
- ))
+ (evilmi--simple-jump)
+ (setq where-to-jump-in-theory (point)))
+
+ (if evilmi-debug (message "evilmi--operate-on-item called. Return: %s"
where-to-jump-in-theory))
+ where-to-jump-in-theory))
(defun evilmi--push-mark (rlt)
- (push-mark (nth 0 rlt) t t)
- )
+ (push-mark (nth 0 rlt) t t))
(defun evilmi-init-plugins ()
(interactive)
@@ -202,6 +365,7 @@ If this flag is nil, then 50 means jump 50 times.")
(forward-line -1)
(setq e (line-end-position)))
)
+ (if evilmi-debug (message "evilmi--region-to-select-or-delete called.
Return: %s" (list b e)))
(list b e)))
(evil-define-text-object evilmi-inner-text-object (&optional NUM begin end
type)
@@ -263,7 +427,7 @@ If this flag is nil, then 50 means jump 50 times.")
;;;###autoload
(defun evilmi-jump-items (&optional NUM)
- "jump between item/tag(s)"
+ "Jump between item/tag(s)"
(interactive "P")
(cond
((and evilmi-may-jump-by-percentage NUM)
@@ -272,7 +436,7 @@ If this flag is nil, then 50 means jump 50 times.")
))
;;;###autoload
-(defun evilmi-version() (interactive) (message "1.5.2"))
+(defun evilmi-version() (interactive) (message "2.0"))
;;;###autoload
(define-minor-mode evil-matchit-mode
diff --git a/pkg.sh b/pkg.sh
index cbc54875f7..524e0a8f55 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-pkg=evil-matchit-1.5.2
+pkg=evil-matchit-2.0
mkdir $pkg
cp README.org $pkg
cp *.el $pkg
- [nongnu] elpa/evil-matchit 8123eef094 146/244: Merge pull request #88 from Khady/master, (continued)
- [nongnu] elpa/evil-matchit 8123eef094 146/244: Merge pull request #88 from Khady/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 3f49ee9d17 140/244: improve ocaml, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 8d6bd9187d 154/244: [chen] update doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 2143844e2b 170/244: support js2-jsx-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit e941c695f3 173/244: Add [ and { as well., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit c04f8f480c 164/244: Match Ruby's begin also when it's not on the beginning of the line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d779aedaf1 195/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit dead63c7d0 194/244: add unit test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 80dc731ab7 237/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 0be04f960f 049/244: use text objects v1.3.2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 62cef4f91a 077/244: replace evil-jump-items v2.0,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 6390e9e06c 216/244: Silence byte-compiler, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ae8fddea39 207/244: clean code, tdd for markdown, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 0fd65c463b 226/244: clean code&doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ceec6a63b0 236/244: better algorithm to match bracket/brace in javascript, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 8c4f516265 238/244: Support matlab-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 82c80786e5 240/244: jump between merge conflict markers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 5c43939d01 212/244: Merge pull request #126 from neojski/more-ocaml-tests, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit cdb9b90381 229/244: extra json support, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d005e0465e 223/244: Merge pull request #130 from nbfalcon/bugfix/evilmi-sdk-simple-jump-whitespace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ce90eae4bd 243/244: typo, ELPA Syncer, 2022/01/06