Exemple #1
0
    def ensure_win_exists(self):
        no_shared_buffer = self.buf_nr is None
        has_no_window = no_shared_buffer or self.nvim.funcs.bufwinnr(
            self.buf_nr) == -1

        log_debug("buf_nr is {}", self.buf_nr)
        log_debug("has window? {}", has_no_window)

        if no_shared_buffer or has_no_window:
            self.random = random.randint(0, 100)
            cmds = [
                'file acid://meta-repl-{}'.format(self.random),
                'nnoremap <buffer> <localleader><CR> :e<CR>',
                'nnoremap <buffer> <localleader><localleader> kdggjdG',
                'nnoremap <buffer> <localleader>D kdgg',
                'nnoremap <buffer> <localleader>d jdG',
            ]

            self.buf_nr = build_window(
                self.nvim,
                close=1,
                commands=cmds,
                throwaway=1,
            )
            log_debug("Set buf_nr to {}", self.buf_nr)
Exemple #2
0
    def ensure_cmd_win_exists(self):
        use_cmd_win = bool(
            self.nvim.vars.get('acid_meta_repl_use_cmd_window', False))

        log_debug("use cmd win? is {}", self.use_cmd_win)

        if use_cmd_win:
            no_cmd = self.cmd_buf_nr is None
            has_no_cmd_window = self.nvim.funcs.bufwinnr(self.cmd_buf_nr) == -1

            if no_cmd or has_no_cmd_window:
                send = """:call AcidSendNrepl({
                    'op': 'eval', 'code': join(getline(1, '$'), '\\n')
                    }, 'MetaRepl')<CR>""".splitlines()

                send = "map <buffer> <silent> <localleader><CR> {}".format(
                    "".join(map(str.strip, send)))
                meta_repl_window = self.nvim.funcs.bufwinnr(self.buf_nr)
                nvim.command("{} wincmd w".format(meta_repl_window))

                self.cmd_buf_nr = build_window(
                    self.nvim,
                    close=1,
                    throwaway=1,
                    orientation="rightbelow 20 split",
                    commands=[
                        'file acid://meta-repl-{}/scratchpad'.format(
                            self.random), 'set ft=clojure', send,
                        "let b:acid_ns_strategy='ns:user'"
                    ])
Exemple #3
0
    def on_handle(self, msg, *_):
        if 'no-info' in msg.get('status', []):
            warning(self.nvim, "No information for symbol")
            return

        try:
            lines = self.transform(msg)
        except Exception as e:
            warning(self.nvim, "Couldn't transform msg into doc.")
            log_error(e)
            return

        no_doc_buffer = self.doc_buf_nr is None
        buf_win_nr = self.nvim.funcs.bufwinnr(self.doc_buf_nr)
        doc_len = len(lines)

        if no_doc_buffer or buf_win_nr == -1:
            cmds = ['file acid://doc', 'wincmd p']

            self.doc_buf_nr = build_window(
                self.nvim,
                close=1,
                commands=cmds,
                throwaway=1,
                orientation="leftabove {} split".format(doc_len))
        else:
            self.nvim.command('{} wincmd w | resize {} | wincmd p'.format(
                buf_win_nr, doc_len))

        log_debug(lines)
        self.nvim.buffers[self.doc_buf_nr][:] = lines
Exemple #4
0
    def on_pre_handle(self, *_):

        no_shared_buffer = self.buf_nr is None
        has_no_window = self.nvim.funcs.bufwinnr(self.buf_nr) == -1

        if no_shared_buffer or has_no_window:
            cmds = ['file acid://meta-repl',
                    'nnoremap <buffer> <localleader><CR> :e<CR>',
                    'nnoremap <buffer> <localleader><localleader> kdggjdG',
                    'nnoremap <buffer> <localleader>D kdgg',
                    'nnoremap <buffer> <localleader>d jdG',]
            if self.nvim.funcs.exists(':AnsiEsc'):
                cmds.append('AnsiEsc')

            self.buf_nr = build_window(
                self.nvim, close=1, commands=cmds, throwaway=1
            )

        use_cmd_win = bool(self.nvim.vars.get(
            'acid_meta_repl_use_cmd_window', False
        ))

        if use_cmd_win:
            no_cmd = self.cmd_buf_nr is None
            has_no_cmd_window = self.nvim.funcs.bufwinnr(self.cmd_buf_nr) == -1

            if no_cmd or has_no_cmd_window:
                send = """:call AcidSendNrepl({
                    'op': 'eval', 'code': join(getline(1, '$'), '\\n')
                    }, 'MetaRepl')<CR>""".splitlines()

                send = "map <buffer> <silent> <localleader><CR> {}".format(
                    "".join(map(str.strip, send))
                )
                meta_repl_window = self.nvim.funcs.bufwinnr(self.buf_nr)
                nvim.command("{} wincmd w".format(meta_repl_window))

                self.cmd_buf_nr = build_window(
                    self.nvim,
                    close=1,
                    throwaway=1,
                    orientation="rightbelow 20 split",
                    commands=['file acid://scratchpad',
                              'set ft=clojure',
                              send,
                              "let b:acid_ns_strategy='ns:user'"]
                )
Exemple #5
0
    def prepare_payload(self):
        send = "map <buffer> <silent> <localleader><CR> {}".format("".join(
            map(
                str.strip, """:call AcidSendNrepl({'op': 'eval',
                'code': join(getline(1, '$'), '\\n')}, 'MetaRepl')
                <CR>""".splitlines())))

        cmds = [
            'file acid://scratch-buffer-{}'.format(random.randint(0, 100)),
            'set ft=clojure',
            'let b:acid_ns_strategy="ns:user"',
            'nmap <buffer> <silent> q :bd! %<CR>',
            send,
        ]

        build_window(
            self.nvim,
            throwaway=1,
            orientation="rightbelow 20 split",
            commands=cmds,
        )

        return None
Exemple #6
0
    def on_handle(self, msg, *_):
        if not 'no-info' in msg.get('status', []):
            name = msg['name']
            ns = msg.get('ns', '')

            arglist = msg.get('arglists-str', [])
            doc = msg.get('doc', '')
            javadoc = msg.get('javadoc', '')
            added = msg.get('added', '')
            super_ = msg.get('super', '')
            modifiers = msg.get('modifiers', [])
            see_also = msg.get('see-also', [])
            interfaces = msg.get('interfaces', [])

            if arglist:
                fn_calls = ["({}{})".format(name, " {}".format(i) if i else "")
                           for i in arglist[2:-2].split('] [')]
            else:
                fn_calls = [name]

            if see_also:
                see_also = ["https://clojuredocs.org/{}".format(i)
                            for i in see_also]

            docl = [i for i in [
                " ".join(fn_calls),
                ns,
                modifiers,
                " ",
                javadoc,
                *doc.split('\n'),
                " ",
                added and "Since version {}".format(added),
                interfaces and "Implements: {}".format(
                    ",".join(interfaces)
                ) or "",
                super_ and "Extends: {}".format(super_) or "",
                see_also and "See also:" or "",
                *see_also,
            ] if i ]

            no_doc_buffer = self.doc_buf_nr is None
            buf_win_nr = self.nvim.funcs.bufwinnr(self.doc_buf_nr)
            doc_len = len(docl)

            if no_doc_buffer or buf_win_nr == -1:
                cmds = ['file acid://doc',
                        'wincmd p',
                        ]

                self.doc_buf_nr = build_window(
                    self.nvim, close=1, commands=cmds, throwaway=1,
                    orientation="leftabove {} split".format(doc_len)
                )
            else:
                self.nvim.command('{} wincmd w | resize {} | wincmd p'.format(
                        buf_win_nr, doc_len
                ))

            info(self.nvim, "Documentation  for {}/{}".format(ns, name))
            log_debug(docl)
            exec_cmd = "bd {} | au! AcidDoc".format(self.doc_buf_nr)

            self.nvim.buffers[self.doc_buf_nr][:] = docl
            self.nvim.command('augroup AcidDoc')
            self.nvim.command('au!')
            self.nvim.command(
                'au CursorMoved * exec "{}"'.format(exec_cmd))
            self.nvim.command('augroup END')

        else:
            warning(self.nvim, "No information for symbol")