Since the announcement of Redaktilo on this blog, this silly library has jumped from 164 lines of code in v0.3 to 571 in v0.7.
In this article:
- we'll quickly oversee the changes done
- then we'll have some insight on the upcoming changes
- finally I'll list the remaining unresolved questions
Thanks to WouterJ you can now:
- remove the current line:
- replace the current line:
- replace all occurences:
$editor->replaceWith($file, $regex, $callback);
- check line presence:
I've updated to documentation to make the library easier to learn with:
Redaktilo has been created to fulfill actual needs. To make sure it keeps this promise, I've added executable examples using PHPUnit tests.
The major changes have been massive refactorings to allow the library to be extended:
Sublime Text's go to anything feature is really awesome, which is why I'd like to implement something similar:
- go to the previous/next line (
- go to x lines above/under
- go to the previous/next substring match (
- go to the previous/next regex match (
- go to the previous/next PHP class/method/function (
The two first ones are already available, so the other one still have to be implemented (the last one might be done by Loick Piera).
The methods allowing this throw exception when nothing is found. Adding a
relative check (
hasAfter) might make things easier.
Moving relatively isn't always sufficient. To go to an absolute line number
you have to use directly
File, maybe it would be nicer to add a new method
Finally, the editor should allow insertion, replacement and removal in any locations, not just on the current line.
Once these features added, more refactoring should take place: since the
creation of Redaktilo, Jean-François Simon
advised me to use the command and memento patterns, which would allow the
While I now think that
Command is indeed more suitable than
for insertion, replacement and removal, I'm not sure the versioning feature
is actually needed... For now.
And that should bring us near an alpha version :) .
A lot of renaming should happen at this stage:
And perhaps some other methods or class names.
Once the heavy renaming done, beta versions can begin, with a main focus on making every thing safer (argument checking, exception handling).
Remaining unresolved questions
I'm still not fully sure of what Redaktilo v1.0 will look like. Mainly because I still haven't anwsered this by question (which have been in my mind since the begining):
Should Redaktilo handle different kinds of files?
Sometimes I think it should, which is why the project has seen:
- Editor interface
- File interface
- a premature ReplaceEngine/ReploaceStrategy
- ContentConverter interface
The motives behind this is the JSON use case: you can currently edit JSON files, but it's tedious.
Let's take the
composer.json example. What if you need to
add a script when:
- there's no
- there's no subsection in
- there's already a script, but not in an array
- there's already some scripts
Another example would be the addition of a new element in an array: you currently have to manually a trailing comma to the previous entry...
Redaktilo fulfills 98% of my use cases (inserting new lines in a YAML configuration file, editing PHP files and replacing bits in a documentation file) and is now extensible.
Some search strategies will be added to make it similar to the Sublime Text's go to anything, and some refactoring are still necessary before an alpha version.
There's still some unresolved questions (JSON edition is the 2% use case left), but I'm sure they'll be answered during the development.
In the end
Editor should have the following methods (no guaranty on the
- filesystem operations: open/save
- checking line presence: has/hasBefore/hasAfter
- content navigation: jumpTo/jumpUpTo/jumpDownTo
- content manipulation: insert/remove/replace (on the current line or at the given location)
- global manipulation: replaceAll
I'd like to thank the early contributors:
Any help is appreciated, whether it's some code review, typo fixing or code/documentation contribution. But the biggest help you could give me: provide me with some feedback on Redaktilo's usage :) .
If you have any questions, remarks, please feel free to open an issue and start a discussion here.