4coder»Forums
Mevius
13 posts
Love dark theme. Use it for everything. OS, browser, webpages, IDE, desktop background.
How to get autocomplete in .txt ?
Edited by Mevius on Reason: Initial post
From time to time I will be working on a single plain text file to write articles or essays. I really want 4coder code autocomplete feature to work within that txt file as well.

I watched the tutorial on using 4coder_default_hooks.cpp to modify type of file 4coder will handle. I tried to add another if condition to put txt files to it but it still treated txt file just like any other file that are not originally in 4coder_default_hooks.cpp

Currently the only way to implement this feature that I found is by adding .txt to extension section inside config.4coder. The result is colorful txt with some words highlighted when it match any C++ keywords in the typical essay txt file.

The official documentation is not clear. I may have missed something (big).

How to correctly get words autocomplete without C++ keywords auto highlight?

I just bought full version yesterday though have been the using the demo since it released. I'm new to customization.
Simon Anciaux
1337 posts
How to get autocomplete in .txt ?
Edited by Simon Anciaux on Reason: I'm wrong !
EDIT: look at the reply below, what I said was wrong.

I don't think there is a setting for that. I believe that the thing that populate the autocomplete list is the "treat as code" flags on the buffer. What you could do with the custom layer is create a new language context with no keywords in it.

Look at the default_file_settings function in 4coder_default_hooks.cpp and files in the languages folder.
nj
26 posts
How to get autocomplete in .txt ?
Afaik the "problem" is that the command `word_complete` is not bound to a key when the file opened is not marked as "code file".
The solution would be simply to rebind `word_complete`, e.g.
1
bind(context, '\t', MDFR_NONE,  word_complete);
on the key map that is used for non-code files as well.
Mevius
13 posts
Love dark theme. Use it for everything. OS, browser, webpages, IDE, desktop background.
How to get autocomplete in .txt ?
Which file do I look for the place that set the command "word_complete"?

I found the code mentioned in "4coder_generated/remapping.h". Is it the right one?

Do I just edit that file directly and recompile?

Mevius
13 posts
Love dark theme. Use it for everything. OS, browser, webpages, IDE, desktop background.
How to get autocomplete in .txt ?
mrmixer
EDIT: look at the reply below, what I said was wrong.

I don't think there is a setting for that. I believe that the thing that populate the autocomplete list is the "treat as code" flags on the buffer. What you could do with the custom layer is create a new language context with no keywords in it.

Look at the default_file_settings function in 4coder_default_hooks.cpp and files in the languages folder.


I tried editing default_file_settings in the 4coder_default_hooks.cpp directly by:
1. adding another if statement to match "txt" extension. Nothing happen after recompile.
2. adding another condition to
1
if (match(ext, "cpp") || match(ext, "h")...
into
1
if (match(ext, "cpp") || match(ext, "h") || match(ext, "txt")...
Recompile that one too and nothing happen.

Sorry for asking this noobies question. I'm new.
Allen Webster
476 posts / 6 projects
Heyo
How to get autocomplete in .txt ?
nicoco
Afaik the "problem" is that the command `word_complete` is not bound to a key when the file opened is not marked as "code file".
The solution would be simply to rebind `word_complete`, e.g.
1
bind(context, '\t', MDFR_NONE,  word_complete);
on the key map that is used for non-code files as well.


This is the best route. Treating .txt as code will lead to problems, but you can just bind word complete to a text file. The reason this isn't already done is because in text files I sometimes actually want to insert tabs, and didn't want a different key combo for word complete.

You will want to edit 4coder_generated/remapping.h

Bring the
1
bind(context, '\t', MDFR_NONE,  word_complete);
into the section for mapid_file.
Allen Webster
476 posts / 6 projects
Heyo
How to get autocomplete in .txt ?
Also note that this fix assumes you are using the default bindings. If you are maintaining your own key map, you will just have to make the equivalent change to that map.
Mevius
13 posts
Love dark theme. Use it for everything. OS, browser, webpages, IDE, desktop background.
How to get autocomplete in .txt ?
thanks. It works :-)