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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil-matchit 24dcd74a55 205/244: support terminal in Emacs


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 24dcd74a55 205/244: support terminal in Emacs
Date: Thu, 6 Jan 2022 02:59:02 -0500 (EST)

branch: elpa/evil-matchit
commit 24dcd74a55911662e6951e76a6a69fe9669c544d
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>

    support terminal in Emacs
---
 README.org               |  4 +-
 evil-matchit-sdk.el      |  6 ++-
 evil-matchit-terminal.el | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
 evil-matchit.el          |  3 ++
 4 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/README.org b/README.org
index d93d901f77..6d57cd2885 100644
--- a/README.org
+++ b/README.org
@@ -31,11 +31,13 @@ Many modern languages are supported:
 - Laravel Blade Templating
 - Vim script
 - Verilog
+- Diff/Patch
+- Shell/Terminal bundled in Emacs
 - Emacs email (message-mode)
 
 This package uses Evil as its vi layer!
 
-Tested on Emacs 24.3, 24.4, 24.5, 25.1
+Tested on Emacs 24.4, 24.5, 25.1, 26, 27, 28
 
 * Why use evil-matchit
 - No learning curve. Press "%" to jump. That's all!
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index 6a28ead799..2f42609a95 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -193,8 +193,10 @@ If IS-FORWARD is t, jump forward; or else jump backward."
 
 ;;;###autoload
 (defun evilmi-sdk-curline ()
-  (buffer-substring-no-properties (line-beginning-position)
-                                  (line-end-position)))
+  "Get current line text."
+  (let* ((inhibit-field-text-motion t))
+    (buffer-substring-no-properties (line-beginning-position)
+                                    (line-end-position))))
 
 ;;;###autoload
 (defun evilmi-sdk-member (keyword keyword-list)
diff --git a/evil-matchit-terminal.el b/evil-matchit-terminal.el
new file mode 100644
index 0000000000..210e4c0d4d
--- /dev/null
+++ b/evil-matchit-terminal.el
@@ -0,0 +1,96 @@
+;;; evil-matchit-terminal.el --- terminal plugin of evil-matchit
+
+;; Copyright (C) 2020 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:
+
+;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
+;; but SDK do make you write less code, isn't it?
+;; All you need to do is just define the match-tags for SDK algorithm to 
lookup.
+;;
+;;; Commentary:
+;;
+;;; Code:
+
+(require 'evil-matchit-sdk)
+
+(defvar evilmi-terminal-primary-prompt "^\\$ "
+  "The primary prompt of terminal")
+
+(defvar evilmi-terminal-ps1-line-number 1
+  "The line containing PS1.")
+
+;;;###autoload
+(defun evilmi-terminal-get-tag ()
+  "Get tag at point."
+  (let* ((curline (evilmi-sdk-curline))
+         (prompt evilmi-terminal-primary-prompt)
+         line1
+         line2)
+    (cond
+     ((string-match prompt curline)
+      ;; open tag
+      (list (line-beginning-position) 0))
+     (t
+      (save-excursion
+        (forward-line)
+        (setq line1 (evilmi-sdk-curline))
+        (forward-line)
+        (setq line2 (evilmi-sdk-curline)))
+      (when (and line1 line2 (or (string-match prompt line1)
+                                 (string-match prompt line2)))
+        (list (line-end-position) 1))))))
+
+;;;###autoload
+(defun evilmi-terminal-jump (info num)
+  "Use INFO to jump NUM times."
+  (ignore num)
+  (when info
+    (let* ((type (nth 1 info))
+           (prompt evilmi-terminal-primary-prompt)
+           pos)
+      (cond
+       ;; from open tag
+       ((eq type 0)
+        (save-excursion
+          ;; skip current line
+          (forward-line 1)
+          (when (re-search-forward prompt (point-max) t)
+            (forward-line -1)
+            (forward-line (- evilmi-terminal-ps1-line-number))
+            (setq pos (line-end-position))))
+        (when pos (goto-char pos)))
+
+       ;; from close tag
+       ((eq type 1)
+        (save-excursion
+          ;; skip current line
+          (when (re-search-backward prompt (point-min) t)
+            (setq pos (line-beginning-position))))
+        (when pos (goto-char pos))))
+      pos)))
+
+(provide 'evil-matchit-terminal)
+;;; evil-matchit-terminal.el ends here
diff --git a/evil-matchit.el b/evil-matchit.el
index 4f30491963..107a2b27ff 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -206,6 +206,9 @@ Some people prefer using \"m\" instead.")
   ;; Ruby
   (evilmi-load-plugin-rules '(ruby-mode enh-ruby-mode) '(simple ruby))
 
+  ;; terminal
+  (evilmi-load-plugin-rules '(term-mode shell-mode) '(simple terminal))
+
   ;; Elixir
   (evilmi-load-plugin-rules '(elixir-mode enh-elixir-mode) '(simple elixir)))
 



reply via email to

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