Change doc string summary of a function on the flyIs there an existing function to add docstrings, relevant to the current major mode?Is it possible to attach generated doc string to a lambda?How can I define the syntax of a C-defined function with with module_make_function?\{ in a doc string: what does it mean/do?
Which big number is bigger?
Why do games have consumables?
Mjolnir's timeline from Thor's perspective
Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?
What language was spoken in East Asia before Proto-Turkic?
Combinable filters
Realistic Necromancy?
Critique of timeline aesthetic
Are Boeing 737-800’s grounded?
What term is being referred to with "reflected-sound-of-underground-spirits"?
What does the "ep" capability means?
Is there an official tutorial for installing Ubuntu 18.04+ on a device with an SSD and an additional internal hard drive?
Seemingly unused edef prior to an ifx mysteriously affects the outcome of the ifx. Why?
Is it idiomatic to construct against `this`?
How to have a sharp product image?
Is this homebrew Wind Wave spell balanced?
How to stop co-workers from teasing me because I know Russian?
How to verbalise code in Mathematica?
Do I have an "anti-research" personality?
Why isn't the definition of absolute value applied when squaring a radical containing a variable?
What is the most expensive material in the world that could be used to create Pun-Pun's lute?
Do I have to worry about players making “bad” choices on level up?
Is there really no use for MD5 anymore?
What is Niska's accent?
Change doc string summary of a function on the fly
Is there an existing function to add docstrings, relevant to the current major mode?Is it possible to attach generated doc string to a lambda?How can I define the syntax of a C-defined function with with module_make_function?\{ in a doc string: what does it mean/do?
Is it possible to change the first line of a docstring of a function, without editing the source code of this function? And if, how can I do this?
Background: some packages come with a pretty useless doc string summary.
(for example, fci-mode
: "Toggle fci-mode on and off.").
Because I have some helper commands, which show this summary, I'd like to exchange the docstring summary of those functions to something more useful (or even translate them to my mother tongue), without touching the source code of those packages.
doc-strings
add a comment |
Is it possible to change the first line of a docstring of a function, without editing the source code of this function? And if, how can I do this?
Background: some packages come with a pretty useless doc string summary.
(for example, fci-mode
: "Toggle fci-mode on and off.").
Because I have some helper commands, which show this summary, I'd like to exchange the docstring summary of those functions to something more useful (or even translate them to my mother tongue), without touching the source code of those packages.
doc-strings
add a comment |
Is it possible to change the first line of a docstring of a function, without editing the source code of this function? And if, how can I do this?
Background: some packages come with a pretty useless doc string summary.
(for example, fci-mode
: "Toggle fci-mode on and off.").
Because I have some helper commands, which show this summary, I'd like to exchange the docstring summary of those functions to something more useful (or even translate them to my mother tongue), without touching the source code of those packages.
doc-strings
Is it possible to change the first line of a docstring of a function, without editing the source code of this function? And if, how can I do this?
Background: some packages come with a pretty useless doc string summary.
(for example, fci-mode
: "Toggle fci-mode on and off.").
Because I have some helper commands, which show this summary, I'd like to exchange the docstring summary of those functions to something more useful (or even translate them to my mother tongue), without touching the source code of those packages.
doc-strings
doc-strings
edited Apr 24 at 11:38
Peter Mortensen
1334
1334
asked Apr 24 at 9:44
juejue
1,545112
1,545112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can access the raw documentation string of a function foo
with (documentation 'foo t)
.
You can set the documentation string of foo
with(put 'foo 'function-documentation "My new docstring.")
.
The following example shows you how you can exchange the first line of the documentation string:
(defun change-description-line (symbol new-description)
"Change first line of doc string for SYMBOL to NEW-DESCRIPTION."
(put symbol 'function-documentation
(concat new-description
(let* ((doc (documentation symbol t))
(pos (cl-position ?n doc)))
(and pos (substring doc pos))))))
;;; Usage example:
(unintern 'foo obarray)
(defun foo ()
"Greetings from function foo.
The real info often is on the second line:-(."
)
(change-description-line 'foo "New description of foo.")
Note that the symbol property function-documentation
overrides the documentation stored in the function object.
To restore the documentation from the function object you can use(put 'foo 'function-documentation nil)
Alternatively, if you want to re-define foo
anyway you can just remove the symbol foo
from the global obarray:(unintern 'foo obarray)
add a comment |
In addition to @Tobias's answer, refer to C-hig (elisp)Accessing Documentation
The other notable aspect of dynamic documentation via the function-documentation
symbol property (amongst others), is that it can be generated on-demand.
If FUNCTION is a symbol, this function first looks for the
‘function-documentation’ property of that symbol; if that has a
non-‘nil’ value, the documentation comes from that value (if the
value is not a string, it is evaluated).
e.g. A function-documentation
property value of '(foo)
will cause the function foo
to be called to obtain the documentation, each time it is needed.
very interesting
– jue
Apr 24 at 11:25
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "583"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f50121%2fchange-doc-string-summary-of-a-function-on-the-fly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can access the raw documentation string of a function foo
with (documentation 'foo t)
.
You can set the documentation string of foo
with(put 'foo 'function-documentation "My new docstring.")
.
The following example shows you how you can exchange the first line of the documentation string:
(defun change-description-line (symbol new-description)
"Change first line of doc string for SYMBOL to NEW-DESCRIPTION."
(put symbol 'function-documentation
(concat new-description
(let* ((doc (documentation symbol t))
(pos (cl-position ?n doc)))
(and pos (substring doc pos))))))
;;; Usage example:
(unintern 'foo obarray)
(defun foo ()
"Greetings from function foo.
The real info often is on the second line:-(."
)
(change-description-line 'foo "New description of foo.")
Note that the symbol property function-documentation
overrides the documentation stored in the function object.
To restore the documentation from the function object you can use(put 'foo 'function-documentation nil)
Alternatively, if you want to re-define foo
anyway you can just remove the symbol foo
from the global obarray:(unintern 'foo obarray)
add a comment |
You can access the raw documentation string of a function foo
with (documentation 'foo t)
.
You can set the documentation string of foo
with(put 'foo 'function-documentation "My new docstring.")
.
The following example shows you how you can exchange the first line of the documentation string:
(defun change-description-line (symbol new-description)
"Change first line of doc string for SYMBOL to NEW-DESCRIPTION."
(put symbol 'function-documentation
(concat new-description
(let* ((doc (documentation symbol t))
(pos (cl-position ?n doc)))
(and pos (substring doc pos))))))
;;; Usage example:
(unintern 'foo obarray)
(defun foo ()
"Greetings from function foo.
The real info often is on the second line:-(."
)
(change-description-line 'foo "New description of foo.")
Note that the symbol property function-documentation
overrides the documentation stored in the function object.
To restore the documentation from the function object you can use(put 'foo 'function-documentation nil)
Alternatively, if you want to re-define foo
anyway you can just remove the symbol foo
from the global obarray:(unintern 'foo obarray)
add a comment |
You can access the raw documentation string of a function foo
with (documentation 'foo t)
.
You can set the documentation string of foo
with(put 'foo 'function-documentation "My new docstring.")
.
The following example shows you how you can exchange the first line of the documentation string:
(defun change-description-line (symbol new-description)
"Change first line of doc string for SYMBOL to NEW-DESCRIPTION."
(put symbol 'function-documentation
(concat new-description
(let* ((doc (documentation symbol t))
(pos (cl-position ?n doc)))
(and pos (substring doc pos))))))
;;; Usage example:
(unintern 'foo obarray)
(defun foo ()
"Greetings from function foo.
The real info often is on the second line:-(."
)
(change-description-line 'foo "New description of foo.")
Note that the symbol property function-documentation
overrides the documentation stored in the function object.
To restore the documentation from the function object you can use(put 'foo 'function-documentation nil)
Alternatively, if you want to re-define foo
anyway you can just remove the symbol foo
from the global obarray:(unintern 'foo obarray)
You can access the raw documentation string of a function foo
with (documentation 'foo t)
.
You can set the documentation string of foo
with(put 'foo 'function-documentation "My new docstring.")
.
The following example shows you how you can exchange the first line of the documentation string:
(defun change-description-line (symbol new-description)
"Change first line of doc string for SYMBOL to NEW-DESCRIPTION."
(put symbol 'function-documentation
(concat new-description
(let* ((doc (documentation symbol t))
(pos (cl-position ?n doc)))
(and pos (substring doc pos))))))
;;; Usage example:
(unintern 'foo obarray)
(defun foo ()
"Greetings from function foo.
The real info often is on the second line:-(."
)
(change-description-line 'foo "New description of foo.")
Note that the symbol property function-documentation
overrides the documentation stored in the function object.
To restore the documentation from the function object you can use(put 'foo 'function-documentation nil)
Alternatively, if you want to re-define foo
anyway you can just remove the symbol foo
from the global obarray:(unintern 'foo obarray)
edited Apr 24 at 10:35
answered Apr 24 at 10:01
TobiasTobias
15.7k11036
15.7k11036
add a comment |
add a comment |
In addition to @Tobias's answer, refer to C-hig (elisp)Accessing Documentation
The other notable aspect of dynamic documentation via the function-documentation
symbol property (amongst others), is that it can be generated on-demand.
If FUNCTION is a symbol, this function first looks for the
‘function-documentation’ property of that symbol; if that has a
non-‘nil’ value, the documentation comes from that value (if the
value is not a string, it is evaluated).
e.g. A function-documentation
property value of '(foo)
will cause the function foo
to be called to obtain the documentation, each time it is needed.
very interesting
– jue
Apr 24 at 11:25
add a comment |
In addition to @Tobias's answer, refer to C-hig (elisp)Accessing Documentation
The other notable aspect of dynamic documentation via the function-documentation
symbol property (amongst others), is that it can be generated on-demand.
If FUNCTION is a symbol, this function first looks for the
‘function-documentation’ property of that symbol; if that has a
non-‘nil’ value, the documentation comes from that value (if the
value is not a string, it is evaluated).
e.g. A function-documentation
property value of '(foo)
will cause the function foo
to be called to obtain the documentation, each time it is needed.
very interesting
– jue
Apr 24 at 11:25
add a comment |
In addition to @Tobias's answer, refer to C-hig (elisp)Accessing Documentation
The other notable aspect of dynamic documentation via the function-documentation
symbol property (amongst others), is that it can be generated on-demand.
If FUNCTION is a symbol, this function first looks for the
‘function-documentation’ property of that symbol; if that has a
non-‘nil’ value, the documentation comes from that value (if the
value is not a string, it is evaluated).
e.g. A function-documentation
property value of '(foo)
will cause the function foo
to be called to obtain the documentation, each time it is needed.
In addition to @Tobias's answer, refer to C-hig (elisp)Accessing Documentation
The other notable aspect of dynamic documentation via the function-documentation
symbol property (amongst others), is that it can be generated on-demand.
If FUNCTION is a symbol, this function first looks for the
‘function-documentation’ property of that symbol; if that has a
non-‘nil’ value, the documentation comes from that value (if the
value is not a string, it is evaluated).
e.g. A function-documentation
property value of '(foo)
will cause the function foo
to be called to obtain the documentation, each time it is needed.
answered Apr 24 at 11:00
philsphils
28.5k23871
28.5k23871
very interesting
– jue
Apr 24 at 11:25
add a comment |
very interesting
– jue
Apr 24 at 11:25
very interesting
– jue
Apr 24 at 11:25
very interesting
– jue
Apr 24 at 11:25
add a comment |
Thanks for contributing an answer to Emacs Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f50121%2fchange-doc-string-summary-of-a-function-on-the-fly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown