[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit 3417dbb275 117/244: Add ocaml support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit 3417dbb275 117/244: Add ocaml support |
Date: |
Thu, 6 Jan 2022 02:58:54 -0500 (EST) |
branch: elpa/evil-matchit
commit 3417dbb2754de6f9d076400a9289db9921ef7d65
Author: Tomasz KoĆodziejski <tkolodziejski@gmail.com>
Commit: Tomasz KoĆodziejski <tkolodziejski@gmail.com>
Add ocaml support
---
evil-matchit-ocaml.el | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/evil-matchit-ocaml.el b/evil-matchit-ocaml.el
new file mode 100644
index 0000000000..00e1c2e00e
--- /dev/null
+++ b/evil-matchit-ocaml.el
@@ -0,0 +1,82 @@
+(setq evilmi-ocaml-keywords
+ '((("struct" "begin" "object") ("end"))
+ (("if") ("then"))
+ (("match") ("with"))
+ (("match" "try") ("with"))
+ (("while" "for") ("done"))
+ (("let") ("in"))
+ ()))
+
+;; regexp to find next/previous keyword
+(setq keywords-regex
+ (let ((all-keywords (apply 'append (apply 'append evilmi-ocaml-keywords))))
+ (format "\\<\\(%s\\)\\>" (mapconcat 'identity all-keywords "\\|"))))
+
+;; jumps to next keyword. Returs nil if there's no next word
+(defun evilmi-ocaml-next-word (direction)
+ (if (= direction 0)
+ (let ((new-point (save-excursion
+ (forward-char)
+ (if (search-forward-regexp keywords-regex nil t)
+ (search-backward-regexp keywords-regex)
+ nil)
+ )))
+ (if new-point (goto-char new-point)))
+ (search-backward-regexp keywords-regex nil t)))
+
+(defun evilmi-ocaml-end-word ()
+ (save-excursion
+ (search-forward-regexp "\\>")
+ (point)))
+
+(defun evilmi-ocaml-get-word ()
+ (buffer-substring-no-properties (point) (evilmi-ocaml-end-word)))
+
+(defun evilmi-ocaml-is-keyword (l keyword)
+ "Checks if the keyword belongs to a row"
+ (find-if (lambda (w) (string-equal w keyword)) (apply 'append l)))
+
+(defun evilmi-ocaml-get-tag-info (keyword)
+ "Find the row in the evilmi-ocaml-keywords"
+ (find-if (lambda (l) (evilmi-ocaml-is-keyword l keyword))
evilmi-ocaml-keywords))
+
+;; 0 - forward
+;; 1 - backward
+(defun evilmi-ocaml-go (tag-info level direction)
+ (if (= level 0)
+ (point)
+ (if (evilmi-ocaml-next-word direction)
+ (progn
+ (setq keyword (evilmi-ocaml-get-word))
+
+ (if (evilmi-ocaml-is-keyword tag-info keyword)
+ ;; interesting tag
+ (if (member keyword (nth direction tag-info))
+ (evilmi-ocaml-go tag-info (+ level 1) direction)
+ (evilmi-ocaml-go tag-info (- level 1) direction))
+
+ ;; other tag
+ (evilmi-ocaml-go tag-info level direction)))
+ nil)))
+
+(defun evilmi-ocaml-goto-word-beginning ()
+ ;; this is so that when the cursor is on the first character we don't jump
to previous word
+ (forward-char)
+ (search-backward-regexp "\\<"))
+
+;;;###autoload
+(defun evilmi-ocaml-get-tag ()
+ (save-excursion
+ (evilmi-ocaml-goto-word-beginning)
+ (evilmi-ocaml-get-word)))
+
+;;;###autoload
+(defun evilmi-ocaml-jump (rlt num)
+ (let* ((tag-info (evilmi-ocaml-get-tag-info rlt))
+ (direction (if (member rlt (car tag-info)) 0 1)))
+ (let ((new-point (save-excursion
+ (evilmi-ocaml-goto-word-beginning)
+ (evilmi-ocaml-go tag-info 1 direction))))
+ (if new-point (goto-char new-point)))))
+
+(provide 'evil-matchit-ocaml)
- [nongnu] elpa/evil-matchit 2fc961d94b 122/244: fixed css-mode minor issue, (continued)
- [nongnu] elpa/evil-matchit 2fc961d94b 122/244: fixed css-mode minor issue, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 2001c5be5f 147/244: ocaml: improve validation of keywords, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 8fa4c1390d 163/244: can change shortcut from "%" to "m", ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 665751dff8 165/244: Ignore trailing space in Ruby blocks with arguments, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 848dc06902 183/244: clean code&do, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 1027459d44 180/244: more torelant to ruby syntax, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d75d41d7b3 197/244: add unit test for c, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 25ad66d397 190/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 289982cbee 192/244: doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 9b228b097a 242/244: easier to add own rules, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 3417dbb275 117/244: Add ocaml support,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 80413a836a 121/244: Merge pull request #79 from msaffer/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 47894a6cc0 151/244: Merge pull request #93 from AitBits/patch-2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 4c6b8f412f 159/244: Add autoload definitions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 1c428e192b 149/244: ocaml use font-lock-doc-face for comment, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 0845b2a0bf 178/244: Merge pull request #109 from neojski/add-double-semicolon, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 11aa990ecb 177/244: Merge pull request #110 from leungbk/elisp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 11d98debf8 187/244: Merge pull request #115 from dajva/jump_motion, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit bc31e7d594 199/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 6fd4c56855 198/244: clean code, more c unit test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 24dcd74a55 205/244: support terminal in Emacs, ELPA Syncer, 2022/01/06