|
From: | Sudeepam Pandey |
Subject: | Re: option for enabling/disabling auto-suggest feature |
Date: | Thu, 3 May 2018 02:39:28 +0530 |
On 05/02/2018 11:12 AM, Sudeepam Pandey wrote:
> > > On Wed, May 2, 2018 at 9:34 PM, Rik <address@hidden> wrote: > > > Here is a demo I made just now... It is able to do the job of a on/off feature. The initial try/catch block is for the first time when the preference 'autosuggestion' will not be present in the group 'Octave'. Later on, the user can turn the feature on/off using setpref(); > > ------------------------------------------------------------ ------------------------------ ------------------------------ ------------- > > function txt = __suggestions__(fcn) > > try > getpref ("Octave", "autosuggestion"); > catch err > if (strcmpi (err.message, "getpref: preference autosuggest does not exist in GROUP Octave")) > addpref ("Octave", "autosuggestion", true); > endif > end > > pref = getpref ("Octave", "autosuggestion"); > if (pref == false) > disp ("Disabled"); > elseif (pref == true) > disp ("Did you mean any of the following..."); > endif > > endfunction; > > ------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------------- > > Note: It is a sample code, it may not strictly adhere to the Octave style of coding.
Looks good. For performance, you can use the try/catch block to get the value of the preference just once. See below
pref = false;
trycatch err
pref = getpref ("Octave", "autosuggestion");
if (strcmp (err.message, "getpref: preference autosuggest does not exist in GROUP Octave"))pref = true;
addpref ("Octave", "autosuggestion", true);
endif
endelse
if (pref == true)
disp ("Did you mean any of the following...");
disp ("Disabled");
endif
endfunction
>> >> 2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are... >> a) How do we do it? What files do we tweak? >> b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook? > > If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook. > > > I understand. There are a few doubts however... > > 1) Will this file, libinterp/corefcn/graphics.cc cover all the major properties (figure, line, axis, etc...)?
Yes.See libinterp/corefcn/variables.
> 2) Can you tell me where I can find missing_function_hook() so that I could make missing_property_hook() similar to that?cc:2581.
--Rik
[Prev in Thread] | Current Thread | [Next in Thread] |