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

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

[nongnu] elpa/evil-matchit fcf6b25407 063/244: fortran


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit fcf6b25407 063/244: fortran
Date: Thu, 6 Jan 2022 02:58:49 -0500 (EST)

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

    fortran
---
 evil-matchit-fortran.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++++
 evil-matchit-sdk.el     | 10 +++++++-
 evil-matchit.el         |  7 ++++++
 3 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/evil-matchit-fortran.el b/evil-matchit-fortran.el
new file mode 100644
index 0000000000..5bbeed072a
--- /dev/null
+++ b/evil-matchit-fortran.el
@@ -0,0 +1,67 @@
+;;; evil-matchit-fortran.el ---fortran (ruby/lua) plugin of evil-matchit
+
+;; Copyright (C) 2014  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:
+
+;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
+;; but SDK don make you write less code, isn't it?
+;; All you need to do is just define the match-tags for SDK algorithm to 
lookup.
+(require 'evil-matchit-sdk)
+
+(defvar evilmi-fortran-extract-keyword-howtos
+  '(("^[ \t]*\\([a-zA-Z _]+\\)[(:].*$" 1) ;; "if (...)"
+    ("^[ \t]*\\([a-zA-Z]+\\) *$" 1) ;; "end"
+    ("^[ \t]*\\(do\\) .*$" 1) ;; "do i=1,10"
+    ("^[ \t]*\\([a-zA-Z]+ [a-zA-Z0-9_]+\\).*$" 1) ;; "end program"
+    ))
+
+;; Fortran (http://www.fortran.org) syntax
+(defvar evilmi-fortran-match-tags
+  '((("if") ("else if" "else") ("end" "end *if"))
+    (("do" "while") () ("end *do" "until" "continue"))
+    (("where") ("elsewhere") ("end *where") "MONOGAMY")
+    (("select *case") ("case" "case default") ("end *select") "MONOGAMY")
+    (("forall") () ("end *forall.*") "MONOGAMY")
+    (("associate .*") () ("end *associate.*") "MONOGAMY")
+    (("enum") () ("end *enum.*") "MONOGAMY")
+    (("interface") () ("end *interface.*") "MONOGAMY")
+    (("subroutine .*") () ("end *subroutine" "end"))
+    (("function .*") () ("end *function" "end"))
+    (("module .*") () ("end *module.*") "MONOGAMY")
+    (("program .*") () ("end *program.*") "MONOGAMY")
+    ))
+
+;;;###autoload
+(defun evilmi-fortran-get-tag ()
+  (evilmi-sdk-get-tag evilmi-fortran-match-tags 
evilmi-fortran-extract-keyword-howtos)
+  )
+
+;;;###autoload
+(defun evilmi-fortran-jump (rlt NUM)
+  (evilmi-sdk-jump rlt NUM evilmi-fortran-match-tags 
evilmi-fortran-extract-keyword-howtos)
+  )
+
+(provide 'evil-matchit-fortran)
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index 4f4ab39c83..e3c8229e88 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -9,6 +9,11 @@ to extract the keyword which starts from one. The sub-match is 
the match defined
 between '\\(' and '\\)' in regular expression.
 ")
 
+;; slower but I don't care
+;; @see http://ergoemacs.org/emacs/modernization_elisp_lib_problem.html
+(defun evilmi-sdk-trim-string (string)
+  (replace-regexp-in-string "\\`[ \t\n]*" "" (replace-regexp-in-string "[ 
\t\n]*\\'" "" string)))
+
 (defun evilmi-sdk-tags-is-matched (level orig-tag-info cur-tag-info match-tags)
   (let (rlt
         (tag-pair-status (nth 2 cur-tag-info)))
@@ -105,7 +110,10 @@ is-function-exit-point could be 'FN_EXIT' or other status"
       (setq howto (nth i howtos))
 
       (when (string-match (nth 0 howto) cur-line)
-        (setq keyword (match-string (nth 1 howto) cur-line))
+        ;; keyword should be trimmed because FORTRAN use "else if"
+        (setq keyword (evilmi-sdk-trim-string (match-string (nth 1 howto) 
cur-line) ))
+        ;; (message "keyword=%s" keyword)
+
         ;; keep search keyword by using next howto (regex and match-string 
index)
         (if (not (evilmi-sdk-member keyword match-tags)) (setq keyword nil))
         )
diff --git a/evil-matchit.el b/evil-matchit.el
index 4efb90aa59..88ed0b1d74 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -137,6 +137,13 @@ If this flag is nil, then 50 means jump 50 times.")
           )
         '(c-mode c++-mode))
 
+  ;; Fortran
+  (autoload 'evilmi-fortran-get-tag "evil-matchit-fortran" nil)
+  (autoload 'evilmi-fortran-jump "evil-matchit-fortran" nil)
+  (mapc (lambda (mode)
+          (plist-put evilmi-plugins mode '((evilmi-fortran-get-tag 
evilmi-fortran-jump))))
+        '(f90-mode fortran-mode))
+
   ;; CMake (http://www.cmake.org)
   (autoload 'evilmi-cmake-get-tag "evil-matchit-cmake" nil)
   (autoload 'evilmi-cmake-jump "evil-matchit-cmake" nil)



reply via email to

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