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 23:37:36 +0200	[thread overview]
Message-ID: <877hyttnbz.fsf@galatea.local> (raw)
In-Reply-To: e381c5a7-473b-42b1-802f-db2836601e32@l32g2000vbp.googlegroups.com

TheFlyingDutchman <zzbbaadd@aol.com> writes:

>>
>> 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__
>
> Thanks Pascal. What I was hoping for was not an error if documentation
> is nil, but if the symbol name was invalid. But I guess in Emacs Lisp
> there is no such thing as an invalid symbol name. So it would have to
> be an error if the symbol was only created from a "read or use", not
> from a setq or defvar, etc.

Yes, that's the point.  You could test for boundp, but nothing would
prevent you to document variables that are not bound.

Notice that in emacs lisp, you can define a variable without giving it
an initial value:

(defvar *strange*)
(setf (documentation-property '*strange* 'variable-documentation) 
      "A strange variable, with no value")

(boundp '*strange*) 
--> nil

(defun f ()
   (list (boundp '*strange*) 
         (documentation-property '*strange* 'variable-documentation)))

(let ((*strange* 42))
  (f))
--> (t "A strange variable, with no value")

(f)
--> (nil "A strange variable, with no value")


In programs, it is often the case that the best way is to try to do
something and see if there's a problem, rather than trying to see if
doing something could pose a problem.  Foremost because there is no
reliable way to see if doing something could pose a problem, bar doing
it.

Here, if you want the documentation of a variable, the best way is to
try to get it.  And you cannot know when the documentation is not
available, whether it's because the symbol doesn't name a variable of
whether the variable has not been documented.

-- 
__Pascal Bourguignon__


  reply	other threads:[~2009-06-30 21:37 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
2009-06-30 20:33         ` TheFlyingDutchman
2009-06-30 21:37           ` Pascal J. Bourguignon [this message]
     [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=877hyttnbz.fsf@galatea.local \
    --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.