11

No, it shouldn't, if you use dynamic binding. Here are two choices (alternatives) that can help: Use lexical binding. Set variable lexical-binding for the file. Use dynamic binding (what you are doing now, no doubt), but also substitute the value of the variable cmd for the variable cmd in the lambda body. You can do this only if the function body of the ...


8

In short: dynamic binding. It is maybe a little unfortunate that default-directory was used as the argument to expand-file-name. Note the docstring: (expand-file-name NAME &optional DEFAULT-DIRECTORY) Convert filename NAME to absolute, and canonicalize it. Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative (does not ...


8

Why the two are treated differently is mostly "because that's what we needed". More specifically, the single-argument form of defvar appeared a long time ago, but later than the other and was basically a "hack" to silence compiler warnings: at execution time it had no effect at all, so as an "accident" it meant that the silencing behavior of (defvar FOO) ...


7

You asked: Will be useful to write/build literal closures? Should it be a good practice? any example? Why the closure is not a real type instead of cons? All three questions are answered with the following quote of the elisp manual: However, the fact that the internal structure of a closure is exposed to the rest of the Lisp world is ...


4

Based on experimentation, I believe the issue is that (defvar VAR) with no init value only has an effect on the library(s) it appears in. When I added (defvar my-dynamic-var) to the *scratch* buffer, the error no longer occurred. I originally thought this was on account of evaluating that form, but I then noticed firstly that simply visiting the file with ...


3

You seem to be using dynamic binding which means that str would be evaluated once your lambda function is executed at which time the variable str is no longer in scope. You should turn on lexical binding to have your hook function converted into a closure during the invocation of my-eww-url so that once your hook function will be invoked str will be bound ...


3

Using a should-be-unique prefix is recommended. For init file code I like to use my- because: it is suitably unlikely to conflict with anything. it's short, but meaningful. it's not my name -- so when I share code with other people it reads just as well in their init file as it does in my own.


2

As usual for this kind of thing, just put (defvar orig-win-config) near the beginning of the same file. That declares orig-win-config as a dynamic variable. Otherwise, the byte-compiler thinks that (set-window-configuration orig-win-config) refers to an undefined variable. (It is not that the compiler thinks that (make-local-variable 'orig-win-config) "...


2

In addition to what @cyberbisson has said (no, you cannot) ... First, in this: (setq foo 2) (let ((foo 3)) ;; can I access the original value here? ) there is nothing that says that the (setq foo 2) sets the "global value" or the "original" value. It depends on whether foo in that context is a special variable (aka dynamically scoped or global ...


1

The short answer is "no", there's really no means of escaping to a different scope like you might do in a language like C++. There may be a very hacky way of getting to the variable if you use dynamic binding, although you should definitely not try it (I have not). From Dynamic Binding - GNU Emacs Lisp Reference Manual: Dynamic binding is implemented in ...


1

This is arguably a duplicate of How to avoid use of `lexical-let`, and there are many different questions here. While you may be able to hack something to get some code to sometimes work, I don't recommend you go there: by the time we get to your macro, the surrounding variable has already been defined as dynamically-scoped so it's too late to really fix it ...


1

I was experimenting with the reader macros and I think I figured it out. The problem is that I am trying to evaluate, the let values twice. Once when they are first bound and then again when we rebind them. This is not a problem for variables that are strings, because strings always evaluate to themselves. But lambdas evaluate to closures, and you can’t ...


1

The comment you wrote on of the other answers was very useful in figuring out what you want to do; I hope I understood correctly. I believe you want to write a command that prompts for a string from the minibuffer with TAB temporarily bound to `my-company-backend. Assuming the string prompted for is the only argument your command needs, try something like ...


Only top voted, non community-wiki answers of a minimum length are eligible