Is there a text editor with a mode that will hide the implementation of a Fortran function or subroutine? For example if the function is
function abs_df(df) result(df_abs)
! return a date_time_frame_full with elements that are the absolute values of df
type(date_time_frame_full), intent(in) :: df
type(date_time_frame_full) :: df_abs
if (num_obs(df) < 1 .or. num_var(df) < 1) return
df_abs = df
df_abs%xx = abs(df%xx)
df_abs%title = "|" // trim(df%title) // "|"
end function abs_df
I want to display only the procedure arguments, the initial comment line, the function result, and the final line of the procedure, in this case
function abs_df(df) result(df_abs)
! return a date_time_frame_full with elements that are the absolute values of df
type(date_time_frame_full), intent(in) :: df
type(date_time_frame_full) :: df_abs
end function abs_df
If there is no text editor that does this, I may write a program to create source files with such stubs. I should be able to understand what a procedure does by looking at the stub, without seeing the full source. If not, it needs more initial comment lines.
I think Geany has something similar to this, but I don’t think it is able to recognize the data declaration section of a Fortran subprogram.
I checked how code folding works in MATLAB. It is possible to hide either the entire function, or the help string. But it doesn’t seem possible to hide the function while preserving the help string:
You could separate your Fortran procedures and put the interfaces into a module, and the implementations in a submodule. Then you can document your procedures in the module.
This is very similar to what you’d get from a documentation tool like FORD or doxygen. The drawbacks that I can think of is that 1) they expect the documentation comments to have a particular style (but that is configurable) and 2) they produce html to be viewed in a browser rather than plain text to be viewed in your editor.
If you use vim check out the many fold methods it has. If you are careful about how you indent you can get what you want just with indent folding. You have to have a recent version of vim but you can fold based on syntax highlighting and hide comments, fold manually, fold based on regular expressions, indent, … you can customize it more than that but it requires scripting in a vim-specific format.
As others have mentioned, the key feature you’re looking for is customized code folding in an editor/IDE.
Several of the environments such as Code::Blocks Fortran plug-in and Intel Fortran integration with Microsoft Visual Studio IDE already offer some basic facility toward code folding. Until you can find something that is customizable for your needs, you can consider a “poor” Fortranner’s solution using the BLOCK construct!
Here’s what it can look like in Visual Studio IDE on Windows:
I have installed FORD and run it on a toy program. It would work great on my actual code, except that it recognizes comments only with !! and not a single exclamation mark. It says “the character(s) designating documentation can be changed”, but I don’t see how to do this.
You can customize the character that comes after ! to mark documentation, e.g., docmark: + I believe should make !+ the documentation maker. It’s an option you can set in the project file.
(See “docmark”)
I do not know if it is possible to make a single ! treated as a documentation comment.