branch: elpa/evil-matchit commit 82c80786e596da61acb5cf506ce3225950b0e433 Author: Chen Bin <chenbin...@gmail.com> Commit: Chen Bin <chenbin...@gmail.com>
jump between merge conflict markers --- evil-matchit-prog.el | 50 +++++++++++++++++++++++++++++++++++++++++++++ evil-matchit-sdk.el | 3 +++ evil-matchit.el | 8 ++++++++ tests/conflict.js | 20 ++++++++++++++++++ tests/evil-matchit-tests.el | 15 ++++++++++++++ 5 files changed, 96 insertions(+) diff --git a/evil-matchit-prog.el b/evil-matchit-prog.el new file mode 100644 index 0000000000..5a558faaa9 --- /dev/null +++ b/evil-matchit-prog.el @@ -0,0 +1,50 @@ +;;; evil-matchit-prog.el --- all programming languages plugin of evil-matchit + +;; Copyright (C) 2021 Chen Bin <chenbin DOT sh AT gmail DOT com> + +;; Author: Chen Bin <chenbin DOT sh AT gmail DOT 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/>. + +;;; Commentary: + +;; +;;; Code: + +(require 'evil-matchit-sdk) + +(defvar evilmi-prog-extract-keyword-howtos + '(("^\\(<<<<<<<\\|=======\\|>>>>>>>\\)" 1))) + +(defvar evilmi-prog-match-tags + '((("<<<<<<<") ("=======") (">>>>>>>")))) + +;;;###autoload +(defun evilmi-prog-get-tag () + "Get tag at point." + (evilmi-sdk-get-tag evilmi-prog-match-tags evilmi-prog-extract-keyword-howtos)) + +;;;###autoload +(defun evilmi-prog-jump (info num) + "Use INFO to jump NUM times." + (evilmi-sdk-jump info num evilmi-prog-match-tags evilmi-prog-extract-keyword-howtos)) + +(provide 'evil-matchit-prog) +;;; evil-matchit-prog.el ends here diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el index 2c020ddd88..fad4e2795b 100644 --- a/evil-matchit-sdk.el +++ b/evil-matchit-sdk.el @@ -468,6 +468,9 @@ after calling this function." (= (line-beginning-position) (point-min))) (setq found t))) + (when evilmi-debug + (message "evilmi-sdk-jump was called. ideal-dest=%s" ideal-dest)) + ideal-dest)) diff --git a/evil-matchit.el b/evil-matchit.el index ee53be43ad..ac8bbc43a1 100644 --- a/evil-matchit.el +++ b/evil-matchit.el @@ -81,6 +81,10 @@ Some people prefer using \"m\" instead.") (unless num (setq num 1)) + (when (derived-mode-p 'prog-mode) + (setq jump-rules + (append (plist-get evilmi-plugins 'prog-mode) jump-rules))) + (when jump-rules (dolist (rule jump-rules) ;; execute evilmi-xxxx-get-tag @@ -140,6 +144,10 @@ Some people prefer using \"m\" instead.") (defun evilmi-init-plugins () "Load plugins." (interactive) + + ;; rules for `prog-mode' + (evilmi-load-plugin-rules '(prog-mode) '(prog)) + ;; simple matching for languages containing brackets (evilmi-load-plugin-rules '(java-mode perl-mode cperl-mode go-mode) '(simple)) diff --git a/tests/conflict.js b/tests/conflict.js new file mode 100644 index 0000000000..f90420389d --- /dev/null +++ b/tests/conflict.js @@ -0,0 +1,20 @@ +function hello() { + console.log('hello world'); +} + +<<<<<<< 97a4bebea... debug +const test1 = [ +]; + +const test2 = { +}; +======= + +const test3 = hello( +); +>>>>>>> 97a4bebea... debug + +const test4 = hello( +); + +// bye \ No newline at end of file diff --git a/tests/evil-matchit-tests.el b/tests/evil-matchit-tests.el index a16abd6365..ff80d64768 100644 --- a/tests/evil-matchit-tests.el +++ b/tests/evil-matchit-tests.el @@ -554,5 +554,20 @@ (should (eq major-mode 'org-mode)))) +(ert-deftest evilmi-test-merge-conflict () + (with-temp-buffer + (evilmi-test-read-file "conflict.js") + (js-mode) + + (goto-char (point-min)) + (re-search-forward "^<<<<<<") + (evilmi-jump-items) + (should (string-match "^======" (evilmi-sdk-curline))) + (evilmi-jump-items) + (should (string-match "^>>>>>>" (evilmi-sdk-curline))) + (evilmi-jump-items) + (should (string-match "^<<<<<<" (evilmi-sdk-curline))) + + (should (eq major-mode 'js-mode)))) (ert-run-tests-batch-and-exit) ;;; evil-matchit-tests.el ends here