8
votes
Accepted
Variable scope issue in scratch buffer?
Your Emacs version (29, most likely) has silently changed the value of lexical-binding from nil to t in the *scratch* buffer.
When you use C-M-x to evaluate only those functions that variable isn't ...
8
votes
Accepted
Why does calling expand-file-name indirectly produce a different result?
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-...
8
votes
Accepted
Why does defvar scoping work differently without an initvalue?
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 ...
7
votes
Accepted
About closure creation
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 ...
7
votes
How to temporarily change the definition of a function?
How to temporarily change the definition of a function?
Calling a function by its (symbol) name means calling that symbol's function slot. So, to temporarily change the definition of a function that ...
5
votes
Accepted
why is a let binding is ignored in compiled function?
You're compiling the file using lexical binding, so I suspect the problem is that your file does neither of the following:
(defvar bibtex-completion-bibliography)
(require 'bibtex-completion)
either ...
5
votes
How does scoping work in emacs lisp
All functions and variables defined in a file that gets loaded are put into the global environment. Although Emacs has installable packages, those packages are not isolated from each other in any way. ...
4
votes
Why does defvar scoping work differently without an initvalue?
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, ...
4
votes
Accessing the global value of a locally altered variable
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 ...
4
votes
Accepted
Inconsistency in emacs' rules of scope?
Lexical scope (recently added to emacs) changes the rules, and some documentation is still out of date. The current documentation for setq is this manual page which says
When dynamic variable binding ...
4
votes
Accepted
How does one "extend" an existing function?
TL;DR: As mentioned by the comments on your initial question, you are looking for Advising Functions.
Even though this question has been idle for a while at the time of my writing this, I wanted to ...
3
votes
Accepted
Search in readable eww buffer
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 ...
2
votes
Accepted
Why is org-table-calc-current-TBLFM throwing Wrong type argument: integer-or-marker-p Error?
Ah, very nice. Remember that elisp is dynamically scoped, so any function that you call can see and overwrite any variable you define, and any function that you write can do the same for any variable ...
2
votes
Top-level variables, local variables, variable scoping and the difference between set and setq
Looking at Using Lexical Binding it appears that a needs to be defined special which in using setq it is not. Modifying your example to use defvar gives the answers expected.
;;; -*- lexical-binding:...
2
votes
How did `cl-flet` got circumvented?
You are out of luck here; this is the correct intended behavior.
#'counsel-fzf-action refers to the global function definition of counsel-fzf-action, not the local one.
The cl-flet binding is local, ...
2
votes
Accepted
`make-local-variable` Behaves Differently depending on Whether Variable is Special
Variables with dynamic scope can have global and buffer-local values, which are associated with the canonical symbol for the variable.
The global vs buffer-local concepts are irrelevant to lexically-...
2
votes
Warning: assignment to free variable ‘skeleton-pair’
It's just a warning.
With your setq you're assigning a value to a global variable. Emacs is just letting you know this.
You didn't explicitly tell Emacs that skeleton-pair is a global variable. To do ...
1
vote
Accepted
dynamic scoping rules work differently after redefining an autoloaded function without changing its code
In your example, result is a let-bound lexical variable in the org-babel-execute-src-block function (which is defined in ob-core.el which uses -*- lexical-binding: t; -*-).
This means that result is ...
1
vote
How did `cl-flet` got circumvented?
There are many options for overriding functions, with many different behaviours. https://stackoverflow.com/questions/39550578/in-emacs-what-is-the-difference-between-cl-flet-and-cl-letf will probably ...
1
vote
How does scoping work in emacs lisp
OP seems to be missing the point already clearly made in the two answers given: you cannot do what you are asking. Emacs uses a voluntary naming convention, not syntax or compilation rules, to define ...
1
vote
How does scoping work in emacs lisp
In Elisp, all functions names normaly (but not necessarily) reside as an entry in a global environment (obarray). In Elisp functions can be redefined. Which means the function definition which has ...
1
vote
Accessing the global value of a locally altered variable
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 ...
1
vote
Forcing lexical-scope in the middle of dynamic-scope
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 ...
1
vote
Accepted
capture and replay a closure later
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 ...
1
vote
Accepted
Changing a mode's keymap for the duration of a command's execution
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dynamic-scoping × 28lexical-scoping × 16
variables × 5
elisp × 3
let-binding × 3
org-babel × 2
advice × 2
setq × 2
lexical-binding × 2
defvar × 2
closures × 2
org-mode × 1
init-file × 1
indentation × 1
org-table × 1
search × 1
files × 1
company-mode × 1
keymap × 1
functions × 1
projectile × 1
help × 1
interactive × 1
elisp-macros × 1
compilation-mode × 1