I have problems running eval-defun for a defun when there is a square bracket [ in column 0 of its doc string. For example:

(defun test ()
  "Test function. 
[Some text]"
  (message "Hello"))

When I position the cursor inside the function above and type M-x eval-defun RET it displays "[Some text]" in the echo area, but the defun is not being evaluated. If I remove the square bracket [ in the doc string, and then reevaluate, it works fine and displays "test" in the echo area.

I am using GNU Emacs 25.2.1 on Ubuntu 17.04.

  • Seems like a bug to me. Don't have a way to verify this, but what happens if you replace [ with \133?
    – wvxvw
    Oct 20, 2017 at 9:02
  • 4
    Just insert a backslash \ before the opening square bracket [. See (emacs) Left Margin Paren.
    – Basil
    Oct 20, 2017 at 9:48
  • @Basil Thanks for the link. That seems to be the case, but I wonder why has a bracket in the first column the same effect as a parenthesis for eval-defun? A bracket in the first column cannot be the start of a defun, am I right? Oct 20, 2017 at 9:54
  • 2
    It cannot be the start of a call to the defun macro, but it can be a top-level definition, which is what Emacs documentation refers to as a defun. See (emacs) Defuns. Note also that the documentation is careful to prefer the word "delimiter" to "paren", implying multiple paren-like characters.
    – Basil
    Oct 20, 2017 at 10:02
  • What @Basil said. A "defun" in this context is not necessarily a call to Lisp macro defun.
    – Drew
    Oct 20, 2017 at 15:29

1 Answer 1


AFAIU fixing this would require a hack around of SPECPDL_INDEX in C-source.

However, ar-backward-defun,ar-forward-defun jumps to start and end of a defun also in these cases: https://github.com/andreas-roehler/thingatpt-utils-core/blob/master/ar-subr.el

Wherefrom a command to escape opening parens in column 0 might be provided:

(defun ar-auto-escape ()
  (interactive "*")
    (let ((end (save-excursion (ar-end-of-defun) (line-beginning-position))))
      (forward-line 1) 
      (while (and (re-search-forward "^\\([\[(]+\\)" nil t 1) (< (line-beginning-position) end))
    (replace-match (concat "\\\\" (match-string-no-properties 1)))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.