Not much to add to the question. I'm not looking for function autocompletion which is described in several posts, particularly 56984.
I find myself constantly doing asc//Keys
and then typing the full thing.
Not much to add to the question. I'm not looking for function autocompletion which is described in several posts, particularly 56984.
I find myself constantly doing asc//Keys
and then typing the full thing.
While this may not strictly address your concern, I’d like to present an alternative that might be useful.
Thinking of something balanced regarding your needs, I came up with a function that allows copying the keys from associations. I included an option to present the association in a Dataset
. Here’s the implementation:
CurrentValue[EvaluationNotebook[], {InputAliases, "cck"}] =
RowBox[{"ClickToCopyKey", "[",
TemplateBox[{}, "SelectionPlaceholder",
DisplayFunction -> (FrameBox["\"Association\""] &)], "]"}];
addCompletion = FE`Evaluate[FEPrivate`AddSpecialArgCompletion[#]] &;
addCompletion["ClickToCopyKey" -> {{None}, {"DatasetFormat"}}];
ClickToCopyKey[asc_Association,
type : (Automatic | "DatasetFormat") : Automatic] :=
Module[{assoc},
assoc = Association@KeyValueMap[Rule @@ {ClickToCopy[#1], #2} &]@asc;
Switch[type, Automatic, assoc, "DatasetFormat", Dataset[assoc]]]
The alias implementation is due to @CarlWoll and can be found at:
Input alias having a placeholder which gets selected when the alias is used
The argument completion is due to @Szabolcs, and can be found at:
Argument completions for user-defined functions
I think you can build a dynamic selection function using PopupMenu
or with a DialogInput
(I'm working on it), as I put in the comments, but ClickToCopyKey
might be a good start if you just want to copy keys.
Please try ClickToCopyKey
and comment if you find it useful for something you need.
Note: You might also want an implementation where clicking on a key retrieves its corresponding value.
No
(this is where I add more characters to make this acceptable as an answer)
edit: typing asc//Keys
and then copying the key is a great way to do what the OP wants to do
AssociationKeyPicker[asc]
? $\endgroup$AssociationKeyPicker
is, that doesn't show up when I search for it anywhere. Is it a resource function I can't find? I'm looking for something that (e.g.) when I typeasc[longkeyname]
it autocompletes after just typingasc[lon
kinda like symbol autocompletion. $\endgroup$AssociationKeyPicker
is actually something I came up with to dynamically select keys from an Association using an interactive dropdown menu. I now realize you're asking for inline autocompletion when typing something likeasc[longkeyname]
, similar to symbol autocompletion. Unfortunately, Mathematica doesn't natively support that kind of autocompletion for Association keys. $\endgroup$AssociationKeyPicker
to share as a possible solution. I'm thinking of adding it to my response as a utility for dynamic key selection from an Association. How would you prefer it to work—would you like it to show the keys in a separate window with options, or would you prefer using aPopupMenu
right within the notebook? $\endgroup$