sogaiu / ajrepl

A mode for interacting with a Janet REPL
6 stars 1 forks source link

There is no equivalent of Emacs' `eval-defun` #2

Open sogaiu opened 2 hours ago

sogaiu commented 2 hours ago

It was pointed out on Zulip that there is no command to send a top-level expression.

sogaiu commented 2 hours ago

Some points of consideration include:

If tree-sitter functionality is used, the cost involved to account for the above points may be reasonable.

A non-tree-sitter-based implementation that tries to handle the items above seems like it would be (much?) more costly. One idea is to provide something simpler.

Another consideration is how to handle detection of tree-sitter capabilities and behave appropriately.

sogaiu commented 2 hours ago

Here is an initial attempt (note: this is on a separate branch).

A new command named ajrepl-send-top-level-exression is provided. It is bound to C-M-x (what eval-defun's keybinding is locally). It's also exposed via the Ajrepl menu.

The following method was used to provide an alternate implementation in case tree-sitter functionality is not available:

;; https://emacs.stackexchange.com/a/30086
(when (not (require 'ajrepl-ts nil 'noerror))
  (defun ajrepl-send-top-level-expression ()
    "Send top-level expression containing point."
    (interactive)
    (save-excursion
      (let ((beg nil)
            (end nil))
        (ajrepl--column-zero-target-backward)
        (setq beg (point))
        (forward-sexp)
        (setq end (point))
        (ajrepl-send-region beg end)))))

Some rearrangement of code was done to get the above to work out.