meain / evil-textobj-tree-sitter

Tree-sitter powered textobjects for evil mode in Emacs
Apache License 2.0
197 stars 14 forks source link

Problems with R #74

Closed jsilve24 closed 1 year ago

jsilve24 commented 1 year ago

Thanks for putting this package together. I am very excited to use it. Trying it out things seem to work as expected when working in python. Not so much for R.

For example, trying any of the following bindings out in R inevitably ends with a "No [function.outer] text object found."

(define-key evil-normal-state-map (kbd "]f") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer")))
;; Goto start of previous function
(define-key evil-normal-state-map (kbd "[f") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" t)))
;; Goto end of next function
(define-key evil-normal-state-map (kbd "]F") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" nil t)))
;; Goto end of previous function
(define-key evil-normal-state-map (kbd "[F") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" t t)))

;; bind `function.outer`(entire function block) to `f` for use in things like `vaf`, `yaf`
(define-key evil-outer-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.outer"))
;; bind `function.inner`(function block without name and args) to `f` for use in things like `vif`, `yif`
(define-key evil-inner-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.inner"))

;; You can also bind multiple items and we will match the first one we can find
(define-key evil-outer-text-objects-map "a" (evil-textobj-tree-sitter-get-textobj ("conditional.outer" "loop.outer")))

Any advice?

meain commented 1 year ago

There was a mapping missing for ess-r-mode in the package. #75 should fix it.

jsilve24 commented 1 year ago

Hmm... I just pulled the most recent version and I am still getting the same result. No ’function.outer’ text object found [2 times]

Here is the R code I am working with:

r2_internal <- function(eta.hat, eta){
  resid <- eta - eta.hat
  ## variance / sum of squares being defined as total variation
  ## (trace of covariance matrix)
  var.res <- apply(resid, c(3), function(x) sum(diag(var(t(x)))))
  var.tot <- apply(eta, c(3), function(x) sum(diag(var(t(x)))))

  ## Note as we are doing this all in the latent space (under the multinomial)
  ## it guarantees that 1-var.res/var.tot is equal to var_fit/(var_fit+var_res)
  ## exactly as discussed in Gelman 2019
  return(1-var.res/var.tot)
}

Here is my config

(use-package evil-textobj-tree-sitter
  :straight (evil-textobj-tree-sitter :type git
                      :host github
                      :repo "meain/evil-textobj-tree-sitter"
                      :files (:defaults "queries"))
  :config
;; bind `function.outer`(entire function block) to `f` for use in things like `vaf`, `yaf`
(define-key evil-outer-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.outer"))
;; bind `function.inner`(function block without name and args) to `f` for use in things like `vif`, `yif`
(define-key evil-inner-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.inner"))

;; You can also bind multiple items and we will match the first one we can find
(define-key evil-outer-text-objects-map "a" (evil-textobj-tree-sitter-get-textobj ("conditional.outer" "loop.outer")))

;; Goto start of next function
(define-key evil-normal-state-map (kbd "]f") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer")))
;; Goto start of previous function
(define-key evil-normal-state-map (kbd "[f") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" t)))
;; Goto end of next function
(define-key evil-normal-state-map (kbd "]F") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" nil t)))
;; Goto end of previous function
(define-key evil-normal-state-map (kbd "[F") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" t t))))

And I did confirm that I have pulled and built the most recent version that you pushed a few hours ago.

jsilve24 commented 1 year ago

Appologies, please disregard, I think I found the problem in my own config. I think your fix did indeed fix things.