Skip to content

Commit

Permalink
ocaml: improve validation of keywords
Browse files Browse the repository at this point in the history
If a keyword is discovered in a value/function name it shouldn't be
considered as a valid keyword. Use tuareg font face to detect good
positions.
  • Loading branch information
Khady committed May 24, 2018
1 parent 8123eef commit 2001c5b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions evil-matchit-ocaml.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
"Build regexp to find next/previous keyword in a row."
(format "\\<\\(%s\\)\\>" (mapconcat 'identity (apply 'append tag-info) "\\|")))

(defun evilmi-ocaml-valid-position-p ()
"Check if point is not in comment, string or doc"
(not (or (evilmi-in-comment-p (point))
(evilmi-in-string-or-doc-p (point)))))
(defun evilmi-ocaml-in-keyword-p (pos)
"Check character at POS is keyword by comparing font face."
(evilmi-current-font-among-fonts-p pos '(tuareg-font-lock-governing-face
font-lock-keyword-face)))

;; jumps to next keyword. Returs nil if there's no next word
(defun evilmi-ocaml-next-possible-keyword (direction keywords-regex)
Expand All @@ -74,7 +74,7 @@ such keyword is available."
(keyword-exist-p t))
(while (and (not found-keyword-p) keyword-exist-p)
(setq keyword-exist-p (evilmi-ocaml-next-possible-keyword direction keywords-regex))
(if (and keyword-exist-p (evilmi-ocaml-valid-position-p))
(if (and keyword-exist-p (evilmi-ocaml-in-keyword-p (point)))
(setq found-keyword-p t)))
found-keyword-p))

Expand Down

0 comments on commit 2001c5b

Please sign in to comment.