help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to distinguish gobal and local variables in elisp?


From: Pascal Bourguignon
Subject: Re: How to distinguish gobal and local variables in elisp?
Date: Thu, 21 Sep 2006 20:54:22 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

"jronald" <followait@163.com> writes:

> The question comes from setq.
> Usually, setq appears in a file without in any parentheses.

Still not.
Here is a short example:
$ grep setq .emacs|grep -v -e '^ *;'|head -20
(setq default-enable-multibyte-characters      t
(setq my-latin (if (assoc-ignore-case "Latin-9" language-info-alist) 9 1))
  ((= my-latin 1) (setq my-lenv     "Latin-1"
  ((= my-latin 9) (setq my-lenv     "Latin-9"
(setq sendmail-coding-system           my-encoding
(setq inhibit-default-init t)
            (setq file (concat site-lisp "/" file))
(setq load-path
(setq x-toolkit-scroll-bars nil)
   (setq *window-manager-y-offset* (+ 24 24))
   (setq mac-command-key-is-meta t
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
         (setq palette            pal-thalassa
         (setq palette            pal-larissa
         (setq palette            pal-naiad
         (setq palette            pal-naiad
         (setq palette            pal-lassel

See?  There are a lot of parentheses.  setq DOES NOT appears in a file
without any parentheses.

So, since you start from a false assumption, we don't know if we speak
the same language, even thought we're using the same words.  

Have you read more of the emacs lisp introduction I advised you to read?



> Does it mean that it awlays set the global varaible then? Or what's a local 
> variable in lisp?

In lisp, a local variable is one that is bound locally. 
For example:

(defvar *global-variable* 1)

(let ((local-variable 2))
   (print (list *global-variable* local-variable)))

*global-variable* is a global variable.
local-variable is a local variable.


Now, if what you want to know is how to distinguish buffer-local
variables in emacs lisp, that's something else.

But note the differences:

    lisp              <-->    emacs lisp
    local variable    <-->    buffer-local variables

Buffer-local variables are specific to emacs lisp. However, in emacs
lisp there are also local variables, like in any other lisp.




In emacs, apart from the user and programmer manuals accessible by info
    C-h i d m emacs RET
    C-h i d m emacs lisp intro RET
    C-h i d m elisp RET

you can find information about variables, functions etc using various
commands such as:
    C-h f                     describe-function
    C-h v                     describe-variable
    M-x apropos 

For example, M-x apropos RET local.*variable RET
will give you a list of functions and variables concerned by local variables.
The first result is:

buffer-local-variables
  Function: Return an alist of variables that are buffer-local in BUFFER.

So this gives you an easy way to find what you want, even not knowing
anything.

(mapcar (function car) (buffer-local-variables))

If you read more of the apropos results, you could encounter the
function local-variable-p  that will tell you if a symbol is the name
of a buffer local variable.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]