Questions tagged [dynamic-scoping]

26 questions
10
votes
3 answers

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-var x)) (f2))) (defun f2 () "Returns the…
Ryan C. Thompson
  • 435
  • 2
  • 10
6
votes
1 answer

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> (expand-file-name "http://example.com"…
Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
6
votes
1 answer

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 (lambda () (set (make-local-variable…
5
votes
1 answer

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, read it back in, and evaluate it. That’s pretty…
4
votes
1 answer

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-valid-keys () "Return a list of valid bibtex…
John Kitchin
  • 11,555
  • 1
  • 19
  • 41
3
votes
3 answers

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-something.el Suppose somewhere during init.el…
american-ninja-warrior
  • 3,773
  • 2
  • 21
  • 40
3
votes
1 answer

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 other functions.) evil-delete takes optional…
3
votes
1 answer

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 () (return-number)) (defun patch-cl-labels () …
Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
2
votes
1 answer

`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-variable 'xx) ;; set the value of xx, buffer-locally …
shynur
  • 4,065
  • 1
  • 3
  • 23
2
votes
0 answers

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-root. Is this possible? Side note (not part of…
George Mauer
  • 397
  • 2
  • 9
2
votes
2 answers

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
  • 3,204
  • 1
  • 12
  • 30
2
votes
3 answers

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 function is not shown): (defun my-function() …
AlwaysLearning
  • 749
  • 4
  • 14
2
votes
1 answer

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: :var dc-list='((US . "United States of America") (CA .…
Melioratus
  • 4,504
  • 1
  • 25
  • 43
1
vote
1 answer

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 () "Completing brace marks group." (setq…
Dilna
  • 1,173
  • 3
  • 10
1
vote
1 answer

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 scope was wrong, which I always reluctantly…
Ruy
  • 787
  • 4
  • 11
1
2