2 In general, =define-namespace= should work as you expect it to. But if you
3 need to understand why something is or isn't being namespaced, here's
4 the nitty gritty of how it happens.
7 Quoted lists (be it with =quote= or =function=) are namespaced *only*
8 of the list is a =lambda= form (or a =macro= form). Arbitrary lists
9 are returned untouched (they are way too arbitrary to be handled
11 #+begin_src emacs-lisp
12 (define-namespace foo-
15 '(lambda (x) (infinite x))
16 '(not a lambda (infinite x))))
20 #+begin_src emacs-lisp
21 (defun foo-infinite (y)
23 '(lambda (x) (foo-infinite x))
24 '(not a lambda (infinite x))))
27 Note that = '(lambda ...)= is bad practice in Emacs, you should use
28 =(lambda ...)= instead (which is also namespaced just fine).
30 ** Symbols Quoted with Quote
31 A symbol quoted with =quote= (or = ' =) is never namespaced.
32 #+begin_src emacs-lisp
33 (define-namespace foo-
35 (defvaralias 'varalias 'var)
37 (defalias 'alias 'fun)
38 (defalias 'otheralias 'var)
42 #+begin_src emacs-lisp
44 (defvaralias 'varalias 'var)
46 (defalias 'alias 'fun)
47 ;;; foo-var is not a function, so:
48 (defalias 'otheralias 'var)
51 If you provide the =:assume-var-quote= keyword, quoted symbols will be
52 namespaced as variables instead.
53 ** Symbols Quoted with Function
54 A symbol quoted with =function= (or =#' =) is assumed to be the name of a
55 function, and will be namespaced as such if possible. You may provide
56 the =:dont-assume-function-quote= keyword to disable this behaviour,
57 =function= will then be treated like =quote=.
59 #+begin_src emacs-lisp
60 (define-namespace foo-
62 (mapcar 'fun somelist)
63 (mapcar #'fun somelist)
67 #+begin_src emacs-lisp
69 (mapcar 'fun somelist)
70 (mapcar #'foo-fun somelist)
73 ** Backticks (quasi-quotes)
74 Backticks (or =`=) are handled as you would expect. Lists or simbles
75 quoted with a backtick are treated the same as those quoted with
76 regular quotes ([[#quoted-lists][see above]]), except anything prefixed by a comma (which
77 is effectively not quoted) is namespaced as usual.
79 ** Local Variables Take Precedence
80 Local variables take precedence over namespace variables.
82 #+begin_src emacs-lisp
83 (define-namespace foo-
91 #+begin_src emacs-lisp
98 Note how the last =bar= isn't namespaced. That's because it is local
99 to the =funca= function, and takes precedence over the global
100 =foo-bar=. The argument list of functions, macros, and lambdas are
101 all local definitions.
103 By default, this does not happen with let bindings, they are
104 namespaced as usual (if the variable name in question has a global
105 definition). The reason is that let bindings are commonly used to
106 temporarily override global bindings.
108 You can customize this behaviour with the =:no-let-vars= keyword.
110 #+begin_src emacs-lisp
111 (define-namespace foo- :no-let-vars
119 #+begin_src emacs-lisp
127 Macros are handled in a very intelligent manner.
129 *Names* needs to know which parts of a macro's arguments are
130 evaluatable forms, and which are just arbitrary symbols. This presents
131 a challenge because macro arguments could be absolutely anything.
132 Fortunately, (good) macros already provide that information in their
135 Thus, *Names* uses the macro's =edebug-spec-list= to find out which
136 arguments are evaluatable forms, and namespaces only those. Other
137 arguments are left untouched. Usually, this is not something you'll
138 need to worry about, it should just do what you expect from it.
140 This is only relevant if you write your own macros. If you do,
141 remember to add a debug declaration in them.
142 ** Accessing Global Symbols
143 If one of your definitions shadows a global definition, you can still
144 access it by prefixing it with =::=.
146 #+begin_src emacs-lisp
147 (define-namespace foo-
154 #+begin_src emacs-lisp
155 (defun foo-message ()
160 When in doubt feel free to use =::=, it will always get removed (as
161 long as it's not inside a =quote=). You may also change this prefix to
162 something else with the =:prefix= keyword.