[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit de6ce21e1e 106/244: jump in comment
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit de6ce21e1e 106/244: jump in comment |
Date: |
Thu, 6 Jan 2022 02:58:53 -0500 (EST) |
branch: elpa/evil-matchit
commit de6ce21e1e24b7a0370ca3a6ce83b529f772c8db
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
jump in comment
---
README.org | 19 +++++-------
evil-matchit-pkg.el | 2 +-
evil-matchit-simple.el | 62 ++++++++++++++++---------------------
evil-matchit.el | 83 ++++++++++++++++++++++++++++++++++++--------------
pkg.sh | 2 +-
5 files changed, 97 insertions(+), 71 deletions(-)
diff --git a/README.org b/README.org
index 81fadb6999..e18014dd44 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v2.1.3)
+* evil-matchit (v2.1.4)
[[http://melpa.org/#/evil-matchit][file:http://melpa.org/packages/evil-matchit-badge.svg]]
[[http://stable.melpa.org/#/evil-matchit][file:http://stable.melpa.org/packages/evil-matchit-badge.svg]]
@@ -150,11 +150,6 @@ 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
@@ -227,13 +222,15 @@ The forth *optional* column defines the relationship
between open and close tags
;;;###autoload
(defun evilmi-script-get-tag ()
- (evilmi-sdk-get-tag evilmi-script-match-tags
evilmi-sdk-extract-keyword-howtos)
- )
+ (evilmi-sdk-get-tag evilmi-script-match-tags
+ evilmi-sdk-extract-keyword-howtos))
;;;###autoload
-(defun evilmi-script-jump (rlt NUM)
- (evilmi-sdk-jump rlt NUM evilmi-script-match-tags
evilmi-sdk-extract-keyword-howtos)
- )
+(defun evilmi-script-jump (rlt num)
+ (evilmi-sdk-jump rlt
+ num
+ evilmi-script-match-tags
+ evilmi-sdk-extract-keyword-howtos))
(provide 'evil-matchit-script)
#+END_SRC
diff --git a/evil-matchit-pkg.el b/evil-matchit-pkg.el
index 85b8084606..8f1268badd 100644
--- a/evil-matchit-pkg.el
+++ b/evil-matchit-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-matchit" "2.1.3"
+(define-package "evil-matchit" "2.1.4"
"Vim matchit ported into Emacs (requires EVIL)")
diff --git a/evil-matchit-simple.el b/evil-matchit-simple.el
index 10df0db350..4b42b52eae 100644
--- a/evil-matchit-simple.el
+++ b/evil-matchit-simple.el
@@ -47,29 +47,24 @@
;;;###autoload
(defun evilmi-simple-get-tag ()
- (let* (p
- tmp
- ch
- forward-line-num
- rlt
- (cur-line (evilmi-sdk-curline)))
-
- ;; Only handle open tag
- (setq tmp (evilmi--get-char-under-cursor))
- (if tmp (setq ch (car tmp)))
+ (let* (forward-line-num
+ ;; Only handle open tag
+ (tmp (evilmi--get-char-under-cursor))
+ (ch (if tmp (car tmp)))
+ rlt)
+
(if evilmi-debug (message "evilmi-simple-get-tag called => %s" ch))
(cond
;; In evil-visual-state, the (preceding-char) is actually the character
under cursor
((not (evilmi--char-is-simple ch))
- (if (setq forward-line-num (evilmi--simple-find-open-brace cur-line))
- (when forward-line-num
- (setq p (line-beginning-position))
- (forward-line (1- forward-line-num))
- (search-forward "{" nil nil)
- (backward-char)
- (setq rlt (list p))
- )))
+ (when (setq forward-line-num (evilmi--simple-find-open-brace
(evilmi-sdk-curline)))
+ (setq rlt (list (line-beginning-position)))
+ ;; need handle case "if () \n { ... }".
+ ;; move cursor over "{", prepare for `evil-jump-item'
+ (forward-line (1- forward-line-num))
+ (search-forward "{" nil nil)
+ (backward-char)))
(t
;; use evil's own evilmi--simple-jump
(setq rlt (list (point)))))
@@ -79,22 +74,19 @@
;;;###autoload
(defun evilmi-simple-jump (rlt NUM)
- (let (cur-line)
- (when rlt
- (if evilmi-debug (message "evilmi-simple-jump called"))
-
- ;; In latex-mode `scan-sexps' does NOT work properly between "[]"
- ;; so we have to fallback to evil's API.
- (if (memq major-mode '(latex-mode))
- (evil-jump-item)
- (evilmi--simple-jump))
-
- (setq cur-line (evilmi-sdk-curline))
- ;; hack for javascript
- (if (string-match "^[ \t]*})(.*)\; *$" cur-line)
- (line-end-position)
- (1+ (point)))
- )
- ))
+ (when rlt
+ (if evilmi-debug (message "evilmi-simple-jump called"))
+
+ ;; In latex-mode `scan-sexps' does NOT work properly between "[]"
+ ;; so we have to fallback to evil's API.
+ (if (memq major-mode '(latex-mode))
+ (evil-jump-item)
+ (evilmi--simple-jump))
+
+ ;; hack for javascript
+ (if (string-match "^[ \t]*})(.*)\; *$"
+ (evilmi-sdk-curline))
+ (line-end-position)
+ (1+ (point)))))
(provide 'evil-matchit-simple)
diff --git a/evil-matchit.el b/evil-matchit.el
index a4f1e2a152..b0513bd40e 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: 2.1.3
+;; Version: 2.1.4
;; Keywords: matchit vim evil
;; Package-Requires: ((evil "1.0.7"))
;;
@@ -45,11 +45,9 @@
"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")
+ "Simulate evil-jump-item behaviour.
+For example,press 50% to jump to 50 percentage in buffer.
+If nil, presing '50 %' means jump 50 times.")
(defvar evilmi-forward-chars (string-to-list "[{("))
(defvar evilmi-backward-chars (string-to-list "]})"))
@@ -108,12 +106,61 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(if evilmi-debug (message "evilmi--is-jump-forward return (%s %s %s)" rlt
ff (string ch)))
(list rlt ff ch)))
+(defun evilmi--in-comment-p (pos)
+ "Check the code at POS is comment by comparing font face."
+ (let* ((fontfaces (get-text-property pos 'face)))
+ (when (not (listp fontfaces))
+ (setf fontfaces (list fontfaces)))
+ (delq nil
+ (mapcar #'(lambda (f)
+ ;; learn this trick from flyspell
+ (or (eq f 'font-lock-comment-face)
+ (eq f 'font-lock-comment-delimiter-face)))
+ fontfaces))))
+
(defun evilmi--scan-sexps (is-forward)
(let* ((start-pos (if is-forward (point) (+ 1 (point))))
(arg (if is-forward 1 -1))
- (rlt (scan-sexps start-pos arg)))
- ;; normal state and other state
- (if evilmi-debug (message "evilmi--scan-sexps called. Return: %s" rlt))
+ (limit (if is-forward (point-max) (point-min)))
+ (lvl 1)
+ (b (following-char))
+ (e (cond
+ ;; {}
+ ((= b 123) 125)
+ ((= b 125) 123)
+ ;; ()
+ ((= b 40) 41)
+ ((= b 41) 40)
+ ;; []
+ ((= b 91) 93)
+ ((= b 93) 91)))
+ (rlt start-pos))
+ (cond
+ ((evilmi--in-comment-p (point))
+ ;; Matching tag in comment.
+ ;; Use own algorithm instead of `scan-sexps'
+ ;; because `scan-sexps' not work in some major-mode
+ (save-excursion
+ (setq start-pos (point))
+ (while (and (not (= start-pos limit))
+ (> lvl 0))
+ (setq start-pos (+ start-pos arg))
+ (goto-char start-pos)
+ (if (evilmi--in-comment-p start-pos)
+ (cond
+ ((= (following-char) b)
+ (setq lvl (1+ lvl)))
+ ((= (following-char) e)
+ (setq lvl (1- lvl))))))
+ (if (= lvl 0)
+ (setq rlt (+ start-pos (if is-forward 1 0))))))
+ (t
+ ;; not comment
+ ;; search but ignore comments
+ (let* ((parse-sexp-ignore-comments t))
+ (setq rlt (scan-sexps start-pos arg)))))
+
+ (if evilmi-debug (message "evilmi--scan-sexps called => rlt=%s lvl=%s" rlt
lvl))
rlt))
(defun evilmi--adjust-quote-jumpto (is-forward pos)
@@ -157,7 +204,7 @@ If font-face-under-cursor is NOT nil, the quoted string is
being processed"
(if evilmi-debug (message "evilmi--find-position-to-jump return %s"
(evilmi--adjust-jumpto is-forward rlt)))
(evilmi--adjust-jumpto is-forward rlt)))
-(defun evilmi--tweak-selected-region-finally (ff jump-forward)
+(defun evilmi--tweak-selected-region (ff jump-forward)
;; visual-state hack!
(if (and jump-forward (eq evil-state 'visual) (not ff))
;; if ff is non-nil, I control the jump flow from character level,
@@ -166,25 +213,15 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(defun evilmi--simple-jump ()
"Alternative for evil-jump-item."
- ;; parse-sexp-ignore-comments is used
(interactive)
- (let* ((old-flag parse-sexp-ignore-comments)
- (tmp (evilmi--is-jump-forward))
+ (let* ((tmp (evilmi--is-jump-forward))
(jump-forward (car tmp))
;; if ff is not nil, it's jump between quotes
;; so we should not use (scan-sexps)
(ff (nth 1 tmp))
(ch (nth 2 tmp)))
-
- (unless evilmi-ignore-comments
- (setq parse-sexp-ignore-comments nil))
-
- ;; need pass the char
(goto-char (evilmi--find-position-to-jump ff jump-forward ch))
- (evilmi--tweak-selected-region-finally ff jump-forward)
-
- (unless evilmi-ignore-comments
- (setq parse-sexp-ignore-comments old-flag))))
+ (evilmi--tweak-selected-region ff jump-forward)))
(defun evilmi--operate-on-item (NUM &optional FUNC)
(let ((plugin (plist-get evilmi-plugins major-mode))
@@ -412,7 +449,7 @@ If font-face-under-cursor is NOT nil, the quoted string is
being processed"
(evilmi--operate-on-item NUM))))
;;;###autoload
-(defun evilmi-version() (interactive) (message "2.1.3"))
+(defun evilmi-version() (interactive) (message "2.1.4"))
;;;###autoload
(define-minor-mode evil-matchit-mode
diff --git a/pkg.sh b/pkg.sh
index 31f38467a7..bd59e0d30c 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-pkg=evil-matchit-2.1.3
+pkg=evil-matchit-2.1.4
mkdir $pkg
cp README.org $pkg
cp *.el $pkg
- [nongnu] elpa/evil-matchit 23a0576255 213/244: fixed: can not jump tag from prompt line in shell-mode sometimes, (continued)
- [nongnu] elpa/evil-matchit 23a0576255 213/244: fixed: can not jump tag from prompt line in shell-mode sometimes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d701acb054 158/244: Merge pull request #96 from JJPandari/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit cc3654b00d 133/244: only keep fn-end and do-else-end pairs, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 7bee6fad80 167/244: Merge pull request #106 from porras/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit abe43359bf 160/244: Merge pull request #98 from nitros12/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit c5b87b4de5 174/244: Merge pull request #108 from neojski/better-parens-handling, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 5e92e374e6 179/244: better algorithm to match keyword, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 449da5ca10 082/244: fixed typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 18a3e6ab47 096/244: Merge pull request #64 from hlissner/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 58e735c5ea 097/244: org-element-property exist in 24.4+ only, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit de6ce21e1e 106/244: jump in comment,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 3873a93653 081/244: support enh-ruby-mode, more tips v2.0.1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 2f423258e1 152/244: support mhtml-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 4a24de3862 126/244: Add copyright preamble, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 73bef5fb56 134/244: Merge pull request #84 from dsdshcym/83-elixir-support, ELPA Syncer, 2022/01/06
- [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