Questions tagged [dynamic-scoping]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
10 votes
3 answers
381 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-...
Ryan C. Thompson's user avatar
6 votes
1 answer
1k 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 (...
user1943733's user avatar
6 votes
1 answer
1k 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> (...
Wilfred Hughes's user avatar
5 votes
1 answer
499 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, ...
anquegi's user avatar
  • 749
4 votes
1 answer
69 views

why is a let binding is ignored in compiled function?

I have this function which works perfectly in an uncompiled function. It should let-bind the variable bibtex-completion-bibliography to the result of (org-ref-find-bibliography). (defun org-ref-...
John Kitchin's user avatar
  • 11.9k
3 votes
3 answers
343 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-...
american-ninja-warrior's user avatar
3 votes
1 answer
356 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 () (...
Wilfred Hughes's user avatar
3 votes
2 answers
579 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? )
Toothrot's user avatar
  • 3,264
3 votes
1 answer
189 views

How does one "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 ...
not-just-yeti's user avatar
2 votes
1 answer
70 views

`make-local-variable` Behaves Differently depending on Whether Variable is Special

Two examples (both are in the *scratch* buffer and under lexical scoping rule): _ (setq xx :default) (let ((xx :let)) (with-current-buffer (get-buffer-create "tmp") (make-local-...
shynur's user avatar
  • 5,308
2 votes
1 answer
238 views

Why is org-table-calc-current-TBLFM throwing Wrong type argument: integer-or-marker-p Error?

Why does my code generate the error when used with org-table? No error message when code used outside of org-table #+NAME: get-country-or-area-name #+HEADER: :var iso-alpha2-code="ca" #+HEADER: :...
Melioratus's user avatar
  • 4,644
2 votes
3 answers
180 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 ...
AlwaysLearning's user avatar
2 votes
0 answers
104 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-...
George Mauer's user avatar
1 vote
1 answer
277 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)...
Talespin_Kit's user avatar
1 vote
1 answer
53 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 ...
Ruy's user avatar
  • 839
1 vote
1 answer
81 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-...
ivan's user avatar
  • 1,948
1 vote
1 answer
95 views

Warning: assignment to free variable ‘skeleton-pair’

Am using the following function, but getting the error In bracemk-balance: fencones.el:109:9:Warning: assignment to free variable ‘skeleton-pair’ What is wrong with this? (defun bracemk-balance ()...
Dilna's user avatar
  • 1
1 vote
1 answer
71 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 ...
Ivan Ruski's user avatar
1 vote
1 answer
327 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 @...
Kevin's user avatar
  • 1,318
1 vote
1 answer
33 views

dynamic scoping rules work differently after redefining an autoloaded function without changing its code

Evaluate the following code: (package-initialize) (unless package-archive-contents (package-refresh-contents)) (package-install-selected-packages) (org-babel-do-load-languages 'org-babel-load-...
user615536's user avatar
1 vote
0 answers
276 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." (...
Jose V's user avatar
  • 141
0 votes
3 answers
202 views

How did `cl-flet` got circumvented?

I want to slightly alter the behavior of counsel-fzf by locally changing the definition of counsel-fzf-action, which activates in the end of the definition of the former. See the source code of ...
Student's user avatar
  • 225
0 votes
1 answer
116 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 ...
Pfedj's user avatar
  • 338
0 votes
1 answer
174 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: ;; -*- ...
zeRusski's user avatar
  • 335
0 votes
1 answer
49 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-...
Prgrm.celeritas's user avatar
0 votes
0 answers
43 views

dynamic scoping doesn't perform as expected

(require 'cl) (require 'seq) (require 'dash) (eval-when-compile (require 'cl-lib) (require 'subr-x) (require 'env) (require 'json)) (defgroup chatgpt nil "ChatGPT frontend." :...
A-nak Wannapaschaiyong's user avatar
0 votes
2 answers
201 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 ...
Aquaactress's user avatar
  • 1,453