summaryrefslogtreecommitdiff
path: root/fnl/config/comment.fnl
blob: 92df966c23390daf1a81fd4641d3a671cc81f778 (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
;; Language aware commenting.
(module config.comment
  {autoload {util util}})

(defn- get-type [ctx U]
  (if (= ctx.ctype U.ctype.line)
    :__default
    :__multiline))

(defn- get-location [ctx U]
  (let [utils (require :ts_context_commentstring.utils)]
    (if (= ctx.ctype U.ctype.block)
      (utils.get_cursor_location)
      (or (= ctx.cmotion U.cmotion.v) (= ctx.cmotion U.cmotion.V))
      (utils.get_visual_start_location)
      nil)))

(defn- pre-hook [ctx]
  (let [U (require :Comment.utils)
        internal (require :ts_context_commentstring.internal)]
    (internal.calculate_commentstring
      {:key (get-type ctx U)
       :location (get-location ctx U)})))

(let [nvim-comment (util.load-plugin :Comment)]
  (nvim-comment.setup
    {:pre_hook (fn [ctx]
                  (pre-hook ctx))}))