Using Emacs as a PHP ide

Keine Antworten
arielenter

I am a member!

I am a translator!

Offline
Beigetreten: 08/25/2010

Hi everyone, sometime ago I got encouraged to use Emacs in the following post:

https://trisquel.info/en/forum/vscodium-repos

By @Magic Banana (thanks a lot friend), to try Emacs as an IDE for PHP developing. 1 year later and I can now say it’s awesome, but it did took me some time. I wanted to share my journey through learning, hoping it will encourage others to try it too. Also, it was quite difficult for me to find information specifically for PHP, only though the help of @Ark74 friend ‘dinomug’ I was able to get some lights. @Ark74 please give my thanks to him if you are still pals and see him.

Emacs has a mini tutorial in the default start up screen. While following it I felt that dominating the use of the keyboard was a must. I’m not sure how important the following might be for some, and I’ll love to hear others opinion about the matter, but I never learned how to type “correctly” in a keyboard, by which I mean using every single finger in its corresponding position, and without ever looking at the keyboard. I mean, having used a computer for over 20 years it might have sounded like something I should have tried before, but I never thought it was crucial, I was happy about how fast I could type using my own way. Never the less, I want to share about this cool program that can be found in the repository called ‘klavaro’, it is awesome and I really enjoyed the challenge, and now I feel like a pro typing at 50 words per min. I did have to practice for a while, but I really think it is worth the effort.

Before continuing, I would suggest updating emacs, since the one present in the repository has a problem where it fails to connect to elpa unless a work around has to be used. Also, a newer version ensure that any feature shown in a given tutorial can be replicated. To this end you can compiled, the following tutorial work great for me: https://www.rahuljuliato.com/posts/compiling_emacs_30_1 The only different is the I prefer to use ‘checkinstall’ instead of make install, which makes a .deb package, which makes it easy to track it as an installed deb package in applications like synaptic, and it also make it easy to uninstall. There is also an app ppa:ubuntuhandbook1/emacs which may some easier, but an update has make it not so much so. Newer version 30.2 breaks, presumably because the lack of a package requirement in Trisquel 11. You might work around it by forcing version 30.1 with the following command:

sudo apt install emacs=1:30.1-0build1~ubuntu2204 emacs-bin-common=1:30.1-0build1~ubuntu2204 emacs-common=1:30.1-0build1~ubuntu2204 emacs-el=1:30.1-0build1~ubuntu2204 emacs-gtk=1:30.1-0build1~ubuntu2204

Then, you my use synaptic or some other method to keep that version locked, so that an update doesn’t break Emacs.

I found the compiling method easy to follow, so no need to use ppa really.

Next I used the tutorial offer by https://systemcrafters.net/emacs-from-scratch/#old-series to learn Emacs form cero. I felt it explained things very good, it is not necessary to see his videos, everything is written down step by step in the lessons. I felt that stopping at lesson 5 Org Mode Basics was good enough for my liking. One place were I got little confuse was when it came to the use of Evil mode, since I wasn’t sure if I should learn ‘vim’ too. Learning new things is always good, but I was assure that it was not absolutely necessary. I don’t think that basic vim usage must be hard to learn, but up to now I’m stilling preferring nano just because it shows exactly how to use it in the bottom. Some people talk about hands gymnastic and picky sore, but I haven't seen that being a problem for me, but I must admit that those experiences must come from really professional people that must use Emacs in a higher capacity than me. In any case, I was assure that evil mode was only useful if you are already accustom to work with vim.

Being an enthusiast of free software, I’ve been aware of the vim vs emacs meme war, with Richard Stallman and his character San Ignucio, and I knew it was all in good fun and laughs, but I did feel a little compelled to prefer using Emacs the way ‘God’ intended, knowing of course all is part of the joke. I just feel cool to think I better understand the joke and being part of it.

First thing you are probably are going to need while developing in PHP is to install its interpreter. I haven’t been needing it as a server, since so far I’ve been developing packages to upload them to packagist.org so that they can be used by other using composer. Right now there isn’t one that I can recommend, since I’m still experimenting trying to construct my own work tools to use with Laravel. Am I trying to re-invent the wheel? May be, but it’s been a very good exercise for me in my opinion.

While writing this, I was going to say that when needing a server for developing, docker was the way to go, but it seems that as for anything in the IT word, you must be constantly up to date, and now a new way called Laravel Herd exist, so never mind, I don’t know ¯\_(ツ)_/¯ . If I start using a server when developing again, I’ll comment here.

But still, Trisquel 11 has PHP 8.1 on the repository, but I believe that when developing in PHP or in general, it’s important to be up to date for security reasons. Now, I know this might sound funny considering that I use Trisquel for anything else, but I do think that applications for the web are more exposed that just a random guy using trisquel, and we must remember that Aramo is still receiving security updates until 2027. Also Ecne is about to come out ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧

Unless I’m mistaken, the new way suggested by Laravel 12 to install the latest PHP seem to be respectful of the free software principals and safe. What do you guys think? And PHP 8.1 won’t cut it to develop on Laravel 12 I’m afraid.

Now when it comes to PHP developing, the best option I found is to use lsp-mode with ‘phpactor’. The reason to prefer ‘phpactor’ is because is Free Software unlike ‘intelephense’ which is not, or at least its paid version uses and EULA. What I did is that I donated to ‘phpactor’ what I would have paid for ‘intelephense’.

Now continuing with the preparation to use Emacs as a PHP ide with lsp-mode and phpactor, I had two concerns which could had been avoided if I just had read the supported page more closely:

https://phpactor.readthedocs.io/en/master/lsp/support.html

These were that, in order to be able to give auto-formatting to the file and renaming methods, you need to install either PhpCsfFxer or PhpCs. I myself ended choosing PhpCs (Php_CodeSniffer).

Another particularity, is that phpactor lsp server does not support class renaming directly inside the file, but this functionality can be accomplish using the terminal as follow:

https://phpactor.readthedocs.io/en/master/reference/refactorings.html#refactoring-rename-class

Now, depending on the power of your pc, auto-complete might be smooth or not on complicated files, like in Laravel TestCases. Both my x200 tablet and Chromebook v1 struggle with it, but on an Intel Core i3-8100 3.60GHz (ohlala I know) doesn’t. I have tried the indications offered at:

https://phpactor.readthedocs.io/en/master/tips/performance.html

and

https://emacs-lsp.github.io/lsp-mode/page/performance/

but I don’t seem to see much difference. Something I was doing was to kill the server using ‘C-l w D’, where I noticed that some minimum competition is still available, though I’m not sure from where it might be coming. And I simply restart the server with ‘M-x lsp RET’ when ever I needed aditional completion support.

I’m thinking on trying to disable some of the completion using the configuration that can be found here:

https://phpactor.readthedocs.io/en/master/reference/configuration.html#completionworseextension

to see if I can find what’s the most problematic, and only disable that function while is not been used. I’ll report back once I got something to share.

Lastly I want to share my on Emacs package, I’m in the process to get it accepted into elpa, hopefully it will be soon:

https://github.com/arielenter/php-fill.el

Any way that’s all I wanted to share. If someone needs help on a particular point please reply or send me a message from my profile, I’ll be glad to help.

I truly feel blessed by all I’ve learn and I feel very grateful. I’ve been a fan of the videos by the 8 bit guy, and how all used to be text base, and though I wasn’t interested on the old software, I am very attacked to non graphic environments. With Emacs and Cool Retro Terminal package from the repository, it felt like a dream come true. Thank you every one.