How to disable ginput() in Octave? - plot

I want to make Octave work only in terminal mode and options like
--no-gui
--no-window-system
-W
don't help me avoid ginput() command.

You can overload ginput at the beginning of the octave session (in your .octaverc file for instance)
ginput = #() warning("ginput has been disabled")
This is defining a new function with the same name. The original ginput will "screened" by this new function. But a clear ginput would get rid of the new definition. Then a new call to ginput would search for it in memory (where it is not anymore), then in the path. It will eventually find the original one.
If you control the installation of octave on your customer's machine, just get rid of ginput.m file.

Related

How to scroll up in Vim buffer with R (using Nvim-R)

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.

Use bash_profile aliases in jupyter notebook

It looks like my Jupyter notebook picks up everything that I export in my .bash_profile, but nothing that I alias.
I think ! uses bin/sh, so it's understandable that the aliases from the bash profile don't port over, but the %%bash magic also does not pick up the aliases I've written.
Is there a way to make the aliases in my bash profile available through ! (ideally) or, at the least, using %%bash?
This seems to work (python3, modified from a hack I found in a jupyter issue)
import subprocess
lines = subprocess.check_output('source ~/.bash_profile; alias',shell=True).split(b'\n')
manager = get_ipython().alias_manager
for line in lines:
line = line.decode("utf-8")
split_index = line.find('=')
cmd = line[split_index+1:]
alias = line[:split_index]
cmd = cmd[1:-1]
print ("ALIAS:{}\t\tCMD:{}".format(alias,cmd))
manager.soft_define_alias(alias, cmd)
Here's another alternative, which is less a solution than a workaround: you can define aliases locally to the notebook using the %alias magic, and make those aliases available in the future using the %store magic. More alias trickiness here: https://github.com/ipython/ipython/wiki/Cookbook:-Storing-aliases
More on the %store magic here: http://ipython.readthedocs.io/en/stable/config/extensions/storemagic.html
The next step is hacking the %store magic to persist these aliases: https://github.com/ipython/ipython/blob/master/IPython/extensions/storemagic.py
For posterity, here are the results of some experiments I ran before finally finding a solution:
I sourced my .bash_profile in a %%bash cell. From within that cell, I was able to interrogate the values of variables I defined in my .bash_profile, and was able to list aliased commands by invoking alias. However, I was still not able to use aliased commands. Additionally, variables defined in my .bash_profile were only accessible inside the cell with the source call: trying to access them in subsequent %%bash cell didn't work, and the alias command also failed. More interesting still: if I sourced using !, I wasn't able to interrogate variables defined in my bash profile nor list my aliases with ! shell commands in the same cell.
Suffice it say, the %%bash magic is finicky.

Run bash command for currently selected line

I'd like to be able to hit a shortcut like cmd-shift-r and have that automatically run a bash command, say, mix test test/turtle/api/v3_test.exs:72.
In other words: mix test {FILE_ACTIVE}:{FILE_ACTIVE_LINE_NUMBER}
What is the best way to accomplish this? Is there an atom package that takes care of this or something I could write quickly myself?
Thanks!
There is a fairly low-fi way to get this to work using your init.coffee load this by going to File → Init Script... or by choosing Application: Open Your Init Script from the Command Palette.
Add the following to the bottom of your init.coffee:
atom.commands.add 'atom-text-editor',
'custom:execute-this-test': ->
if editor = atom.workspace.getActiveTextEditor()
row = editor.getCursors()[0].getBufferRow() + 1
path = editor.buffer.file.path
{spawn} = require 'child_process'
mix = spawn 'mix', ['test', "#{path}:#{row}"]
mix.stderr.on 'data', (data) ->
atom.notifications.addError data.toString()
mix.stdout.on 'data', (data) ->
atom.notifications.addInfo data.toString()
mix.on 'exit', (code) ->
atom.notifications.addInfo "Exited with Code #{code}"
Save the file with Ctrl-S and reload the text editor with Ctrl-Alt-R.
Once Atom has restarted, find the line in the file you want to execute the code against and open the Command Palette with Ctrl-Shift-P and search for Execute This Test.
You may want to tweak the code to be reduce the amount of output it generates, however the above is probably enough to get you started. If you wanted to optimize the workflow even further you can create a Keybinding.

Evaluating buffer until the cursor

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).

Changing the home key behavior in an R session in emacs

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.

Resources