[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Executing function only if another function is defined
From: |
carlmarcos |
Subject: |
Re: Executing function only if another function is defined |
Date: |
Mon, 25 Jul 2022 12:24:04 +0200 (CEST) |
Jul 25, 2022, 01:39 by incal@dataswamp.org:
> carlmarcos--- via Users list for the GNU Emacs text editor wrote:
>
>> Because it may be possible that some functions are not
>> available (e.g. during testing or debugging phases), I would
>> like to test whether the function `toucan' has been defined
>> before I call `docboost'. What can I do?
>>
>> (defun toucan-usage ()
>> "TODO"
>>
>> (docboost 'toucan "Usage Information"))
>>
>
> (Why are you using no-break space?)
>
> What you can do?
>
> You can ...
>
> 1. `require' the library where "toucan" is defined.
>
> 2. Use the hash/sharp-quote, #', instead of just the quote for
> toucan. (#' is `function' and ' is `quote' BTW.)
>
> 3. Byte-compile. The byte compiler will tell you if toucan
> is undefined.
>
I have modified the function as follows
(defun docboost (fname doc-boost)
"Appends a string to the documentation of a function.
FNAME Name of function
DOC-BOOST Documentation"
(if (functionp fname)
(put fname 'function-documentation
(concat (documentation fname t) doc-boost))))
Then doing as you suggest with
(typex-docboost #'toucan "Additional Text:")
Is `functionp' appropriate for testing whether `fname' was defined?
Adding a newline before printing the additional documentation would be a
sensible thing to do.
How to do it within docboost?