I would like to change the behavior of the home key within an R session run from emacs. When I press the home key, it takes me all the way to the > prompt. I'd like the home key to take me to the start of the command entry (i.e., two points in from the start of the line). I assume that I can make this adjustments via my .emacs file; any guidance for the commands that I would need to add to that file would be appreciated. Thanks!
The behaviour you want is already available as C-a. You can rebind the home key with the following line:
(local-set-key (kbd "<home>") 'comint-bol)
There are a number of ways to get this to happen automatically when you are using the R session. I use something like the following:
;; Define the keybinding you want
(defun my-inferior-ess-mode-hook ()
(local-set-key (kbd "<home>") 'comint-bol))
;; add the key-binding to the hook that gets called whenever you start an R session:
(add-hook 'inferior-ess-mode-hook 'my-inferior-ess-mode-hook)
That's a bit much for a single key-binding, but you can extend the definition of my-inferior-ess-mode-hook to include a number of customizations you'd like to use.
Related
Is there a quick way to search old commands which were run in the Julia REPL? Using the up arrow to go back in time seems to have a limit on its history and it is also quite cumbersome.
One of the five REPL models available in Julia is the "Search mode" which allows you to search through previously executed commands from the REPL. You can click "Control" + "r" to open search mode like is shown below:
(reverse-i-search)`':
There is also a forward search available with "Control" + "s". You can read more about Julia's REPL Search mode here: https://docs.julialang.org/en/v1/stdlib/REPL/#Search-modes
In addition to "real" search, you can also enter the beginning of a previous line and scroll up in the history (using ↑ or Ctrl-P) to switch between all previously entered lines starting with the same prefix.
So, if you had previously entered x = some_complicated_expression, you can write x = and go up until the line you were looking for appears.
Checkout: https://kristofferc.github.io/OhMyREPL.jl/latest/features/fzf/#Fuzzy-REPL-history-search
Which will be easier to use than reverse-i-search
I'm a happy user of the Nvim-R plugin, but I cannot find out how to scroll up in the buffer window that the plugin opens with R. Say for instance that I have a large output in console, but I cannot see the top of it - how do I scroll up to see this? In tmux for instance there's a copy mode that quite handily lets you do this, but how is this done in the R buffer?
An example below where I'm very curious to see what's on the line above the one begining with "is.na(a)...". How can this be achieved?
I have scoured the documentation found here, but without luck.
The answer is apparently to use Ctrl+\ Ctrl+n according to this answer on the bugreports for NVim-R.
Here's what my output looks like when I output mtcars:
When I hit Ctrl+\ Ctrl+n, I can move the cursor and I get line numbers:
To get back to interactive, I just use i, the same way I normally would.
Apparently, if you are using neovim, then you can add let R_esc_term = 0 in your ~/.vimrc file and you can then use the escape key, but if you don't use neovim, you are stuck using the two ctrl commands ¯\_(ツ)_/¯.
As pointed out by ZNK, it is about switching to normal mode in Vim's terminal. This, however, can easily fail due to cumbersome keybinding. If such is the case, remap the default keybinding to something reasonable, say, by putting this in your .vimrc:
tnoremap jk <C-\><C-n>
This works for me in Linux running Vim 8.0 in terminal (e.g. does not require Neovim). As you can see, I use 'jk' to switch from insert to normal mode. One can use Esc instead of jk, however, this makes me unable to use up arrow to retrieve command line history as been reported elsewhere.
I recently upgraded from R 2.15 and an older version of ESS using Vincent Goulet's Windows 7 installer at http://vgoulet.act.ulaval.ca/en/emacs/. This includes ESS version 13.09. I also just installed R version 3.0.2.
My old workflow was to use C-c C-t (the default key binding) to run commands via ess-execute and send results to a temporary buffer. I found this incredibly useful for my workflow and style of R programming.
However with the new version this key binding has been removed. I searched around and could not find any other threads regarding this topic. I looked into ess-mode.el and found this line:
;; (define-key map "\C-c\C-t" 'ess-execute-in-tb)
Which is commented out. I see they have added the nice feature ess-describe-object-at-point but that doesn't allow for executing commands.
I'm not an emacs power-user so I tend to copy pieces of lisp into my .emacs and do minor edits to them. I tried (1) uncommenting the line above and (2) defining a new keybinding in my .emacs file the same place as the new keybindings in ESSShift Enter (http://www.emacswiki.org/emacs/ESSShiftEnter).
(add-hook 'ess-mode-hook
(lambda()
(local-set-key [(shift return)] 'my-ess-eval)
;; added Ctrl-Enter to stay on same line
(local-set-key [C-return] 'ess-eval-line)
;; Newest version of ESS got rid of C-c C-t for ess-execute add back
(local-set-key "\C-c\C-t" 'ess-execute-in-tb))
However, neither one of these methods worked.
My questions are: Is there a reason this keybinding was disabled in the new version? I.e. should I be using some other feature that has replaced it? If not, what is the best way to enable this keybinding again?
ESS keys were remodeled an year or so ago. C-c C-t is now bound to
dev-map which provides a bunch of useful functionality that you might want to
use in the future. So better not disable it. Your code should work. You probably
tried C-c C-t from the*R* buffer, but that one is inferior-ess-mode, not
ess-mode.
You better define your keys in ess-exta-map, this way it will work both in
ess-mode and inferior-ess-mode. Something like this:
(eval-after-load "ess-mode"
'(progn
(define-key ess-extra-map "\C-e" 'ess-execute-in-tb)))
The pain with eval-after-load is necessary because Vincent's distribution loads ess after the user init file has been loaded. If you load your ESS with (load "ess-site") then you can just leave (define-key ...) part in your .emacs.el .
Now C-c C-e C-e should execute your command.
I am adding this exact key to ESS development version. So, in the next version
you can remove the above code. Thanks for popping this up.
By the way C-RET is bound to
ess-eval-region-or-line-and-step. You might consider keeping it like that.
I am trying to create a key binding for "Evaluate buffer till here" in Emacs & ESS, which is situated in ESS => ESS Eval menu. Most of the commands in that menu are listed in help files (http://ess.r-project.org/Manual/ess.html, and in Emacs options), but this particular one is not. If I place following code in .emacs file:
(eval-after-load "ess-mode" '(define-key ess-mode-map (kbd "C-.") 'ess-eval-buffer-till-here))
I get a following message when trying to use the binding: Symbol´s function definition is void: ess-eval-buffer-till-here. Obviously I am calling for wrong name. What is the right name for this command and how can I see all of the commands for ESS?
So it's a menu item? Type C-hk and then select that item.
(Menus are implemented as keymaps, so this is just the normal describe-key functionality.)
You can also see the non-interactive call form of the last command with C-xESCESC or C-xM-:. It's easy to figure out the command name once you have that. (thanks event_jr)
For listing all commands, most modes will list all their key bindings in their docstring, so you can use C-hm to describe the modes in use in the buffer.
As there may be commands without bindings, you could also use M-x apropos-command to list them all (most likely specifying ^ess as a pattern, if it uses that as a consistent name space).
When you ask ESS to evaluate the following from a buffer (C-c, C-b, or similar)
par(ask=TRUE)
plot(1,1)
plot(2,1)
The interpreter goes into a infinite loop because ESS starts the R session with the argument --no-readline. The loop can be broken with C-g, but is there any way to get the interpreter to actually request user input?
A solution is to edit ess-r-d.el and remove the hard-coded --no-runtime option given to R, it is line 127 of the latest implementation.
Change
(let* ((r-always-arg
(if (or ess-microsoft-p (eq system-type 'cygwin))
"--ess "
"--no-readline "))
to
(let* ((r-always-arg
(if (or ess-microsoft-p (eq system-type 'cygwin))
"--ess "))
If there is a compiled version, you have to compile the .el to generate and replace the binary .elc file.
The file may be (the location of the directory depends on your OS)
in the site-lisp directory. Edit the .el file in emacs (^X^F) then do M-x byte-compile-file to generate the .elc.
if you installed from the whole zip/tar source package, in the lisp directory. In this case, after the change, perform a make followed with a make install.
You need of course to have write access to the .el and .elc files.
If you do not feel comfortable with the compilation of the .el file, you may simply remove it (.elc) and use only the .el version (should be only a slight performance difference).
(Strategies gathered from Google and RSiteSearches):
Do you see the prompt : "hit Return" in any of your session windows? If so ... hit .
If not, then try clicking in the plot window.
And if that fails, you should get control back with c-G.
Edit: A further strategy, admittedly not solving the ESS-non-interactivity problem: If you want to hold for user input, then readLines can be used:
input=file("stdin")
print(readLines(input,1))