Skip to main content
Share Your Experience: Take the 2024 Developer Survey
14 votes
Accepted

How do you recompile an .el source file and make it active in my current session

How do you recompile an .el source file [...] In Elisp file-visiting buffers, you can run the command M-xemacs-lisp-byte-compileRET to byte-compile the corresponding file. In Dired buffers, you can ...
Basil's user avatar
  • 12.4k
9 votes
Accepted

Defun inside let with lexical binding gives byte-compile warning "the function is not known to be defined"

The byte-compiler's way to decide whether a function will be defined or not is very "naive" and gets fooled even in your "obvious" case. But you can write it in a way that lets the compiler understand ...
Stefan's user avatar
  • 26.5k
8 votes
Accepted

Why is Emacs asking me to save changed buffers, when I install a package?

There isn't a lot of logic behind this. At least, not in the sense of a conscious decision. It's more of a feature of the compilation process that really doesn't apply to package management but nobody ...
Malabarba's user avatar
  • 23.2k
7 votes
Accepted

package.el: How can I avoid byte-compilation

Try using a ~/.emacs.d/elpa/.dir-locals.el file containing: ((emacs-lisp-mode . ((no-byte-compile . t)))) no-byte-compile is generally intended to be used as a file-local variable (see C-hig (elisp) ...
phils's user avatar
  • 51.5k
6 votes
Accepted

How can I make Emacs warn about calls to my pure functions?

If you look in byte-optimize-form-code-walker, you can see that a warning is printed for side-effect-free functions, but error-free functions just get optimized out and logged (not warned) only. ...
npostavs's user avatar
  • 9,203
6 votes

Defun inside let with lexical binding gives byte-compile warning "the function is not known to be defined"

To suppress the byte-compiler warning, try adding this before your code, starting in column 0 (leftmost): (declare-function increase-count "your-file-name.el") C-h f declare-function tells you: ...
Drew's user avatar
  • 77.9k
6 votes
Accepted

eval-when-compile: defsubst vs defmacro vs define-inline

I'd say stick with defun. If you want to try define-inline, which is new (it doesn't even have a doc string yet!), go ahead. But think about how much you want or need inlining. It is rare to need it,...
Drew's user avatar
  • 77.9k
6 votes
Accepted

Fixing "reference/assignment to free variable" warning during compilation if variable is dynamically bounded

Assuming you are using lexical binding, if the variable is dynamic, then it must be defvar'd (to ensure that lexical binding cannot treat it otherwise). AFAIK it would be a bug to not use defvar. For ...
phils's user avatar
  • 51.5k
6 votes

error: Invalid byte opcode: op=183, ptr=2

A solution to this is to delete all compiled EmacsLisp files in the user's Emacs directory cd ~/.emacs.d/ find . -name "*.elc" -type f Once you are satisfacted by what the find command ...
smonff's user avatar
  • 1,589
6 votes
Accepted

eval-when-compile and eval-and-compile identical definitions?

How can eval-when-compile and eval-and-compile have different behavior if their definitions are identical? The hint is in the commentary in the definition of eval-and-compile: ;; When the byte-...
Basil's user avatar
  • 12.4k
6 votes
Accepted

Is there a way to suppress warnings when a package is compiled in elisp?

See byte-compile-warnings: List of warnings that the byte-compiler should issue (t for almost all). Elements of the list may be: docstrings: docstrings that are too wide (longer than byte-compile-...
shynur's user avatar
  • 5,318
5 votes
Accepted

Prevent byte-compiler warnings after requiring features

IMHO, the right way is to ignore it. ;-) But the standard Emacs answer is to use declare-function - see (elisp) Declaring Functions. All you need to do is add a declare-function statement before ...
Drew's user avatar
  • 77.9k
5 votes
Accepted

When I (byte-compile-file "my-package.el"), can I treat warnings as errors?

The documentation for the customisable variable byte-compile-error-on-warn says: If true, the byte-compiler reports warnings with `error'.
Basil's user avatar
  • 12.4k
5 votes
Accepted

Does `load` prefer .elc files over .el files?

By default the .elc would be loaded rather than the .el, as noted in the other answers/comments. A few things can affect this behavior, however: Set load-prefer-newer to t if you want to load ...
glucas's user avatar
  • 20.6k
5 votes
Accepted

Which functions cannot be redefined after byte compilation?

If you look at (symbol-plist 'not) you will see that it has a byte-opcode property with value byte-not. So the elisp compiler will use this rather than a general function call. I have not looked for ...
icarus's user avatar
  • 1,914
5 votes

Where and when should emacs lisp files be byte-compiled?

Before the advent of eager (load-time) macro expansion, I would have said this was crazy talk, and told you to forget the idea and compile everything as usual. Maybe it's somewhat less crazy now that ...
phils's user avatar
  • 51.5k
5 votes

Disassembly of a bytecode *file*?

With cl-print.el (builtin as of Emacs 26), this is actually pretty easy to do almost perfectly: (require 'cl-print) (defun disassemble-file (filename) (let ((inbuf (find-file-noselect filename))) ...
npostavs's user avatar
  • 9,203
5 votes
Accepted

Why are custom themes not usually byte-compiled?

The manual nodes (elisp) Custom Themes, (emacs) Custom Themes and (emacs) Creating Custom Themes make no mention of byte-compilation, so why is it not done? At the time of writing, the manuals indeed ...
Basil's user avatar
  • 12.4k
5 votes

Where are these variables defined? - bytecomp Warnings

See the answer by Drew for a general description of compiler warnings pertaining to free variables. In your particular case, however, the culprit is the package oauth2.el, which for some reason is ...
Basil's user avatar
  • 12.4k
5 votes

Can one inhibit eval-when-compile?

EDIT: The comment of npostavs is true. When you load "other-package" during byte compilation the test result on byte-compilation in "other-package" is negative. You need to ...
Tobias's user avatar
  • 33.2k
5 votes
Accepted

How to get Emacs to know that a symbol has a function definition

Your question is a little confusing, but I suspect you actually mean that you've byte-compiled the prelude-ivy.el library (as opposed to "reading the source file"), and that the compiler has produced ...
phils's user avatar
  • 51.5k
5 votes
Accepted

Is there a way to determine if emacs uses the byte compiled or the natively compiled code of a function?

In emacs-28.1, describe-function gives this information: switch-to-buffer is an interactive native compiled Lisp function in ‘window.el’.
Fran Burstall's user avatar
5 votes

Is there a way to determine if emacs uses the byte compiled or the natively compiled code of a function?

Variable system-configuration-features will contain NATIVE_COMP if your Emacs has been compiled with native compilation support.
gjm's user avatar
  • 151
5 votes
Accepted

Which byte-compile-file is my Emacs using? Function signature in describe-function differs to that in bytecomp.el

There is only one function of a given name at a time. describe-function tells you what file the function was defined in, and clicking the link takes you directly to it. When a function is redefined, ...
db48x's user avatar
  • 18.2k
4 votes
Accepted

`Warning (bytecomp)` is a bit vague - can I get any more information?

This happens due to display-warning delaying warnings until after init time. By then, the file name and location are no longer known. (defun display-warning (type message &optional level buffer-...
npostavs's user avatar
  • 9,203
4 votes

Where and when should emacs lisp files be byte-compiled?

js2-mode benefits substantially from byte compilation because it does heavy computing to semantically analyze the Javascript code. Other major modes use regular expression. byte compilation does not ...
chen bin's user avatar
  • 4,877
4 votes
Accepted

Does package-install do byte-compilation?

package-install does byte-compile the files, yes. Not sure how/why your auctex install doesn't have any .elc files, tho. Maybe a bug, or a pilot error.
Stefan's user avatar
  • 26.5k
4 votes
Accepted

Function might not be defined at runtim

That's because the compiler simply sees that at compile-time the function is defined (because of the eval-and-), but it sees that at runtime, the function will only be defined (if <blabla>, IOW ...
Stefan's user avatar
  • 26.5k
4 votes

How do you find all macro calls in an elisp file?

I found a way to do it interactively with el-search (http://elpa.gnu.org/packages/el-search.html). M-x el-search `(,(pred macrop) ,_) finds them. Interestingly, it matches backticked s-exps like `(:...
John Kitchin's user avatar
  • 11.9k

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