VSCode: disable parentheses when autocompleting functions in R - r

When a function is autocompleted it always adds brackets at the end. as an example, I want to use mean: I type mea > VSCode offers mean > I hit tab > I get mean(). But what I want to get is mean.
ideally I would be able to hit different shortcuts that would let me pick the options (with brackets, opening bracket only, no brackets), but I would also be happy with just disabling the () entirely.
This question has settings for how to do this in python, but I haven't been able to find a way to do this in R (or as a global setting that applies to all languages)
VSCode add parentheses when autocompleting functions
Note: I know about the editor 'auto closing brackets' setting, but this only works when I am doing the typing, not for auto complete.

Related

Use Julia with Notepad++ and AutoHotkey

In practice I prefer to write R codes with Notepad++ and NppToR, where you can use the default shortcut keys to achieve the following functions:
F8: Pass line or selection
Shift+F8: Pass to point of cursor (from the very beginning)
Ctrl +F8: Pass entire file at once
Ctrl+Shift+F8: Pass by source (i.e., source("C:/Users/lenovo/Desktop/yourRcode.r"))
It is said that Julia is as simple as R or Python, but much faster than the latter two, almost as fast as C or Fortran. Thus, I try to use Julia to write codes.
According to julia-NotepadPlusPlus, we can use Julia with Notepad++ and AutoHotkey, where one can achieve the following goals:
Win-F12 -> Start Julia
Left_Shift-Enter -> Evaluate current line
Right_Shift-Enter -> Evaluate selected block
I want to write a NppToJulia.ahk file to link Notepad++ and Julia, achieving the functions as the R-NpptoR-Notepad++ way:
F8: Pass line or selection
Shift+F8: Pass to point of cursor (from the very beginning)
Ctrl +F8: Pass entire file at once
Ctrl+Shift+F8: Pass by source (i.e., include("C:/Users/lenovo/Desktop/yourJuliaCode.jl"))
As I know nothing about AutoHotkey, can anyone give me some hints?

Taboo Script or Undesired Note

I included in my package the following scripts;
foo <- function(X){ Y <-substitute(X);cat(Y)}
fooo <-function(){
foo(aaa)
}
Then R cmd check said the undesired note:
checking R code for possible problems ... NOTE fooo: no visible binding for global variable 'aaa'
How to remove this note or I have to change the definition of foo()?
Details
The foo iscat() without double quote "".
Surrounding character by double quote bother me, and I wanted to remove it by making foo()
> foo(aaa)
aaa
which is same as cat("aaa").
But, R CMD check thinks the pseudo object aaa does not exist.
I want to remove this note. In past, such note did not appear. But today it appears.
Use globalVariables:
globalVariables('foo')
It’s … not a great solution — in particular, you have to do this for every name you use in this way.
It’s therefore better to limit NSE in package code to the absolute necessary. Pure convenience functions such as yours need to be weighed carefully against this.

Emacs ESS indentation and auto-completion

There are a number of useful variables to control TAB key indentation and completion in Emacs (R) code chunks, when using ESS mode.
ess-tab-complete-in-script first indents lines and, if there is nothing to indent, autocompletes the word.
"With great power, comes great responsibility", so, when fast indenting your code, you might end up completing code without noticing with catastrophic results. Therefore you can refine things with the variable
ess-first-tab-never-complete. For example: if 'unless-eol, TAB completes only when cursor is at the end of the line; if 'symbol, it completes also in the middle of a line, but not if you are in the middle of a word; etc (read doc for more
with F1vess-first-tab-never-complete).
The problem is that, at least for me, TAB is bound to ess-noweb-indent-line, but the command governing indent-or-complete behaviour is: ess-indent-or-complete. So I use to fix the tab binding with:
(add-hook 'ess-mode-hook
'(lambda()
(local-set-key (kbd "<tab>") 'ess-indent-or-complete)
))
This works, but I wonder if this is the proper way. In the manual I don't see any prompt to hook to ESS mode and reset tab binding.
Do you know which is the canonical way to perform this?
There are a couple of reasonable ways to set the tab key (or any key, for that matter) for a specific mode. The first you alluded to in your answer, by setting the key locally via a mode hook. Note, though, that it's generally preferable to use a named function rather than a lambda so that you can remove the hook later if you want to do so:
(defun ess-keys-hook ()
"Put a bunch of keybindings in here."
(local-set-key [tab] 'ess-indent-or-complete))
(add-hook 'ess-mode-hook 'ess-keys-hook)
The other option is to define the key in the relevant mode map, which you can do like so:
(define-key ess-mode-map [tab] 'ess-indent-or-complete)
Both ways are pretty commonly used, although my own preference is for the latter, as it strikes me as cleaner and more efficient.

Customizing the ESS environment for R

I am trying to optimize my ESS - R environment. So far I make use of the r-autoyas, I set intendation and stuff following style guides, in the mini-buffer there are eldoc hints for function arguments, and I have the option to press a key in order to find information about variable at point (more here).
Are there any other things you use in order to have a nice R environment? Maybe non-ESS people have some nice things to add (I got that info of variable at point from looking at an Eclipser). One example could be an easy way to insert "just-before-defined" variables without typing the variable name (should be something for that?).
(Please help me to change the question instead of "closing" the thread if it is not well formulated)
I am not using autoyas as I find auto-complete integration a better approach.
Insertion of previously defined symbols is a general emacs functionality called 'dabbrev-expand' and is bound to M-/. I have this in my .emacs to make it complete on full symbols:
(setq dabbrev-abbrev-char-regexp "\\sw\\|\\s_\\|s.")
(setq dabbrev-case-fold-search t)
Another thing which I use extensively is imenu-based-jump-to-symbol-definition. It offers similar functionality to emacs tags, but just for open buffers in the same mode as the current buffer. It also uses IDO for queries:
Put imenu-anywhere.el into your emacs load path and add this:
(require 'imenu-anywhere)
(global-set-key [?\M-o] 'imenu-anywhere)
Now, if I do M-o foo RET emacs jumps to the function/class/method/generic definition of 'foo' as long as 'foo' is defined in one of the open buffers. This of course works whenever a mode defines imenu-tags. ESS defines those, so you should not need to add more.
There is also somewhere a collection of R-yas templates. I didn't get around to starting using them but my guess is that it's a pretty efficient template insertion mechanism.
[edit] Activate tracebug:
(setq ess-use-tracebug t)

VIM: Bijection between VIM Taglist elements and code snippets?

My Taglist in a C code:
macro
|| MIN_LEN
|| MAX_ITERATIONS
||- typedef
|| cell
|| source_cell
||- variable
|| len_given
Taglist elements (domain):
A = {MIN_LEN, MAX_ITERATIONS, cell, source_cell, len_given}
Code snippets (codomain):
B = {"code_MIN_LEN", "code_MAX_ITERATIONS", ..., "code_len_given"}
Goal: to have bijection between the sets A and B.
Example: I want to remove any element in A, such as the MIN_LEN, from A and B by removing either its element in A or B.
Question: Is there a way to quarantee a bijection between A and B so that a change either in A or in B results in a change in the other set?
I strongly doubt you can do that. The taglist plugin uses ctags to collect the symbols in your code and display them in a lateral split. The lateral split contains readonly information (if you try to work on that window, vim tells you that modifiable is off for that buffer).
What you want to achieve would imply quite complex parsing of the source code you are modifying. Even a simple task like automatic renaming (assuming you modify a function name entry in the taglist buffer and all the instances in your source are updated) requires pretty complex parsing, which is beyond the ctags features or taglist itself. Deleting and keeping everything in sync with a bijective relationship is even more complex. Suppose you have a printf line where you use a macro you want to remove. What should happen to that line? should the whole line disappear, or just the macro (in that case, the line will probably be syntactically incorrect.
taglist is a nice plugin for browsing your code, but it's unsuited for automatic refactoring (which is what you want to achieve).
Edit: as for the computational complexity, well, the worst case scenario is that you have to scout the whole document at every keystroke, looking for new occurrence of labels that could be integrated, so in this sense you could say it's O(n) at each keystroke. This is of course overkill and the worst method to implement it. I am not aware of the computational complexity of the syntax highlight in vim, (which would be useful to extract tags as well, via proper tokenization), but I would estimate it very low, and very limited in the amount of parsed data (you are unlikely to have large constructs to parse to extract the token and understand its context). In any case, this is not how taglist works. Taglist runs ctags at every vim invocation, it does not parse the document live while you type. This is however done by Eclipse, XCode and KDevelop for example, which also provide tools for automatic or semiautomatic refactoring, and can eventually integrate vim as an editor. If you need these features, you are definitely using the wrong tool.

Resources