summaryrefslogtreecommitdiff
path: root/emacs/inits/25-theorems.el
blob: f5ab26b248ab47eec597b73a6e18fc9986b8c9f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;; Time-stamp: <2020-01-08 18:37:56 (tslil@bison)>

;; -----------------------------------------------------------------------------
;; Coq

;; (defvar pg-inserted-newline nil)
;; (defconst pg-whitespace-match "[ \\t]")
;; (defconst pg-subgoal-match "[*+\\-]")

;; (defun pg-move-point-dwim ()
;;   (interactive)
;;   ;; Did we move to a blank new line?
;;   (when (= (point) (point-at-bol))
;;     ;; If there's nothing here, lets add another line below
;;     (when (looking-at-p (concat pg-whitespace-match "*$"))
;;       (save-excursion (newline))
;;       (setq pg-inserted-newline t))
;;     ;; Now let's work out where the point should go
;;     (previous-line)
;;     (beginning-of-line)
;;     ;; Is the previous line essentially a subgoal marker?
;;     (if (looking-at-p (concat pg-whitespace-match "*"
;;                               pg-subgoal-match "+"
;;                               pg-whitespace-match "*$"))
;;         ;; If so, trim the line and put the point in after the subgoal marker
;;         (progn
;;           (delete-trailing-whitespace (point-at-bol) (point-at-eol))
;;           (end-of-line)
;;           (insert-char ? ))
;;       ;; If not, go back to where we were and indent
;;       (next-line)
;;       (indent-for-tab-command))))

(defconst coq-env '(("UniMath"
                     :topdir "~/theorems/coq/UniMath/"
                     :binary "sub/coq/bin/coqtop"
                     :args ("-coqlib" "/home/tslil/theorems/coq/UniMath/sub/coq/"
                            "-emacs" "-noinit"
                            "-indices-matter"
                            "-type-in-type" "-w" "-notation-overridden"
                            "-Q" "/home/tslil/theorems/coq/UniMath/UniMath" "UniMath"
                            "-Q" "/home/tslil/academic/proof_relevant_cats/formalisation" "PRCats"))
                    ("HoTT"
                     :topdir "~/theorems/coq/HoTT/"
                     :binary "hoqtop"
                     :args nil)))

(defvar use-coq-env "HoTT")

(defun mike-implicify (ntimes)
  (interactive "p")
  (save-excursion
    (re-search-backward "(\\|{")
    (dotimes (i ntimes)
      (if (looking-at "(")
          (progn (delete-char 1)
                 (insert "{")
                 (backward-char 1)
                 (forward-sexp 1)
                 (delete-char -1)
                 (insert "}"))
        (progn (delete-char 1)
               (insert "(")
               (backward-char 1)
               (forward-sexp 1)
               (delete-char -1)
               (insert ")")))
      (re-search-forward "(\\|{")
      (backward-char 1))))

(use-package proof-general
  :ensure t
  :defer t
  :functions coq-local-environment
  :init (setq proof-splash-enable nil
              proof-follow-mode 'followdown)
  ;; It's really annoying to have the code truncated due to equal
  ;; division ratios of the windows. The 5 is to accomodate line
  ;; numbers and the like
  (defadvice proof-layout-windows (after resize-window-properly activate)
    (let ((ww (window-width)))
      (when (< ww (+ 7 fill-column))
        (enlarge-window-horizontally (- (+ 7 fill-column) ww)))))
  (defun coq-local-environment ()
    (require 'corral)
    (bind-keys :map coq-mode-map
               ("M-i" . mike-implicify)
               ("M-a" . forward-sexp)
               ("M-e" . backward-sexp)
               ("M-/" . lh-matching-delim)
               ("M-(" . corral-parentheses-forward)
               ("M-)" . corral-parentheses-backward)
               ("M-{" . corral-braces-forward)
               ("M-}" . corral-braces-backward)
               ("M-[" . corral-brackets-forward)
               ("M-]" . corral-brackets-backward)
               ("C-(" . lh-slurp-forward)
               ("C-)" . lh-slurp-backward)
               ("C-s" . isearch-forward))
    (let* ((data (alist-get use-coq-env coq-env nil nil #'string-equal))
           (topdir (expand-file-name (plist-get data :topdir)))
           (binary (plist-get data :binary))
           (args (plist-get data :args)))
      ;; TAGS
      (visit-tags-table (concat topdir "TAGS"))
      ;; Formatting
      (setq fill-column 70)
      (visual-line-mode 1)
      (set-fringe-mode 0)
      (make-local-variable 'before-save-hook)
      (add-hook 'before-save-hook 'delete-trailing-whitespace)
      (setq proof-three-window-mode-policy 'hybrid
            proof-layout-windows-on-visit-file t
            proof-shrink-windows-tofit t
            proof-script-fly-past-comments t)
      ;; Tweak syntax table
      ;; (modify-syntax-entry ?' "w")
      ;; Coq binary related
      (dolist (var '(coq-use-project-file coq-prog-args coq-prog-name))
        (make-local-variable var))
      (setq coq-use-project-file nil
            coq-prog-args args
            coq-prog-name (concat topdir binary))
      (agda-input-setup)
      (activate-input-method "Agda")))
  :mode ("\\.v$" . coq-mode)
  :hook (coq-mode . (lambda ()
                      (programming-setup)
                      (coq-local-environment)
                      (auto-fill-mode)
                      (company-coq-mode))))

(use-package company-coq
  :after proof-general
  :ensure t
  :bind (:map company-coq-map
              ("M-." . xref-find-references)
              ("M-*" . pop-tag-mark))
  :init
  (setq company-coq-disabled-features '(hello)))

;; -----------------------------------------------------------------------------
;; Agda

(load-file (let ((coding-system-for-read 'utf-8))
             (shell-command-to-string "agda-mode locate")))

(add-hook 'agda2-mode
          (lambda ()
            (subword-mode 1)
            (auto-fill-mode)
            (aggressive-indent-mode -1)))

;; -----------------------------------------------------------------------------
;; Lean

;; (use-package lean-mode
;;   :ensure t
;;   :defer t
;;   :mode ("\\.lean$" . lean-mode))