PDA

View Full Version : VS Code + Pascal : Editor for the future!



Rickmeister
30-12-2016, 08:38 PM
Yep. Probably the best editor for pascal at the moment. Try it out, it's free!! Not to say that the built-in editor that comes with Lazarus is bad, but it's like comparing apples and oranges. VS Code is on the same page as Google Atom - or in short a modern approach at making a real text editor for coders. It's like Vim or Emacs without much of the hazzle (I do still prefer Emacs when editing C-code, but it's hard to learn old dogs new tricks...)

https://code.visualstudio.com/
http://www.omnipascal.com/

The bad thing is that the extension, OmniPascal, is windows only :(

This is the part where I need ALL of you to get over to Bitbucket, register (it's free) and up-vote this issue:

https://bitbucket.org/Wosi/omnipascalissues/issues/6/add-rich-language-support-for-mac-and

By doing so you will be doing the whole community of Pascal indie and hobbyist developers a huge favour, and I also belive that it will boost the popularity of Pascal/Delphi and maybe, just maybe make more people open their eyes to see the beauty of the language. No need to convince you, but let the masses know that 'Inc(p);' is way more readable then 'p++;'!! ;D

[edit] By a honest mistake I used 'c' in the above code example, rendering in 'c++' wich I thought was highly inappropriate :-X

farcodev
31-12-2016, 11:40 PM
I dunno, my old Delphi 2009 with the old Castalia do all I need. I also use Notepad++ for XML and text edit.

I will try it, thanks for the info.

Rickmeister
01-01-2017, 03:24 PM
IntelliJ Idea with the I-Pascal plugin is also quite nice. It does lack a few things, and Idea isn't really a 'small' editor, but it's usable. I just don't like IDE;s, most of them tend to clutter the screen with information I do not need, and as a worst case scenario you have Lazarus with that multiple window setup. 99% of the time I edit code, and I want a streamlined yet powerful editor, preferably extendable like emacs, vim or atom/vs-code.

Carver413
02-01-2017, 07:39 PM
I use Lazarus for compiling and debugging and managing the compiler stuff. as far as the editor goes I have my own design. a long time ago when I start out back in the days of delphi3 before the days of XML I developed the fold file format. in short it allows use to view our code more like the oop object it has intended to be. not to be confused with things like code explorer which sort of do the same thing but only move your editors view. with the explorer you see only what you intended to see and work only that. your editor area can be fill with pages of code you want to see and nothing else. you can have multiple files open at the same time. code can be moved,copied,pasted,removed painlessly from one fold to the next. the explorer has a layout manager to deal with all pages you open there is no complicated docking system to deal with. also the explorer was design from the start to have a scripted front-end and is build into the framework. the end goal is not yet another editor but a full on graphic work station for creating games,and such. it already has alot of graphic design code built into it but thats another story so I wont get into that today

Rickmeister
02-01-2017, 09:36 PM
I actually prefer FP-IDE over Lazarus for code editing. Laz has a nasty habit of munching up all your RAM and acts like a real CPU hog for me on Linux, filed numerous bug reports over it since I started using it. Minimalized it alone uses 70-80% cpu power and buttloads of memory. Ofcourse the Lazarus people told me it was a Kernel bug, so I should file a bug report aimed at the Fedora kernel instead.. Yeah.. right that's not going to happend... Even Eclipse with a massive amount of plugins runs smoother then Lazarus for me on Linux. Tried it on four different computers and swapped four different distros over those machines, and all I found out was that the battery on a laptop drains awfully fast when the fan is revvin' like a formula one car....

Found a nice vim setup aswell, and beeing as old as I am I remember using it on the Amiga. Nice, sleek editor but to start fresh with it might be a bit frigthening - lots of crazy keybinds, but I assure you they all made sense when you worked on an Amiga 500 :D

Carver413
02-01-2017, 10:45 PM
I am using linux mint and I am not having that problem, memory usage goes up only 2% and cpu idle 0-2%, never tried fp-ide. I was a fan of amiga as well in fact AmigaE was my favourite language. it was really hard to move on.

de_jean_7777
03-01-2017, 12:32 PM
Lazarus uses far less memory for me than other IDEs, including VS Code which munches up 200 MiB by default just for three small files open. Both Linux and Windows.

Rickmeister
03-01-2017, 04:08 PM
Glad to hear that Lazarus is working for you, but it doesn't really help me as it's not very usable for me...

Can't find the link to the Lazarus forums where I debated about this, but the problem is that I've tried it with four different Linux distros on four different hardware setups and I still get the same result. Someone suggested that it might be because I only use laptops, and it has something to do with the powersaving setup. What's strange is that it's only Lazarus that's causing this. When running Lazarus in the background with an empty project open it uses 70-80% CPU, when I rescan sources the CPU usage goes down to less then 1% when idling, but increases over time and after a few minutes it's up at 70-80% again. Posted a few traces (strace lazarus-ide) on there but I've heard nothing about it since.

Rickmeister
21-01-2017, 04:52 PM
902 views and one up-vote :( I don't expect you all to like it, but can I please, please, please with sugar on the top make you go over to bitbucket and upvote this issue. I so want to use this, and preferably on my Linux box as I don't like windows (I don't hate it or so, and it's a good OS, I just don't like it.)

Ñuño Martínez
27-01-2017, 10:43 AM
I'm pretty happy with Vim. Actually I think it would be better but I can't back to those CUA (https://en.wikipedia.org/wiki/IBM_Common_User_Access) editors.

Rickmeister
31-01-2017, 07:39 PM
Trolledge (http://www.trolledge.com/) looks very nice, pity it only has Windows and OS/X support. Any one tried it?

Rickmeister
03-02-2017, 02:49 PM
I'm pretty happy with Vim. Actually I think it would be better but I can't back to those CUA (https://en.wikipedia.org/wiki/IBM_Common_User_Access) editors.

I did temper with an Emacs package that talked to Lazarus CodeTools for inteliisense and autocompletion and I actually made it work..sortof. When I finish my current project I'll try to get back into vim-script again and rewrite it. With Vim8 and asynchronous i/o support it would be if not easy, so atleast easier then working with Emacs and background processes.

In short, it shouldn't be that much work involved in writing a vim plugin that talked to a CodeTools server running in the background. With Emacs you had to poll the server to get updates, and pipe them through a hidden buffer into the current buffer you where editing, and that caused lots and lots of overhead, and quite frequently a crash or two (might depend on my not-so-good pascal skills :) ). If you ever used the vim plugin YouCompleteMe when writing C/C++ code you got a pretty good picture on what I'm aiming for.

Please let me know if you would be interested in testing it out, or maybe even give me a hand with it. We 'Vimmers' need to stand up for our editor :)

Ñuño Martínez
04-02-2017, 05:39 PM
I would try.

I have no experience with vim-script, that is why I tried to create my own editor using Lazarus.

Rickmeister
04-02-2017, 08:06 PM
I would try.

I have no experience with vim-script, that is why I tried to create my own editor using Lazarus.

Vim-script is the epiphany of bad design! It's absolutely awful..but if you manage to get your head around it, it's also very, very powerful. Every little aspect of the editor is scriptable. There is however the possibility to use python IF vim was compiled with support for it. I think that most mainstream versions of pre-compiled vim binaries atleast has support for Python2.6 baked into the executable. Another option is lua, or ruby (in the latter case I do think vim-script is tidier and more comprehensive..)

Can't find the time for such a big undertaking atm, but when I finish of some other projects I promise that I'll give it a go, a prototype shouldn't take that much time to produce, but I surely could use some help with the backend, which will be written in Pascal. My Emacs 'server' piped string objects back and forth between the CodeTools interface and the Emacs buffer, but I'm pretty sure that there is another, more efficent way of doing this. The Vim-way of swap-files could be abused to achieve a better interface between the two (Vim and CodeTools).

Disecting the YouCompleteMe source might give me a better understanding on how to proceed.

Can't help it, but I feel like all 'modern' editors, apart from atom/code/sublime isn't really good at handling large amounts of source-code. One thing I hate is when the editor gives you the option to autoclose brackets/parens etc but doesn't do anything to actually match the pairs.. For example:


constructor TSomeClass.Create(|)
This happens in most editors when you turn on autoclose ('|' is used to display the cursor position).

constructor TSomeClass.Create(text:string|)
All is well

constructor TSomeClass.Create(text:string)|)
What? I typed a closing paren and the stupid editor didn't match parens, so instead of jumping over the closing paren, it inserted a new one. Mumblemumblemumbe. Hit 'del', move pinky to right arrow, move cursor over the stupid paren and insert that semicolon

constructor TSomeClass.Create(text:string);

In 'real' editors, that doesn't just autoclose, but actually match pairs of brackets/parens ets this would not have happened, and I would be churning out code instead of cursing and moving the cursor by using the arrow keys, which by the way are located far of where your fingertips should be to write fast and efficent.

Rickmeister
08-02-2017, 07:06 PM
Got some vim hacks I can share with you. If you want to change the default mode, just edit the script. Now it defaults to {$mode delphi}. I think the .vimrc file of my current installation is around 1500 lines long *phew*. This example script shows two things:

Vim is a powerful editor, that you can customize as you like (almost)
Vim-script syntax is horrible




function! InsertModeLine()
python << endpython
import vim
unitname=vim.eval("expand('%:r')")
vim.current.buffer[0:0]=['unit '+unitname+';']
vim.current.buffer[2:0]=['{$MODE DELPHI}']
vim.command(":$")
del vim
endpython
endfunc

augroup Delphi
autocmd!
autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set tabstop=4
autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set shiftwidth=2
autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set softtabstop=4
autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set expandtab
autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set nospell
autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :let g:pascal_delphi=1
autocmd BufNewFile *.pas,*.pp :call InsertModeLine()
augroup END


In short, it sets tabs to be equal to 4 spaces, and sets the auto indent tabstop at 2 spaces. The rest is just for show For some reason vim defaults to some late 60'ies syntax for pascal, but more modern delphi and fpc syntax is provided.

If you want fpc syntax: do this changes


// Change this line
let g:pascal_delphi=1
// to
let g:pascal_fpc=1

Ñuño Martínez
09-02-2017, 11:04 AM
So, should we add that code to the end of the .vimrc file? That's all?

Rickmeister
09-02-2017, 02:40 PM
Yes. Just copy those lines into your .vimrc and source it (:so %). Next time you create a unit (myUnit.pas or myUnit.pp for example) it will automatically insert the line 'unit myUnit' and {$MODE DELPHI}.

Another quickie:


let g:primary_file=""

function! CompilePascal(mode)
python << endpython
import vim
mode=vim.eval("a:mode")
primary_file=vim.eval("g:primary_file")
if mode=='DEBUG':
vim.command("set makeprg=ppcx64\ -dDEBUG\ @fp.cfg\ " + primary_file)
elif mode=='NORMAL':
vim.command("set makeprg=ppcx64\ -dNORMAL\ @fp.cfg\ " + primary_file)
elif mode=='RELEASE':
vim.command("set makeprg=ppcx64\ -dRELEASE\ @fp.cfg\ " + primary_file)
vim.command("make")
endpython
endfunc


Also, add these line to the Delphi augroup:


autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr,*.lpr :compiler fpc
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow


This little snippet, which you can bind to a key if you like, build pascal projects using fp.cfg (created by the fp-ide).
Usage:


:let g:primary_file="program.pas" // Only needed once. Subsequent runs will remember this
:call CompilePascal("DEBUG") // replace with "RELEASE" or "NORMAL" for other build configurations


I think I've made a function that scans the folder for a *.lpr or *.dpr file and automatically set it as the primary file. Can't find it right now. When the build is complete you'll be asked to press a key to return to vim, and when back there you'll see that a "quickfix" window has opened, showing errors and warnings issued by the compiler. If you click them, the cursor will be placed at the error, and if you like me doesn't like to use the mouse, you can either type ':cn' or ':cp', or bind them to a key of your choice to jump to next error (cn) or the previous one (cp)

Rickmeister
09-02-2017, 08:26 PM
Got tons of tips and tricks for vim, some are a bit more advanced then others - ranging from remapping function keys to work in all modes (normal,insert and visual) to configuring Pyclewn for debugging inside vim. Got codecompletion, code generation, building and debugging all set up in a way I like it, and all in the same editor. Some of the more advanced stuff needs a bit of bash-hacking to work in a terminal, but I mainly use gvim (or vim -g), I only use terminal-based vim sessions for editing scripts and config files. Note that I don't know much about setting up vim on windows as I only work on Linux and OS/X. For C related stuff I prefer Emacs, but that's another story :)

Ñuño Martínez
14-02-2017, 07:26 PM
I did create my own color schema to be the same than good old Borland Turbo IDEs. That and setting a few odd edition stuff (show special characters, use two different back-up files...). That's all I did.

Didn't test your code yet.

Rickmeister
15-02-2017, 08:55 AM
I did create my own color schema to be the same than good old Borland Turbo IDEs. That and setting a few odd edition stuff (show special characters, use two different back-up files...). That's all I did.

Didn't test your code yet.


:colorscheme borland
:)

If you want to I can try to tidy up my vimrc and post it here on the forums somewhere, or put it on github - either way is ok.
What I can do with my vim settings:

Automatic insertion of 'header' in files (comment etc). Customized by filetype
Code completion - Provided by NeoComplete (plugin).
Browse tags with a keypress (actually Three ',tt')
Jump between declaration and implementation
Code generation for class procedures/functions/constructors/destructors
Extensive (ab)use of snippets
Build project (debug or release is set by a command)
Debug using Pyclewn and GDB
Send emails (Yeah, really 8))
Generate build scripts (really stupid at the moment, need improvements)
Calltips (also really stupid at the moment, but it's a WIP)


Most of it is written in hackish python, with some extra lines of vimscript to spice it up.

Ñuño Martínez
15-02-2017, 12:59 PM
That would be great.

You may post it at Lazarus forums (http://forum.lazarus.freepascal.org) too.

Rickmeister
18-02-2017, 02:04 AM
That would be great.

You may post it at Lazarus forums (http://forum.lazarus.freepascal.org) too.

I'll drop it in here, just give me a few weeks to tie up all loose ends. Much of the scripts are scattered over a couple of files, so I need to sort them out and package them in a nice way, the ideal solution would be to create a plugin that you can use with Vundle (https://github.com/VundleVim/Vundle.vim) and Pathogen (https://github.com/tpope/vim-pathogen), that would make it so much easier and more user friendly for others. The learning curve is steep, and we that have climbed almost to the top shouldn't keep pushing people down 8)

Got alot of issues with my code completion plugin as it tends to crash from time to time, most likely an out of range error, but as it just dies without issuing any errors, and the abilities to debug python running inside vim are limited (non-existant would maybe be a better word) it's hard to find out exactly where it bugs out. It's also quite slow when you open a project the size of Castle engine (python regex is kinda slow when it has lots of text to process), and the context awareness would need to be improved, so I don't think I'll include that. Now I'm just using NeoComplete and it does the job, but isn't perfect. I need to look into Lazarus CodeTools and try to write some sort of server backend that can talk to vim through a python script, ideally wrap some library calls to python, but my Pascal knowledge is far from the point where I could be able to pull that off. On the other hand, nobody remembers a coward!!

Got a nice little hack that generates class function/procedures that can save you quite some time and it's quite stable, and so is the build/run/debug scripts. Then there are other more basic stuff like header insertions (comments, unit name, defines etc) and stuff like that.

I'll get back to you

phibermon
24-02-2017, 01:55 AM
Stock Lazarus does nearly everything I need - anything else I want I just add myself. I've customised its single window layout and coded some extras specific to my framework/engine for quick templating and prototyping - you may say it means Lazarus is incomplete but for me the ability to customise my IDE at the lowest of levels is exactly why Lazarus is the best for me - it's future proof, I don't have to rely on anybody maintaining it or worry about the project dying - I've got the source code - I'll die before it does.

There's loads of fantastic editors and IDEs out there and everybody has their own preferences - Netbeans tends to be my favourite for web development and C++ for example while I switch to the very similar Eclipse for Java.

Can't stand Visual Studio - it's a propitiatory lumbering mess of an IDE in my opinion and Microsofts habit of locking new versions to the latest editions of windows is utterly infuriating, not to mention its heavy integration with their propitiatory APIs and complete lack of effort to cater for cross platform devs - if Microsoft are disappointed with the low pace of windows phone development for example they've only got themselves to blame. Don't get me started on their perversions of XML (XAML I'm looking at you) - it's abstraction soup with a single implementation - jumping through utterly redundant hoops all day just because somebody naively thought it might get adopted in other ecosystems.

Basing your development future on a Microsoft product is like basing an economy on oil - one day you'll realise you're screwed and you'll have to invade the middle east or collapse like a sky scraper - or something.