Questions tagged [dynamic-scoping]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
235 views

How do I temporarily mock a function for testing?

I'd like to patch some elisp functions inside my unit tests. I've tried cl-labels and cl-flet, but neither achieve the result I want: (defun return-number () 1) (defun calls-return-number () (...
0
votes
1answer
33 views

How to temporarily change the definition of a function?

In the following code the function foo calls the outer f2 function. How to make it call the anonymous function bound within the let? (defun f2 () (message "outer f2")) (defun foo () (f2)...
0
votes
1answer
34 views

Inconsistency in emacs' rules of scope?

I have always felt that emacs' rules of scope are a bit strange and prone to contradictions. In fact I have even attempted to file bug reports just to be told that my interpretation of the rules of ...
1
vote
1answer
25 views

Top-level variables, local variables, variable scoping and the difference between set and setq

I've been reading about emacs dynamic and lexical bindings. While I generally get the difference between the two types, there is one example that is not clear to me. I've checked this question and I ...
1
vote
0answers
48 views

How to override a value inside a function temporarily?

There is this function in tide: ;; Defined in ~/.emacs.d/.local/straight/repos/tide/tide.el (defun tide-rename-file () "Rename current file and all it's references in other files." (...
3
votes
3answers
148 views

How does scoping work in emacs lisp

A lot of emacs configurations shared publicly have this format: ;; 01-something.el (provide 'something) ;; init.el (require 'something) Suppose I'm writing a defun named "s-join" inside 01-...
2
votes
0answers
59 views

how to “extend” an existing function?

What I want to do: have the function evil-delete do one more task after its usual code. (I'm presuming that evil-delete is the underlying workhorse that is called by evil-delete-line and about five ...
0
votes
2answers
113 views

Unusual behavior when overriding `calculate-lisp-indent'

I've modified calculate-lisp-indent as a better solution to the indentation questions here, here and here. By "modified" I mean I overrode the function with advice. After doing this when I restarted ...
2
votes
0answers
62 views

Can I set a variable scoped to a perspective?

I have a large monorepo repository and open different parts of it in a persp-mode perspective. It would be nice if for all buffers owned by that perspective I could set for example projectile-project-...
6
votes
1answer
873 views

Scope in lambda

In my .emacs conf file, I've got this function that adds a hook to set the compile-command based on the mode. It looks something like, (defun set-compile-cmd (mode-hook cmd) (add-hook mode-hook (...
0
votes
1answer
86 views

Search in readable eww buffer [duplicate]

I would like to open url in eww in readable-mode and find str. Below is my code that doesn't work: (defun my-eww-searh-readable (str) "Once-off call to `my-eww-searh-readable' after EWW is done ...
2
votes
2answers
231 views

Accessing the global value of a locally altered variable

Is it possible to access the global value of a variable that has been changed locally? (setq foo 2) (let ((foo 3)) ;; can I access the original value here? )
5
votes
1answer
251 views

About closure creation

After reading this article about readable closures, I check that: Since closures are byte-code function objects, they print readably. You can capture an environment in a closure, serialize it, ...
0
votes
1answer
92 views

Forcing lexical-scope in the middle of dynamic-scope

Today I ran head first into lexical vs dynamic scope in Emacs Lisp. Gist of it is I have a macro defined in lexical scope that expands into a `defun'. Let's say something simple like this: ;; -*- ...
0
votes
1answer
40 views

capture and replay a closure later

I am having a problem working with closures. I hope I can explain this clearly. When I try to start a compilation I typically do it like this: (let ((dir (get-dir)) (model-root root) (default-...
10
votes
3answers
277 views

Why does defvar scoping work differently without an initvalue?

Suppose I have a file named elisp-defvar-test.el containing: ;;; elisp-defvar-test.el --- -*- lexical-binding: t -*- (defvar my-dynamic-var) (defun f1 (x) "Should return X." (let ((my-dynamic-...
6
votes
1answer
491 views

Why does calling expand-file-name indirectly produce a different result?

Running the following in ielm in emacs -Q: ELISP> (defun wh/expand-file-name (name &optional default-directory) (expand-file-name name default-directory)) wh/expand-file-name ELISP> (...
2
votes
3answers
137 views

Changing a mode's keymap for the duration of a command's execution

I would like to bind TAB to my company-mode back-end only for the duration of a command's execution. I am trying to achieve this by using dynamic scoping as follows (the irrelevant part of the ...
1
vote
1answer
66 views

How to avoid variable name collisions in my init file?

I noticed spacemacs puts things like autosave and backup files in ~/.emacs.d/.cache/ and I'd like to use that idea in my own setup. From spacemacs/core/core-load-paths.el (defconst spacemacs-cache-...
1
vote
1answer
283 views

How to fix Warning: assignment to free (local) variable in lambda function

The byte compiler just gave me this message 1103:24:Warning: assignment to free variable `orig-win-config on this bit of code: ;; create window config store and restore functions ;; credit to @...