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

[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)



reply via email to

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