<commit_before>(ns neovim-client.nvim
  (:require [clojure.core.async :as async]
            [clojure.string :as str]
            [neovim-client.message :as message :refer [->request-msg]]
            [neovim-client.rpc :as rpc]))

;; ***** Public *****

(def connect! rpc/connect!)
(def register-method! rpc/register-method!)

;; TODO - Check for connection, before allowing commands?

(defmacro defvim
  [fn-name vim-command & args]
  `(do
     (defn ~(symbol (str fn-name "-async"))
       [~@args f#]
       (rpc/send-message-async!
         (message/->request-msg ~vim-command [~@args])
         f#))
     (defn ~fn-name
       [~@args]
       (rpc/send-message!
         (message/->request-msg ~vim-command [~@args])))))

;; :let g:foo=1
;; (vim-get-var-async "foo" println) => 1
(defvim buffer-get-line "buffer_get_line" buffer line-num)
(defvim buffer-line-count "buffer_line_count" buffer)
(defvim buffer-get-name "buffer_get_name" buffer)
(defvim buffer-get-var "buffer_get_var" buffer var-name)
(defvim buffer-set-line "buffer_set_line" buffer line-num line)
(defvim vim-call-function "vim_call_function" f-name args)
(defvim vim-command "vim_command" cmd-str)
(defvim vim-get-api-info "vim_get_api_info")
(defvim vim-get-current-buffer "vim_get_current_buffer")
(defvim vim-get-current-line "vim_get_current_line")
(defvim vim-get-current-window "vim_get_current_window")
(defvim vim-get-buffers "vim_get_buffers")
(defvim vim-get-var "vim_get_var" var-name)
(defvim vim-get-vvar "vim_get_vvar" var-name)
(defvim vim-get-windows "vim_get_windows")
(defvim vim-set-current-buffer "vim_set_current_buffer" buffer)
(defvim vim-set-current-line "vim_set_current_line" line)
(defvim vim-set-current-window "vim_set_current_window" window)
(defvim window-get-buffer "window_get_buffer" window)
(defvim window-get-cursor "window_get_cursor" window)

;; Special cases
;; TODO give x, y correct names
(defvim buffer-get-line-slice* "buffer_get_line_slice" buffer start end x y)
(defn buffer-get-line-slice
  [buffer start end]
  (buffer-get-line-slice* buffer start end true true))<commit_msg>Add buffer get number api wrapper<commit_after>(ns neovim-client.nvim
  (:require [clojure.core.async :as async]
            [clojure.string :as str]
            [neovim-client.message :as message :refer [->request-msg]]
            [neovim-client.rpc :as rpc]))

;; ***** Public *****

(def connect! rpc/connect!)
(def register-method! rpc/register-method!)

;; TODO - Check for connection, before allowing commands?

(defmacro defvim
  [fn-name vim-command & args]
  `(do
     (defn ~(symbol (str fn-name "-async"))
       [~@args f#]
       (rpc/send-message-async!
         (message/->request-msg ~vim-command [~@args])
         f#))
     (defn ~fn-name
       [~@args]
       (rpc/send-message!
         (message/->request-msg ~vim-command [~@args])))))

;; :let g:foo=1
;; (vim-get-var-async "foo" println) => 1
(defvim buffer-get-line "buffer_get_line" buffer line-num)
(defvim buffer-line-count "buffer_line_count" buffer)
(defvim buffer-get-name "buffer_get_name" buffer)
(defvim buffer-get-number "buffer_get_number" buffer)
(defvim buffer-get-var "buffer_get_var" buffer var-name)
(defvim buffer-set-line "buffer_set_line" buffer line-num line)
(defvim vim-call-function "vim_call_function" f-name args)
(defvim vim-command "vim_command" cmd-str)
(defvim vim-get-api-info "vim_get_api_info")
(defvim vim-get-current-buffer "vim_get_current_buffer")
(defvim vim-get-current-line "vim_get_current_line")
(defvim vim-get-current-window "vim_get_current_window")
(defvim vim-get-buffers "vim_get_buffers")
(defvim vim-get-var "vim_get_var" var-name)
(defvim vim-get-vvar "vim_get_vvar" var-name)
(defvim vim-get-windows "vim_get_windows")
(defvim vim-set-current-buffer "vim_set_current_buffer" buffer)
(defvim vim-set-current-line "vim_set_current_line" line)
(defvim vim-set-current-window "vim_set_current_window" window)
(defvim window-get-buffer "window_get_buffer" window)
(defvim window-get-cursor "window_get_cursor" window)

;; Special cases
;; TODO give x, y correct names
(defvim buffer-get-line-slice* "buffer_get_line_slice" buffer start end x y)
(defn buffer-get-line-slice
  [buffer start end]
  (buffer-get-line-slice* buffer start end true true))
{'fraction_non_alphanumeric': 0.14627285513361463, 'fraction_numerical': 0.0009376465072667605, 'mean_word_length': 4.33375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '91076', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1559, 'n_words': 344}