[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit 34c51f68fd 102/244: jump in diff-mode
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit 34c51f68fd 102/244: jump in diff-mode |
Date: |
Thu, 6 Jan 2022 02:58:53 -0500 (EST) |
branch: elpa/evil-matchit
commit 34c51f68fd0b3e055d00c13a8b0160117b15569b
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
jump in diff-mode
---
evil-matchit-diff.el | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++
evil-matchit.el | 14 ++++++--
2 files changed, 106 insertions(+), 3 deletions(-)
diff --git a/evil-matchit-diff.el b/evil-matchit-diff.el
new file mode 100644
index 0000000000..e654d307ba
--- /dev/null
+++ b/evil-matchit-diff.el
@@ -0,0 +1,95 @@
+;;; evil-matchit-diff.el -- diff-mode plugin of evil-matchit
+
+;; Copyright (C) 2014-2016 Chen Bin <chenbin.sh@gmail.com>
+
+;; Author: Chen Bin <chenbin.sh@gmail.com>
+
+;; This file is not part of GNU Emacs.
+
+;;; License:
+
+;; This file is part of evil-matchit
+;;
+;; evil-matchit is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published
+;; by the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; evil-matchit is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+;;; Code:
+
+(defun evilmi--cur-line ()
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
+
+(defun evilmi-diff-guess-final-pos ()
+ (let* ((final-pos (point)))
+ (save-excursion
+ (let* (tmp-line)
+ (forward-line -1)
+ (setq tmp-line (evilmi--cur-line))
+ (if (string-match-p "^index [0-9a-z]+\\.+[0-9a-z]+ [0-9]+$" tmp-line)
+ (forward-line -1))
+ (setq tmp-line (evilmi--cur-line))
+ (if (string-match-p "^diff [^ ]" tmp-line)
+ (forward-line -1))
+ (setq final-pos (line-end-position))))
+ final-pos))
+
+;;;###autoload
+(defun evilmi-diff-get-tag ()
+ ;; do nothing
+ (let* ((cur-line (evilmi--cur-line))
+ (final-pos (point)))
+ (if (string-match-p "^--- " cur-line)
+ (save-excursion
+ (setq final-pos (evilmi-diff-guess-final-pos))))
+ (list final-pos)))
+
+;;;###autoload
+(defun evilmi-diff-jump (rlt NUM)
+ (let* ((cur-line (evilmi--cur-line))
+ (final-pos (point)))
+ (cond
+ ((string-match-p "^\\+\\+\\+ " cur-line)
+ ;; next file in diff-mode
+ (cond
+ ((re-search-forward "^--- " (point-max) t)
+ (setq final-pos (evilmi-diff-guess-final-pos))
+ (re-search-forward "^\\+\\+\\+ " (point-max) t)
+ (goto-char (line-beginning-position)))
+ (t
+ (setq final-pos (goto-char (point-max))))))
+
+ ((string-match "^--- " cur-line)
+ ;; previous file in diff-mode
+ (when (re-search-backward "^\\+\\+\\+ " (point-min) t)
+ (save-excursion
+ (forward-line 1)
+ (setq final-pos (line-end-position)))
+ (re-search-backward "^--- " (point-min) t)
+ (goto-char (line-beginning-position))))
+
+ ((string-match-p "^@@ " cur-line)
+ (forward-line 1)
+ ;; previous file in diff-mode
+ (cond
+ ((re-search-forward "^\\(diff\\|---\\|@@ \\)" (point-max) t)
+ (goto-char (line-beginning-position))
+ (save-excursion
+ (forward-line -1)
+ (setq final-pos (line-end-position))))
+ (t
+ (setq final-pos (goto-char (point-max)))))))
+ final-pos))
+
+(provide 'evil-matchit-diff)
diff --git a/evil-matchit.el b/evil-matchit.el
index cfa55e5750..d4b9305c96 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -220,17 +220,19 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(if plugin
(mapc
(lambda (elem)
+ ;; excute evilmi-xxxx-get-tag
(setq rlt (funcall (nth 0 elem)))
(when (and rlt (not jumped))
;; before jump, we may need some operation
(if FUNC (funcall FUNC rlt))
- ;; jump now
+ ;; jump now, execute evilmi-xxxx-jump
(setq where-to-jump-in-theory (funcall (nth 1 elem) rlt NUM))
;; jump only once if the jump is successful
(setq jumped t)
))
plugin))
+ ;; give `evilmi--simple-jump' a chance
(when (not jumped)
(if FUNC (funcall FUNC (list (point))))
(evilmi--simple-jump)
@@ -300,10 +302,16 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(autoload 'evilmi-c-jump "evil-matchit-c" nil)
(mapc (lambda (mode)
(plist-put evilmi-plugins mode '((evilmi-c-get-tag evilmi-c-jump)
- (evilmi-simple-get-tag
evilmi-simple-jump)))
- )
+ (evilmi-simple-get-tag
evilmi-simple-jump))))
'(c-mode c++-mode))
+ ;; diff/patch
+ (autoload 'evilmi-diff-get-tag "evil-matchit-diff" nil)
+ (autoload 'evilmi-diff-jump "evil-matchit-diff" nil)
+ (mapc (lambda (mode)
+ (plist-put evilmi-plugins mode '((evilmi-simple-get-tag
evilmi-simple-jump)
+ (evilmi-diff-get-tag
evilmi-diff-jump))))
+ '(diff-mode ffip-diff-mode magit-diff-mode))
;; Fortran
(autoload 'evilmi-fortran-get-tag "evil-matchit-fortran" nil)
(autoload 'evilmi-fortran-jump "evil-matchit-fortran" nil)
- [nongnu] elpa/evil-matchit 8540a4c12a 068/244: supports inner text object, v1.5.0, (continued)
- [nongnu] elpa/evil-matchit 8540a4c12a 068/244: supports inner text object, v1.5.0, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 8b4db43dc2 075/244: Merge pull request #44 from thegreatape/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit af40d309c6 078/244: documentation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 89fd968ac2 080/244: spacemacs use enh-ruby-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ff29cd2264 084/244: workaround issue in python-mode v2.0.2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 63846fc4c0 089/244: Add melpa badge, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 62d948743e 092/244: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 98c045d352 094/244: Merge pull request #61 from robbyoconnor/patch-2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 94e359e30c 095/244: Fix embedded major-mode detection in org-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit c675e740a7 101/244: can simple jump in latex-mode, #70, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 34c51f68fd 102/244: jump in diff-mode,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 64791bc376 105/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 51d46747e3 108/244: support Facebook React JSX, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 8a56092b38 110/244: can handle `render()` in jsx, code cleaned, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit bed39041b1 123/244: support markdown, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 7d65b4167b 156/244: clean plugins setup code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit b63f840ee7 124/244: When on whitespace following a keyword don't jump backwards, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 20270ab6b0 135/244: support one liner, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 51d8b268e5 138/244: Merge pull request #86 from yqrashawn/support-tsx, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit dbaae2b753 127/244: Merge pull request #81 from neojski/ocaml, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit dea3fca13b 168/244: clean code dependency, ELPA Syncer, 2022/01/06