Ability To Collapse Code and Find Code


#1

I’m sure many programmers out there have found the ability to collapse big chunks of code into a single line very useful in other text editors. I think this functionality should be made available for Sonic Pi.

If you’re not sure what I’m talking about I’ll explain it as best I can. In the text editor “TextWrangler” (as well as many others) the user can highlight as many lines of code as they desire. They can then right click and select “collapse” from the drop down. This will in turn collapse the many lines of code into a single line of code with a symbol that looks like this “[…]”. Is the user wishes to uncollapse the code they simply can click on the symbol.

Another thing I noticed Sonic Pi doesn’t have is a simple Find feature that would typically be triggered by “command-F/ctrl-F” which allows the user to search for a keyword or value as well as replace keywords/values. This I believe would result in much faster editing during live coding.


#2

To be honest, if I wanted that kind of capability. I’d be writing my
code in Notepad+ or as you say, some other editor.

I think we should keep SPi as lean as possible… it does what it
does well enough.

Regards,

Eli…


#3

I don’t agree, since the ability to immediately run what you wrote or changed is pretty essential in using Sonic Pi. Can’t do that in another editor. I too think it would a small feature which would greatly enhance Sonic Pi.


#4

It might be a small feature to conceive, but it’s not small to implement and while it’s on my todo list it’s not as high as other things.

We’d need to carefully consider the interaction design of a simple search system. I’m not a fan of complex pop up boxes and lean towards a vim/Emacs approach of using a command line to initiate a search.

If anyone wants to have a go at implementing such a thing that would be ace.


#5

Well, putting aside the question whether you want to use something outside of SP at all (with possible drawbacks), you can use Emacs (or Atom, but I never tried that). I find myself using both, Emacs and the native Sonic Pi editor depending on purpose and context.


#6

100% agree and something I have brought up before. I personally would pay for a professional ‘Sonic Pi IDE’.

When projects get to a certain size these kind of features are invaluable IMO.


#7

hey, i just noticed this: on the sonic pi github, it shows these codemirror pages:


a while ago i modified mr doob’s html editor to add a few things, and added code folding. (here’s my modified editor: https://ds604.neocities.org/mrdoobEditor_glslHighlightingClass_sideFade_06052017.html) anyway, what i added to get code folding was these:

<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/addon/fold/foldcode.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/addon/fold/foldgutter.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/addon/fold/brace-fold.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/addon/fold/xml-fold.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/addon/fold/foldgutter.min.css" />

and then in the editor options, add the options like in this example: https://github.com/codemirror/CodeMirror/blob/master/demo/folding.html

so it would be

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    mode: "text/x-ruby",
    tabMode: "indent",
    matchBrackets: true,
    indentUnit: 2,
    lineNumbers: true,
    value: "#foo",

    //add these lines to get code folding
    foldGutter: true,
    gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
});

i don’t know if this actually works, since i guess you might need to recompile it or something. i don’t see the codemirror part when i do the show package contents, so i don’t know how it gets put in to the one that you download. so, someone else might know that part. but if that’s how it works, then this might get the code folding!


#8

Certainly looks interesting… I was looking at Notepad ++ plugins myself earlier on this evening and
wondering how hard it would be to write an ‘SP’ plugin… there are already numerous ones that add menu
buttons and/or export via clipboard. or execute documents as files in their default environment / applicaton.

Eli…


#9

Sorry to lead you down the wrong track, but the gui/html folder is for the prototype HTML editor I built a long while ago which drastically needs some love. Unfortunately that’s not used at all in the regular GUI which is built in C++ using Qt (and can be found in the gui/qt folder).


#10

thanks, @samaaron! (and thanks for building sonic pi in the first place!) good to know that’s the setup

well, if the html editor gets put in use, then maybe i can help out with something. at least adding or modifying little things i can get by. more complicated things, like c++, are a little beyond me. (though i found out about qml recently, and that’s actually pretty neat. i like that the interface builder looks a little like photoshop)