0
$\begingroup$

In order to remind myself of the arguments a function takes and their ordering I find it useful to use the shortcut to show the template (Ctrl+Shift+k). However, I don't write usage prompts for my functions (maybe I should but I find naming the functions and arguments clearly is enough) and so I can't do this for these functions. Therefore I would like to auto generate and run usage messages containing only the function name and the name of the parameters. I.e. for all my user defined functions such as

func[descriptiveArgument1_,descriptiveArgument2_]:= ...

I want to create and run (preferably without actually creating corresponding individual cells)

func::usage = "func[descriptiveArgument1,descriptiveArgument2]";

so that I can see the names descriptiveArgument1 and descriptiveArgument2 in a template with Ctrl+Shift+k.

$\endgroup$
8
  • $\begingroup$ In general, this will be very difficult to do as soon as you're using any fancier pattern matching constructs. Having said that, you could take a look at ResourceFunction["InformationPopup"] to quickly access function definitions. Finally, this is probably a duplicate of mathematica.stackexchange.com/questions/155184/… $\endgroup$
    – Lukas Lang
    Commented Apr 13, 2023 at 14:04
  • $\begingroup$ Thanks, I will look at those! I am not sure it is a duplicate since that question seems to focus on automatically writing a nice usage message for the purpose of having a nice usage message. I don't care at all about the usage message. It only needs to contain func[arg1,arg2]... $\endgroup$
    – Kvothe
    Commented Apr 13, 2023 at 14:24
  • $\begingroup$ About ResourceFunction["InformationPopup"] do you happen to know where the shortcut Alt+F1 is defined? It does not seem to be in KeyEventTranslations I guess because it comes from an additional package. I need to change it since Alt+F1 is already a system wide shortcut for me. $\endgroup$
    – Kvothe
    Commented Apr 13, 2023 at 14:39
  • $\begingroup$ Regarding the potential duplicate: Couldn't you simply remove all the "nice usage message" parts from the other answer to be left with what you need? Regarding InformationPopup: See the last example in the documentation for how to install it with a different shortcut. It will be something like ResourceFunction["InformationPopup"]["AddMenuItem", System`MenuKey["X", System`Modifiers -> {"Command"}]] $\endgroup$
    – Lukas Lang
    Commented Apr 13, 2023 at 14:48
  • 2
    $\begingroup$ Does this answer your question? How can I automatically generate usage messages? $\endgroup$ Commented Apr 13, 2023 at 23:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.