When I launch my emacs software (Aquamacs.app) I see a message

File mode specification error: (error ":END: line missing at position 23740")

Unfortunately, I do not know in which file this problem occurs. It must be an org-mode buffer, where I have a drawer like :PROPERTIES: or :LOGBOOK: where I accidentally deleted the corresponding :END: line.

I don't see how to find the corresponding place in my files.

Is there a way to check all open buffers for such inconsistency or get a clearer error message which also specifies the buffer where the problem occurs?

3 Answers 3


This appears to be coming from the function org-flag-drawer.

Use C-h f to find where this function is defined, and modify it to also give the buffer name:

(defun org-flag-drawer (flag)
  "When FLAG is non-nil, hide the drawer we are within.
    Otherwise make it visible."
    (beginning-of-line 1)
    (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
      (let ((b (match-end 0)))
        (if (re-search-forward
             "^[ \t]*:END:"
             (save-excursion (outline-next-heading) (point)) t)
            (outline-flag-region b (point-at-eol) flag)
          (user-error (concat (buffer-name) " :END: line missing at position %s" b)))))))
  • hm, I tried it but the error does not occur any more. :-) Seems, I have (unwillingly) already repaired the org file. Commented Nov 13, 2014 at 11:30

The error message tells you where the error is: position 23740. You can go there with goto-char. Doing M-x goto-char 23740 will take you to the error. org-mode's folding may make it hard to see what's going on, so switching to fundamental-mode (with M-x fundamental-mode) first may help you see what's going on.

  • yes, I found that out already, but the error message does not tell me which org-file is the one to check and I have many of them open, they get loaded automatically in the background for the agenda Commented Nov 14, 2014 at 6:16

I've had the same problem. My solution was to write a simple lint-type command.

This adds the command sh/org-lint which will iterate over all the buffers loaded from my agenda and check for this kind of problem. It lists the problems in a compilation buffer, which means that you can just press RETURN to jump to the problems.

It's pretty simplistic, and I keep meaning to improve it, but works well enough for me when I need to track down these kind of things.

Apologies in advance for my shocking elisp.

(defun sh/org-lint-buffer ()
  "Check for balanced BEGIN/END markers in the current Org-mode buffer.

 My edits (especially resolution of git merge conflicts) seem to
 sometimes mess up the balancing of the ':BEGIN:' and ':END:'
 markers in the file. Org-mode does report these as errors when
 it's parsing the file (you can see the messages in the
 '*Messages*' buffer), but it unhelpfully does not identify the
 buffer where the problem has occurred. This function searches
 through the current buffer and reports buffer and line positions
 of the errors, which is much more useful."

  ;; <START> markers are:
  ;; Cases:
   ;;; <START> with no END before end of buffer
   ;;; <START> with no END before next <START>
   ;;; END before <START>

      (goto-char (point-min))
      (let ((previous-point (point))
            (end-marker-re "^:END:")
            (start-marker-re "^:LOGBOOK:\\|:PROPERTIES:"))

        ;; Before we move to the first start block, we're now outside
        ;; of a BEGIN/END. If we find another END before the next
        ;; block then that is clearly an orphan.
            (setq next-max-point
                  (or (re-search-forward start-marker-re (point-max) t)
          (if (re-search-forward end-marker-re next-max-point t)
              (sh/org-lint-error (buffer-file-name) (line-number-at-pos) "orphaned END marker")))

        ;; Loop until there are no more start markers.
        (while (re-search-forward start-marker-re nil t)
          ;; Try to find the END marker that matches this start
          ;; position and move to there.
            (setq next-max-point
                  (or (re-search-forward start-marker-re (point-max) t)
          (unless (re-search-forward end-marker-re next-max-point t)
            (sh/org-lint-error (buffer-file-name) (line-number-at-pos) "START without END"))

          ;; Move on.
          (setq previous-point (point))

          ;; We're now outside of a BEGIN/END; if we find another END
          ;; before the next block then that is clearly an orphan.
              (setq next-max-point
                    (or (re-search-forward start-marker-re (point-max) t)
            (if (re-search-forward end-marker-re next-max-point t)
                (sh/org-lint-error (buffer-file-name) (line-number-at-pos) "orphaned END marker"))))))))

(defun sh/org-lint ()
  "Check for balanced BEGIN/END markers in all Org-mode buffers.

 Apply Org-mode file structure and style checks to all Org-mode
 buffers. See `sh/org-lint-buffer' for a description of the checks
    (with-current-buffer (get-buffer-create "*Org lint*")
      (read-only-mode 0)
  (mapcar (lambda(buffer)
            (with-current-buffer buffer
              (if (eq major-mode 'org-mode)
  (when (buffer-size
         (with-current-buffer (get-buffer "*Org lint*")
    (switch-to-buffer-other-window "*Org lint*")))

(defun sh/org-lint-error (buffer-name line-number error-message)
  "Report an error when linting an Org-mode buffer.

 Reports ERROR-MESSAGE as being the problem reported for line
 LINE-NUMBER in the buffer called BUFFER-NAME."
    (with-current-buffer (get-buffer-create "*Org lint*")
       (format "%s:%d: %s\n" buffer-name line-number error-message)))))
  • cool, thanks a lot! I'll try that out when the error occurs next time! Commented Dec 22, 2014 at 20:25

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.