Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #757 indentation of "\in" #789

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ci/test-indent/indent-backslash-ops.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Require Import mathcomp.ssreflect.ssrbool.

Definition xx := nat.
Module foo.
(* from PG issue #757 *)
Lemma test:
forall a : nat,
a \in [::] -> (* "\in" should be detected as one token *)
False.
Proof.
Abort.
Qed.

Lemma test2:
forall a : nat,
a \in (* "\in" should be detected as one token *)
[::] ->
False.
Proof.
Abort.
Qed.
End foo.

35 changes: 31 additions & 4 deletions coq/coq-smie.el
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,18 @@ the token of \".\" is simply \".\"."


;; A variant of smie-default-backward-token that recognize "." and ";"
;; as single token even if glued at the end of another symbols.

;; as single token even if glued at the end of another symbols. We
;; glue "\" in front of a word though, to follow ssreflects
;; ocnvention.
(defun coq-backward-token-fast-nogluing-dot-friends ()
(forward-comment (- (point)))
(let* ((pt (point))
(tok-punc (skip-syntax-backward "."))
(str-punc (buffer-substring-no-properties pt (point))))
(if (zerop tok-punc) (skip-syntax-backward "w_'"))
;; skip a regular word + one backslash
(when (zerop tok-punc)
(skip-syntax-backward "w_'")
(if (looking-back "\\s-\\\\") (forward-char -1)))
;; Special case: if the symbols found end by "." or ";",
;; then consider this last letter alone as a token
(when (and (not (zerop tok-punc)) (string-match "\\s.+[.;]" str-punc))
Expand All @@ -286,7 +290,9 @@ the token of \".\" is simply \".\"."
(let* ((pt (point))
(tok-punc (skip-syntax-forward "."))
(str-punc (buffer-substring-no-properties pt (point))))
(if (zerop tok-punc) (skip-syntax-forward "w_'"))
(if (or (zerop tok-punc) (string-match "\\\\" str-punc)
)
(skip-syntax-forward "w_'"))
;; Special case: if the symbols found end by "." or ";",
;; then consider this last letter alone as a token
(when (and (not (zerop tok-punc)) (string-match "\\s.+[.;]" str-punc))
Expand Down Expand Up @@ -653,6 +659,27 @@ The point should be at the beginning of the command name."
(cdr res)))
(tok))))

;; Modified from smie.el
(defun smie-default-forward-token ()
(forward-comment (point-max))
(buffer-substring-no-properties
(point)
(let ((dist (skip-syntax-forward ".")))

(when (or (zerop dist)
(and (= 1 dist) (looking-back "\\\\")))
(skip-syntax-forward "w_'"))
(point))))

(defun smie-default-backward-token ()
(forward-comment (- (point)))
(buffer-substring-no-properties
(point)
(progn (when (zerop (skip-syntax-backward "."))
(skip-syntax-backward "w_'")
(if (looking-back "\\s-\\\\") (forward-char -1)))
(point))))

(defun coq-smie-backward-token-aux ()
(let* ((tok (smie-default-backward-token)))
(cond
Expand Down
Loading