CO538 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for folding
2011 |
Submission reference: IN2032
Following the style conventions for folds, it seems duplicate effort to use the PROC/FUNCTION header as the name. Can we include the fold marker ({{{) on the occamdoc line itself? e.g.:
--* Some declaration. {{{ ... --}}}
Please note that folding is a property of the editor you are using, not the occam-pi programming language. Editor folding – i.e. hiding from view some lines of code, leaving a single row of (usually three) dots optionally followed by a short comment – can be done with any text document that has some formal structure (like a programming language, LaTeX, HTML, etc.).
For occam-pi, we often fold up entire PROC declarations – e.g.
--{{{ PROC print.stream (VAL INT delay, CHAN INT in?, CHAN BYTE out!) --* This inputs a number and tabulates it on a single line of output. -- Then, it pauses for delay microseconds. It repeats this for ever. -- @param delay The length of the pause (in microseconds) -- @param in Numbers coming in -- @param out Characters going out PROC print.stream (VAL INT delay, CHAN INT in?, CHAN BYTE out!) WHILE TRUE INT n: SEQ in ? n out.int (n, 10, out!) -- out.int is from "course.module" out.string ("*c*n", 0, out!) -- out.string is from "course.module" pause (delay) : --}}}
which, as you observe, repeats a line of text twice. However, when folded, all that's seen is:
... PROC print.stream (VAL INT delay, CHAN INT in?, CHAN BYTE out!)
For most editors supporting folding, the opening "{{{" and closing "}}}" fold markers must be aligned vertically – so your suggestion won't work. However, your could avoid the redundant (but hidden) text by having:
--* This inputs a number and tabulates it on a single line of output. -- Then, it pauses for delay microseconds. It repeats this for ever. -- @param delay The length of the pause (in microseconds) -- @param in Numbers coming in -- @param out Characters going out PROC print.stream (VAL INT delay, CHAN INT in?, CHAN BYTE out!) --{{{ WHILE TRUE INT n: SEQ in ? n out.int (n, 10, out!) -- out.int is from "course.module" out.string ("*c*n", 0, out!) -- out.string is from "course.module" pause (delay) --}}} :
Now, the body of the process (which may be very long) gets folded away and we are left seeing only the process header, preceded by its documentation:
--* This inputs a number and tabulates it on a single line of output. -- Then, it pauses for delay microseconds. It repeats this for ever. -- @param delay The length of the pause (in microseconds) -- @param in Numbers coming in -- @param out Characters going out PROC print.stream (VAL INT delay, CHAN INT in?, CHAN BYTE out!) ... :
which I think is close to what you are wanting?
It might be nice to go a step further and fold away the documentation as well:
--{{{ documentation --* This inputs a number and tabulates it on a single line of output. -- Then, it pauses for delay microseconds. It repeats this for ever. -- @param delay The length of the pause (in microseconds) -- @param in Numbers coming in -- @param out Characters going out --}}} PROC print.stream (VAL INT delay, CHAN INT in?, CHAN BYTE out!) --{{{ WHILE TRUE INT n: SEQ in ? n out.int (n, 10, out!) -- out.int is from "course.module" out.string ("*c*n", 0, out!) -- out.string is from "course.module" pause (delay) --}}} : --}}}
which yields the view:
... documentation PROC print.stream (VAL INT delay, CHAN INT in?, CHAN BYTE out!) ... :
so that you can open up the documentation and code separately and browse collections of such things more compactly.
Claim: folding is a far more useful property to have in an editor than, for instance, syntax directed colouring.
Keywords: folding
2006 |
Submission reference: IN984
Why do you have comments like this in code?:
--{{{ think ... code --}}}
isn't it "--" for comments?
The dash-pair is for the comment. The triplets of curly braces are for folding. You'll need an editor that understands folding to make any use of these, but vim/gvim (common) and origami (old) do, and I suspect there are others. It basically allows the editor to collapse whole chunks of code into single highlighted lines, making working with any sizeable bit of code a whole lot easier. People who haven't discovered folding are at a disadvantage in my opinion :-). Some editors also understand how to do folding based on language constructs, rather than explicit markup as is commonly used.
Keywords: folding
2002 |
I have a problem with the folding in GVIM. Before this, I could open and close a folder containing a section of code for a PROC or a whole section of comments based on the curly bracket notation --{{{ and --}}} you provide in your .occ files. Once the block of code is closed, it displays a line of text highlighted in blue with a '+' sign on the left with the code indented and encapsulated under this folder and it also has fold column on the far left.
But now my GVIM program running under Exceed seems to have been saved under different settings and is incapable of displaying this anymore where it was OK before, and now it just displays plain text. I find it much easier if I have the folding capabilities as it is much easier to hide lines of comments and PROC bodies - particularly for occam when there are large amounts of code.
How can I change back to the original settings before and is always displayed every time you open any .occ file without having to add folders manually??
This problem is caused because /usr/local/work was renamed to /usr/local/courses on raptor. /usr/local/work doesn't exist any longer, i.e. some students' Vim resource files now point to the wrong (non-existing) directory, that's why the folding scripts are not loaded. To solve this, try to run the vim script again. Run:
/usr/local/courses/co516/vim-setup
and chose option 1 ("Replace old files").
Keywords: vim , gvim , folding
Referrers: Question 23 (2002)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |