Command completion in mathematica : suggest rules/options - reflection

In current version of Mathematica these keyboard shortcuts are quite handy
Ctrl+K completes current command
GraphPl -> press Ctrl+K -> GraphPlot
Ctrl+Shift+K completes current command and adds argument placeholders which could be replaced with actual values with tab key
GraphPl -> press Ctrl+Shift+K -> GraphPlot[{vi1->vj1,vi2->vj2,...}]
However I couldn't find any keyboard option to show associated settings/options
For instance Say If I need to plot a graph with different layouts, I know I need to set Method with one of these Possible settings
"CircularEmbedding"
"RandomEmbedding"
"HighDimensionalEmbedding"
"RadialDrawing"
"SpringEmbedding"
"SpringElectricalEmbedding"
Two things
First How to autocomplete these options , is there any shortcut key ?
GraphPlot[sg, Method -> <what keyboard shortcut to display all possible options>]
Second how to generate following PopupMenu list programmatically
list={
"CircularEmbedding"
, "RandomEmbedding"
, "HighDimensionalEmbedding"
, "RadialDrawing"
, "SpringEmbedding"
, "SpringElectricalEmbedding"
}
Manipulate[GraphPlot[sg, Method -> m], {m, list}, ControlType -> PopupMenu]
Is there any way to introspect Mathematica functions and access method Metadata similar to the way it could be done in other programming languages, Like using reflection in Java ?

I don't believe there is any included function to auto-complete a string. I also cannot recall a way to view all valid settings for a particular option, other than searching the help files.
You can expedite input with the Options Inspector settings InputAliases and InputAutoReplacements, allowing entry by EsctxtEsc or txtSpace.

Draft : work in progress ...
This is the nearest I could reach so far, though It needs loads of enhancement, Adding it as it is hoping to get some Ideas from community. If anyone could help enhance it further, Or suggest any Idea, It would really be appreciated.
ruleOfRule[list_] := Map[Rule[#, #] &, list];
Manipulate[
GraphPlot ## {{"A" -> "B", "B" -> "C", "C" -> "A"},
options}, {{options, {}}, ruleOfRule[Options[GraphPlot]]},
ControlType -> CheckboxBar]

Related

How to search previously executed commands in the Julia REPL?

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

How to get rid of the yellow highlighted background in old search text in Qt Creator?

I have searched for the string "as" a few hours before in Qt Creator.
However it seems to be still active and whenever I type "as" again it is highlighted automatically.
And I can't get rid of it.
It looks like this:
Do you know what could be the problem and how to remove the yellow highlight?
According to your comment, you are using FakeVim so you can set whether or not search results are highligthed in Qt Creator ( Tools > Options > FakeVim). And if you want to clear the highlighted results, just type :nohlsearch in FakeVim.
If you are using FakeVim you can set up a user command in Tools -> Options -> FakeVim -> User Command Mapping. E.g., User command #1 = ":noh". Then you can use 'Alt+V 1' to get rid of the yellow highlight.

Modify or hook into Jupyter's tab completion

I was wondering if there was a way to modify Jupyter Lab or Notebook's tab-complete functionality. For example, if I type "\alpha", and then press the tab key, I will get the UTF-8 character "α" in the cell.
Is there any way that I can do a custom "[string without spaces]" to tab-complete into some specific UTF-8 character or string?
e.g. "\implies" + tab -> "⇒"
I can see a large number of use cases for this in my programming life, so I was wondering if Jupyter (Lab or Notebook) offered the ability to modify some settings (or load in a file) that maps strings to a tabbed output. Or is there a different idea that you could use to implement this?
Thanks!
Jupyter is (based on) IPython and it's completion engine - we can make use of it.
Update: you can override latex_symbols dict to get the behavior you want:
from IPython.core.latex_symbols import latex_symbols
latex_symbols['\\implies'] = '⇒'
You should be able to build upon this example to make it work with a whole range of characters.
Initial answer/another solution: you can hook into IPython completers, though it would not work exactly as you wish: it won't replace the text, but just append a special character. Here is an example:
from IPython import get_ipython
def implies_competer(ipython, event):
return ['⇒']
ipython = get_ipython()
ipython.set_hook('complete_command', implies_competer, re_key='.*implies')
Then when you type (the space after the keyword is important):
and then press tab, you will get:

How to change command-palette scroll key bindings in atom

I'm a new Atom user and I want to override the Atom command palette (shift-ctrl-p) scrolling key bindings to something more vi friendly like
ctrl-n and ctrl-p instead of the annoying arrow keys (which force me to take my hands off the home row).
Just to be clear, I don't want to change the key binding that brings up the command palette, but the key bindings you use to scroll through the list once it's up:
I can only find a binding to override the command palette toggle:
As you can see in the following config file, I was able to override the autocomplete scrolling, and I hope to do the same with the command palette. I've tried 'command-palette:up' ,'command-palette:down' and 'command-palette:move-up' etc. to no avail.
Here's is my keymap.cson.
# Atom Flight Manual:
# https://atom.io/docs/latest/using-atom-basic-customization#cson
#vt add
'body atom-text-editor.autocomplete-active':
'ctrl-p': 'autocomplete-plus:move-up'
'ctrl-n': 'autocomplete-plus:move-down'
'alt-p': 'autocomplete-plus:page-up'
'alt-n': 'autocomplete-plus:page-down'
'home': 'autocomplete-plus:move-to-top'
'end': 'autocomplete-plus:move-to-bottom'
# vim-plus ex mode 2016-04-18
'atom-text-editor.vim-mode-plus.normal-mode':
':': 'vim-mode-plus-ex-mode:open'
'!': 'vim-mode-plus-ex-mode:toggle-setting'
# add cmd palette key bindings --> These do not work.
'body .native-key-bindings':
'ctrl-p': 'command-palette:up'
'ctrl-n': 'command-palette:down'
#vt end
I've been really impressed with the key binding support in Atom thus far. I'd be really surprised if it couldn't handle this but, alas, I think this might be the case.
Does anyone know of a way to do this?
Atom 1.7.2, linux
I was able to get single line scroll to work, but not page scroll to work with the following in my keymap.cson:
'atom-workspace':
# these work
'ctrl-p' : 'core:move-up'
'ctrl-n' : 'core:move-down'
# these don't work
'alt-p' : 'core:page-up'
'alt-n' : 'core:page-down'
It would be nice to have page scroll as well, but I should be able to narrow down the list down by typing in text, so I don't foresee needing page-up, page-down all that often.
Now I'm happy.
To target keybindings for just the command palette, you can find an appropriate selector by looking in the command-palette repo keymaps: https://github.com/atom/command-palette/blob/v0.43.5/keymaps/command-palette.cson
This suggests the use of the .command-palette selector, which seems more appropriate then atom-workspace.
'.command-palette':
'ctrl-n': 'core:move-down'
'ctrl-p': 'core:move-up'
I was not able to find a mapping to scroll a page at a time within the command palette, though I'm sure someone else can figure it out. The keyboard page up/down keys have no effect so mapping to core:page-down etc. is not going to work.

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

Resources