Malabarba / names

A Namespace implementation for Emacs-Lisp
250 stars 19 forks source link

Help with names-eval-last-sexp? #14

Closed melton1968 closed 9 years ago

melton1968 commented 9 years ago

I assumed that names-eval-last-sexp would allow you to interactively evaluate an expression within a namespace without prefixing the namespace name. However, in the example below, I cannot seem to get it to work. I would expect to be able to interactively evaluate the expression (a) within the namespace using names-eval-last-sexp. Am I doing something wrong?

(require 'names)
(define-namespace foo-

(defun a ()
  (message "defun a called"))

(foo-a) ;; defun a called
(a)     ;; *backtrace*  (void-function a)

)

(foo-a) ;; defun a called
(a)     ;; *backtrace*  (void-function a)
Malabarba commented 9 years ago

Yes, you are correct. It absolutely should allow you to evaluate (a). I may have broken something recently. Let me try to reproduce that and I'll get back to you.

melton1968 commented 9 years ago

FYI: I am using emacs 24.4.1 and names-20150115.1 from MELPA.

Malabarba commented 9 years ago

Thanks that helped. Indeed I broke this feature on Emacs 24.4 (I didn't notice cause there aren't any tests for the -dev stuff yet). I'll fix it asap.

Malabarba commented 9 years ago

Ok, should be fixed in version 20150125 Let me know if it works.

melton1968 commented 9 years ago

Interactive evaluation now works as expected within the namespace. Thanks for the quick turn-around.

I have a related question -- if I close and then re-open the namespace, interactive evaluation works as expected, but the unqualified symbol is not found in the re-opened namespace when using commands like eval-buffer or load-file. E.g.,

(require 'names-dev)

;; open the namespace foo
(define-namespace foo-
(defun a ()
  (message "defun a called"))
(foo-a) ;; defun a called
(a)     ;; defun a called
)

;; reopen the namespace foo
(define-namespace foo-
(foo-a) ;; defun a called
(a)     ;; Symbol's function definiton is void: a
)

Is this the intended behavior? I'd like to be able to use the same namespace over multiple files. Is there some other methodology I should be using?

Malabarba commented 9 years ago

Yes, just add the :global keyword after foo-.

By default Names only looks up symbol names locally (inside the macro). This keyword tells it you want to access symbols defined outside the macro as well.

This should allow you to have multifile namespaces. I haven't developed a multifile package using Names yet, so please let me know of any workflow obstacles you encounter so I can fix them!