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


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

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

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

(let [(ok? ncomment) util.load-plugin :Comment]
  (when ok?
    (ncomment.setup 
      {:pre_hook (fn [ctx]
                     (pre-hook ctx))})))