all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: variable's documentation string
Date: Tue, 30 Jun 2009 10:47:22 +0200	[thread overview]
Message-ID: <7ctz1yhzvp.fsf@pbourguignon.anevia.com> (raw)
In-Reply-To: 0a97f5cb-d434-4014-ba0b-dd5126095fbf@f10g2000vbf.googlegroups.com

TheFlyingDutchman <zzbbaadd@aol.com> writes:

>>
>> Here, it works well:
>>
>> (defvar myVar 2 "This is the documentation string")     ; C-x C-e
>> (documentation-property 'myVar 'variable-documentation) ; C-x C-e
>> --> "This is the documentation string"
>
>
> Thanks Pascal! You lead me to the error. When I typed (documentation-
> property 'some_variable 'variable-documentation) and evaluated it, it
> worked. I then compared it to the equivalent part of the message
> statement that I was using, and after 15 seconds of looking at it I
> realized that I had incorrectly used a dash, instead of an underscore
> for the variable name in the documentation-property function call. I
> will have to remember to post the exact code I am using and not type
> in something equivalent. But I would have expected to have gotten an
> error because the symbol-name that I erroneously typed did not exist.
> In fact, I would prefer it gave an error to returning nil.

In emacs lisp,  variable names are symbols and they all already exist.
The variable documentation is actually stored in the symbol property
list:

(symbol-plist 'myVar)
--> (variable-documentation "This is the documentation string")

(get 'myVar 'variable-documentation) 
--> "This is the documentation string"

and get returns nil when the key doesn't exist:
(get 'myVar 'innexistant-key) 
--> nil

So if you want an error instead of nil, you have to ask it yourself:

(defun variable-documentation (var)
   (or (documentation-property var 'variable-documentation)
       (error "Variable %S has no documentation" var)))

(variable-documentation 'xyz)
==> Debugger entered--Lisp error: (error "Variable xyz has no documentation")

(variable-documentation 'myVar)
--> "This is the documentation string"


-- 
__Pascal Bourguignon__


  parent reply	other threads:[~2009-06-30  8:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-29  7:24 variable's documentation string TheFlyingDutchman
2009-06-29  7:25 ` TheFlyingDutchman
2009-06-29  9:24   ` Pascal J. Bourguignon
2009-06-29 22:47     ` TheFlyingDutchman
2009-06-30  6:22       ` Kevin Rodgers
2009-06-30  8:47       ` Pascal J. Bourguignon [this message]
2009-06-30 20:33         ` TheFlyingDutchman
2009-06-30 21:37           ` Pascal J. Bourguignon
     [not found]       ` <mailman.1557.1246352126.2239.help-gnu-emacs@gnu.org>
2009-06-30 20:30         ` TheFlyingDutchman
2009-06-30 20:44           ` Pascal J. Bourguignon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ctz1yhzvp.fsf@pbourguignon.anevia.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.