radian icon indicating copy to clipboard operation
radian copied to clipboard

Autocomplete to include parentheses?

Open dylanjm opened this issue 7 years ago • 15 comments

Any way to set in the settings that autocomplete finishes function calls by providing the () at the end of a function name? I'm so used to having this feature that it always causes bugs in my code when working with rice

dylanjm avatar Dec 09 '17 06:12 dylanjm

Do you mean pairing opening brackets and close brackets?

randy3k avatar Dec 09 '17 06:12 randy3k

Yes

dylanjm avatar Dec 09 '17 13:12 dylanjm

There is no such feature right now. It should not be hard to implement it in a similar fashion of the auto match feature of Rstudio. 😎 AFAIK, other repls such as julia and IPython also do not auto match brackets. It keeps me wonder why....

randy3k avatar Dec 09 '17 14:12 randy3k

I can see why developers might want to limit bracket matching, sometimes they can be a pain when you don't need a second bracket. Especially the case for quotations though.

dylanjm avatar Dec 09 '17 14:12 dylanjm

Ah, I understand why other repls do not support auto bracketing. It is mostly because a terminal, in general, cannot distinguish between typing and pasting. For example, copying and pasting foo( may end up with foo() unless the terminal supports bracketed paste mode and the user triggers BPM correctly. There are more bizarre situations when multiple lines are involved.

Yes, it is possible to support auto bracketing. But there are also use cases that auto bracketing becomes problematic.

randy3k avatar Dec 09 '17 20:12 randy3k

With that said, I have added a new setting rice.auto_match with the default value set as FALSE. Check out the dev version and try.

randy3k avatar Dec 09 '17 20:12 randy3k

@randy3k This is great. I really appreciate you doing that. I wanted to say though that my original idea was that when you TAB-ENTER to autocomplete a function it would also provide the open and closing brackets for that function and place your cursor in-between those brackets. The console in Rstudio does this and I've posted a gif of what I mean below:

Autocomplete Function Brackets

Currently, rice will auto complete the function name but not provide the opening and closing brackets.

rice currently

Thanks for your time, and I understand if that's a little bigger than intended.

dylanjm avatar Dec 09 '17 22:12 dylanjm

Oic, rice uses R internal completion system and the system tells nothing about what is being suggested, eg whether the suggestion is a variable or a function.

I am afraid that it is impossible by now unless we implement a new completion system, which won’t happen any time soon.

randy3k avatar Dec 09 '17 22:12 randy3k

ahhh I see, well great. Thanks for implementing the bracket auto-complete

dylanjm avatar Dec 09 '17 22:12 dylanjm

This would be really great to have. Saving some keystrokes in the long run :)

pat-s avatar Mar 08 '19 10:03 pat-s

Hi Randy! It's been a few years and I love this tool you have created. I wanted to check in and see if there have been any changes to the codebase that would allow this functionality?

dylanjm avatar Aug 24 '19 16:08 dylanjm

unfortunately, there were not many changes in the completion system to allow this.

randy3k avatar Aug 24 '19 17:08 randy3k

I have the same issue as @dylanjm and it is a breaker for me as I am so used to using autocomplete at the RStudio console and having the brackets added automatically. Muscle memory!

francisbarton avatar Aug 03 '22 10:08 francisbarton

Great solution!!!

It works fine with these settings in VS code:

R version 4.2.3 (2023-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=es_ES.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=es_CL.UTF-8        LC_COLLATE=es_ES.UTF-8    
 [5] LC_MONETARY=es_CL.UTF-8    LC_MESSAGES=es_ES.UTF-8   
 [7] LC_PAPER=es_CL.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_CL.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base  

egoipse avatar Mar 21 '23 02:03 egoipse

is this supposed to work now? do I just have to update radian? :)

henningsway avatar May 10 '23 12:05 henningsway