On 05/03/2011 09:45 AM, Tommaso Cucinotta wrote:
> Il 02/05/2011 20:44, Richard Heck ha scritto:
>
>> The problem turns out to be simple. In ApplyParams(), in
>> FindAndReplace.cpp, we apply the document params to the find and replace
>> buffers.
>
> the sole reason we do that, is that we need to copy the language
> settings of the main document, in order to avoid that what we search &
> replace is detected as with the wrong language, w.r.t. what is typed
> within (there was a trac entry about that problem, too).
>
> Alternative solutions that were proposed included disabling at all the
> language highlighting and spellchecker in the F&R workareas (but after
> all I find them useful, i.e., when I search for something, the
> spellchecker can highlight that I typed a "typo", so it wouldn't be
> found, or it would be replaced causing problems etc.), but in the end
> I had found that "ugly" way of solving the issue in FindAndReplace.cpp:
>
> /// Apply to buf the parameters supplied through bp
> static void ApplyParams(Buffer &buf, BufferParams const & bp) {
>     ostringstream ss;
>     ss << "\\begin_header\n";
>     bp.writeFile(ss);
>     ss << "\\end_header\n";
>     istringstream iss(ss.str());
>     Lexer lex;
>     lex.setStream(iss);
>     int unknown_tokens = buf.readHeader(lex);
>     LASSERT(unknown_tokens == 0, /* */);
> }
>
> Probably we would need a BufferParams::setLanguage() method to use,
> here, instead of copying the whole parameters. Looking at
> BufferParams::readLanguage(), I would implement it as:
>
> bool BufferParams::setLanguage(std::string const &lang)
> {
>     Language const *new_language = languages.getLanguage(lang);
>     if (!new_language) {
>         // Language lang was not found
>         return false;
>     }
>     language = new_language;
>     return true;
> }
>
> Would you like such a solution ?
>
This looks to me like a simple and workable plan, especially if this is
really the only bit we need.

The other question, then, is how to reset the language when we switch
Buffers.

rh

Reply via email to