Fork me on GitHub
#cursive
<
2022-01-18
>
Dumch10:01:52

It’s possble to use `f` as ‘form’ for selecting in visual mode in spacemacs (by default) and vim (with https://github.com/guns/vim-sexp). For example, typing `daf` in visual mode will delete a form (“text”, (…), […}, {…}) under the cursor. Is it possible to achieve something like this in idea with cursive?

Dumch08:01:40

managed to solve it with Idea LivePlugin

import com.intellij.openapi.actionSystem.CommonDataKeys
import liveplugin.registerAction
import liveplugin.show

show("Current project: ${project?.name}")

registerAction("SelectForm", "ctrl alt shift W", function = { event ->

    val project = event.project
    val editor = CommonDataKeys.EDITOR.getData(event.dataContext)
    if (project == null || editor == null) return@registerAction

    val actionManager = com.intellij.openapi.actionSystem.ActionManager.getInstance()
    val actionEditorMatchBrace = actionManager.getAction("EditorMatchBrace")
    actionEditorMatchBrace.actionPerformed(event)
    val formStart = editor.caretModel.offset
    actionEditorMatchBrace.actionPerformed(event)
    val formEnd = editor.caretModel.offset
    editor.selectionModel.setSelection(formStart, formEnd)
})
if (!isIdeStartup) show("Loaded 'insertClojureComment' action<br/>Use 'Ctrl+Alt+Shift+W' to run it")

Dumch10:01:30

does anyone use some shortcut to insert a #_ comment on any form under a cursor with `idea/cursive`? originally asked https://clojurians.slack.com/archives/C053AK3F9/p1642494215468300

Dumch15:01:03

managed to solve it with idea LivePlugin + ideavim ideavimrc part:

nnoremap <Leader>c :action insertClojureCommentAtTheFormStart<cr>
live plugin part
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.editor.Document
import liveplugin.executeCommand
import liveplugin.registerAction
import liveplugin.show
import kotlin.math.max

show("Current project: ${project?.name}")

registerAction("insertClojureCommentAtTheFormStart", function = { event ->
    val project = event.project
    val editor = CommonDataKeys.EDITOR.getData(event.dataContext)
    if (project == null || editor == null) return@registerAction

    val actionManager = com.intellij.openapi.actionSystem.ActionManager.getInstance()
    val document = editor.document
    val caretIndex = editor.caretModel.offset
    val currentChar = document.text[caretIndex]

    val startFormChars = charArrayOf('"', '(', '{', '[')

    if (currentChar.isLetterOrDigit() && isPreviousEmpty(document, caretIndex)) { //beginning of a word
        /* just insert here */
    } else if (startFormChars.contains(currentChar)) {
        /* just insert here */
    } else {
        val actionEditorMatchBrace = actionManager.getAction(":cursive.actions.paredit/backward-up")
        actionEditorMatchBrace.actionPerformed(event)
    }
    document.executeCommand(project, "insertClojureCommentAtTheFormStart") {
        document.insertString(editor.caretModel.offset, "#_")
    }
})

fun isPreviousEmpty(document: Document, caretIndex: Int) =
        document.text[max(caretIndex - 1, 0)] == ' '

jmv17:01:11

hey all! would anyone be able to recommend the best way to debug a lein middleware issue? for context: i'm unable to sync a project in cursive with the error log saying it's unable to resolve the middleware function. the middleware works fine when calling lein from the CLI or if i create a lein run configuration.