Autocomplete & Compiling Question

101 views
Skip to first unread message

wackzingo

unread,
Nov 18, 2007, 1:05:46 AM11/18/07
to scintilla-interest
I am currently taking a C class at school and we use visual studios
but I prefer scite.I install the Distribution that includes the php, c/
c++, perl, etc. API's and it works great except two things.

First, When I create a struct and try to use it the autocomplete
doesn't bring up the options menu like the one in visual studios. Is
there a way to make it do that? For example,

typedef struct {
char fname[10];
char lname[10];
int age;
} stud;

Then in main I go to create one and reference it.

int main()
{

stud one;

one.(As soon as I hit the dot I want it to bring up a menu of the
variables I created in the struct)


Is this possible?

The second question is can Scite use visual studios 2005 or 2008 to
compile the code? I got it working for php but not C.

Thanks
Zach

KHMan

unread,
Nov 18, 2007, 3:35:42 AM11/18/07
to scintilla...@googlegroups.com
wackzingo wrote:
> [snip]

> Then in main I go to create one and reference it.
>
> int main()
> {
> stud one;
>
> one.(As soon as I hit the dot I want it to bring up a menu of the
> variables I created in the struct)
>
> Is this possible?

Nope, SciTE cannot gather such dynamic information. It is
bare-bones for the most part, and caters for lots of languages,
while the Visual Studio interface is very highly optimized for a
few particular languages. So yeah, be aware that many of the more
nifty features will be missing. But experienced programmers
usually have many editor and shell windows open, so most of us are
quite happy without those features. As always, YMMV.

> The second question is can Scite use visual studios 2005 or 2008 to
> compile the code? I got it working for php but not C.

You need to configure the command.* settings accordingly, set it
in your user properties file or a per-directory properties file.

Visual Studio has an integrated C/C++ compiler. PHP code is never
compiled, unless you are using a Zend optimizer? So you are always
just editing PHP code.

To configure C/C++ settings, you need to know what the
command-line options are, then set the property files accordingly.
The other way is the old school method: just use SciTE as an
editor, and run "make" or "nmake" using a separate command line
window.

HTH,
--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

wackzingo

unread,
Nov 18, 2007, 7:08:21 AM11/18/07
to scintilla-interest
Thanks for the reply.

I know it won't work like Visual Studios, but it work almost the way I
want. Let me use the previous example again.

int main()
{

stud one;

one. // Right now if I hit ctrl + enter to auto complete it does
nothing.

one.f //however if I type just 1 letter it brings up a menu of
all the function and variable that begin with f including the ones
created above in the struct.



So as soon as I type the dot I can hit ctrl+enter and then it would
bring up all variables. I'm thinking that there might be a setting
where I can make the . operator act like a first letter to all
variables.

Marko Mahnič

unread,
Nov 19, 2007, 12:34:43 PM11/19/07
to scintilla...@googlegroups.com
wackzingo wrote:
>
> So as soon as I type the dot I can hit ctrl+enter and then it would
> bring up all variables. I'm thinking that there might be a setting
> where I can make the . operator act like a first letter to all
> variables.

For this to work, SciTE would need to know what a variable is,
therefore it should compile the file with an internal compiler
(a more complicated lexer might be enough) for every supported
language. At the momoent, this isn't so.

Maybe the attached LUA file (dabbrev.lua) can help you.
It will search for all words in the current buffer that begin
with the word at the cursor and display a list of such words.
You have to type at least the first char of the
variable/function/... you want to insert.
(the list is currently unsorted)

To use dabbrev, save it to your scite directory.
You will need to download SciteExtMan and put it
in the scite directory.
Then create a file named "startup.lua" and add:
require('extman')
require('dabbrev')
scite_Command 'Complete symbol (dynamic)|dabbrev|Ctrl+J'

Finally edit your SciTeUser.properties and
ext.lua.startup.script=$(SciteDefaultHome)/startup.lua

You can modify the shortcut as you see fit.
Now open the file from your first example, type
ln
and press Ctrl-J. "ln" should expand to lname.
If you type
st
and press Ctrl-J, scite should display a list:
struct
stud

Possible improvements of dabbrev are:
- sort list
- search all loaded buffers for possible completions
- search a ctags file
- case-sensitive search
- create the list based on current syntax context, for
example do not include words from comments when in code
- ...

Marko

dabbrev.lua

wackzingo

unread,
Nov 19, 2007, 1:43:34 PM11/19/07
to scintilla-interest
Thanks for the reply, I'll mess around with that and see how it works.
> [dabbrev.lua]-- encoding: UTF-8
> -- Dynamic autocompletion for SciTE
> -- author: Marko MahniÄ
> -- created: 2007-11-19
> --
> -- Reads the word (tag) that is preceeding the current position
> -- and collects all words in the current buffer that begin with the tag.
> -- Autocomplete is then performed with the collected words.
> --
> -- Installation:
> -- * requires extman.lua (http://lua-users.org/wiki/SciteExtMan)
> -- * put the following line in your LUA startup script :
> -- scite_Command 'Complete symbol (dynamic)|dabbrev|Ctrl+J'
> --
>
> require ('extman')
>
> -- return the word that is before the cursor position
> function dab_get_tag()
> local epos = editor.CurrentPos
> local ln = editor:LineFromPosition(epos)
> local lnpos = editor:PositionFromLine(ln)
> local spos = epos - 1
> while spos > lnpos and spos > 0 do
> local ch = string.char(editor.CharAt[spos])
> if not (ch == "_" or (ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z') or (ch >= '0' and ch <= '9'))
> then
> spos = spos + 1
> break
> end
> spos = spos - 1
> end
> editor:SetSel(spos, epos)
> local tag = editor:GetSelText()
> editor:GotoPos(epos)
> return tag
> end
>
> function dabbrev()
> local tag = dab_get_tag()
> if tag == nil or tag == "" then return end
>
> -- find all maching words in current buffer
> local m
> local taglist = {}
> for m in editor:match("\\<"..tag.."[a-zA-Z0-9_]+", SCFIND_REGEXP, 0) do
> taglist[m.text] = 1
> end
>
> -- count the matches returned
> local cslist = ""
> local count = 0
> for k,v in pairs(taglist) do
> count = count + 1
> if count > 1 then break end
> cslist = k
> end
>
> if count == 1 and props['autocomplete.choose.single'] ~= "0" then
> -- replace the current word with the only possible expansion found
> editor.SelectionStart = editor.CurrentPos - string.len(tag)
> editor:ReplaceSel(cslist)
> else
> -- create a list of possible matches and autocomplete
> cslist = nil
> for k,v in pairs(taglist) do
> if cslist == nil then cslist = k
> else cslist = cslist.." "..k end
> end
> editor:AutoCShow(string.len(tag), cslist)
> end
> end
Reply all
Reply to author
Forward
0 new messages