While trying to solve this problem, Iv'e followed this, running cd ~/.emacs.d/elpa && find org*/*.elc -print0 | xargs -0 rm and recompiling elpa. But the undesired behaviour is still there and now this error shows up:

File mode specification error: (wrong-number-of-arguments #[(arg &optional invisible-ok) \306=\203\0    \306=\204\0\307 \210\310
!\210 \211\311X\203 \0\312\313!\210\311V\203]\0
\203G\0\315 \210\202K\0\316\311!\210 \211\2024\0)
S\202 \0)\317!\207 [this-command last-command invisible-ok outline-level start-level arg outline-up-heading push-mark outline-back-to-heading 1 error Already at top level of the outline 0 outline-previous-heading outline-previous-visible-heading looking-at level outline-regexp] 3 (/usr/share/emacs/26.3/lisp/outline.elc . 34670) p] 0)

How can I make org-mode open files in a folded state and not try to sort my headings when I open new files?

Using spacemacs 0.200.13 @ emacs 26.3. the relevant variables/settings are:

  ;; Org mode settings
  (defun org-sort-headings-todo-prio ()
    "sort org headings first by priority then by todo order"
    (org-sort-entries t ?p )
    (org-sort-entries t ?o ))

  (setq org-image-actual-width 400
        org-startup-with-inline-images t
        org-directory "~/path/to/folder/"
        org-default-notes-file (concat org-directory "organizer.org")
        org-startup-folded t)

  (add-hook 'org-mode-hook
            (lambda ()
              (make-variable-buffer-local 'yas/trigger-key)
              (setq yas/trigger-key [tab])
              (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
              (define-key yas/keymap [tab] 'yas/next-field)
              (flycheck-mode 1)
              (local-set-key (kbd "C-c C-x s") (org-sort-headings-todo-prio))))

  (global-set-key (kbd "C-c o") (lambda () (interactive) (find-file org-default-notes-file)))
  (global-set-key [c-x c-c c-r] 'org-preview-latex-default-process)
  (global-set-key (kbd "C-c c") 'org-capture)

the whole config file can be seen here (just without the variable definitions at the end)


1 Answer 1


The problem is apparently linked to the manner in which local-set-key is being used in conjunction with the org-mode-hook; i.e., (local-set-key (kbd "C-c C-x s") (org-sort-headings-todo-prio))

Emacs is being told to call the function org-sort-headings-todo-prio when running the org-mode-hook, instead of assigning org-sort-headings-todo-prio to a shortcut key. Try something like this instead:

(local-set-key (kbd "C-c C-x s") 'org-sort-headings-todo-prio)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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