If you are using the GUI pgAdmin, you can simply select the function in the object browser and open the reverse engineered SQL script in an SQL editor window.
There is a dedicated item in the options to automate it:
Options - Query tool - Query Editor - Copy SQL from main window to query tool