about summary refs log tree commit diff
path: root/fnl/nvrc/events.fnl
blob: 43b5efaa3363cb13282d769fc527b685d207f968 (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
(import-macros {: ag!
                : au!} :nvrc.macro.event)
(import-macros {: set!
                : setl!} :nvrc.macro.set)
(local {: echo!} (require :nvrc.lib.io))

(local {: line
        : mode} vim.fn)
(fn cmd! [...] (vim.cmd ...))
(fn bufexists? [...] (= (vim.fn.bufexists ...) 1))

; Restore cursor style to beam on exit
;; (ag! restore-cursor
;;           (au! VimLeave * (set! guicursor ["a:ver75-blinkon0"])))

(ag! restore-last-cursor-line
          (au! BufReadPost * (if (and (> (line "'\"") 1)
                                       (<= (line "'\"") (line "$")))
                                  (cmd! "normal! g`\""))))

(ag! resize-splits-on-resize
          (au! VimResized * "wincmd ="))

(ag! read-file-on-disk-change
          (au! [FocusGained BufEnter CursorHold CursorHoldI] *
                    (if (and (not= :c (mode))
                              (not (bufexists? "[Command Line]")))
                       (cmd! "checktime")))
          (au! FileChangedShellPost *
                    (echo! "File changed on disk. Buffer reloaded.")))

(ag! terminal-options
          ;; Enter Terminal-mode (insert) agtomatically
          (au! TermOpen * "startinsert")
          ;; Disables line number on terminal buffers
          (au! TermOpen * (do
                                  (setl! nonumber)
                                  (setl! norelativenumber)))
          ;; Disables spell on terminal buffers
          (au! TermOpen * (setl! nospell))
          ;; Disables sign column on terminal buffers
          (au! TermOpen * (setl! signcolumn :no))
          ;; Disables colorcolumn on terminal buffers
          (au! TermOpen * (setl! colorcolumn [])))

(ag! markdown-wrap-line
     (au! FileType markdown (setl! textwidth 80)))

(ag! mail-wrap-line
     (au! FileType mail (setl! textwidth 80)))

(ag! extra-filetypes
     ;; Tailscale "Human JSON" files
     (au! [BufNewFile BufRead] "*.hujson" (vim.api.nvim_buf_set_option (vim.api.nvim_get_current_buf) :filetype :jsonc)))