In Terminal, type "defaults write .GlobalPreferences NSRecentDocumentsLimit 30" to apply a limit of 30 to every app. To do it only for specific programs, you can replace the ".GlobalPreferences" part with the name of the program's preferences file without "plist" at the end — so for TextEdit, it would be "com.apple.TextEdit".