Emacs: narrow-to-defun, eval-defun, bug

By Xah Lee. Date:

when coding elisp, there's narrow-to-defun, and eval-defun. They do not always work.

For them to work, they require that your code be already formatted in the standard elisp convention.

Here's a example.

emacs narrow-to-defun bug 2015-06-09
Emacs: narrow-to-defun, eval-defun, bug.

This is more serious if you are habituated in Alt+x eval-defun, because it may eval only part of the code.

As a consequence, i never use them.

Here's the code you can try. Paste the following in a new buffer, Alt+x emacs-lisp-mode. Put cursor before the “3”, then Alt+x narrow-to-defun.

;; some
(defun xxtest ()
  "..."
  (interactive)
(let (x)
  (setq x
 [
 3
 4
 ])))
;; more

This is emacs GNU Emacs 24.4.1. But is in emacs 23.x, and i think earlier too.

Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs