7

I'm new to emacs, org-mode. I have an org file which, every time I open, I have to enable the minor modes: visual-line-mode and org-indent-mode by hand using the M-x command.

I saw this question in stackoverflow and tried the following code in my .emacs file only to see an error when emacs loads.

Code

(require 'org-mode)  
(defun turn-on-visual-line-mode () (visual-line-mode 1))  
(add-hook 'org-mode-hook 'turn-on-visual-line-mode)  

Error

Warning (initialization): An error occurred while loading ‘c:/Users/Prasanna Rajaram/AppData/Roaming/.emacs’:

File error: Cannot open load file, No such file or directory, org-mode

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

I did not try the org-indent-mode as I did not know how to turn on multiple minor modes with defun().

1
  • 1
    So get the full debug trace as stated in that message: Start Emacs with the ‘--debug-init’ option to view a complete error backtrace. and let us know what that is. The culprit here is that you are doing (require 'org-mode) instead of (require 'org). May 10, 2016 at 16:04

1 Answer 1

20

The culprit here is that you are doing (require 'org-mode) instead of (require 'org).


But here's an alternative way to enable the minor modes that you need for org files (below is tested to work in an emacs -Q session):

;; `with-eval-after-load' macro was introduced in Emacs 24.x
;; In older Emacsen, you can do the same thing with `eval-after-load'
;; and '(progn ..) form.
(with-eval-after-load 'org       
  (setq org-startup-indented t) ; Enable `org-indent-mode' by default
  (add-hook 'org-mode-hook #'visual-line-mode))

Recommendation: You should not directly require a package (even though doing so will also work). Doing so will make emacs load that whole package at startup and could result in slower startup. Instead, you should allow the org package to get automatically loaded as configured in the package itself, and then do org-specific setup in the with-eval-after-load or eval-after-load form.

1
  • 2
    I also found another way of doing it on a per-file-basis only for indenting. #+STARTUP: indent
    – Prasanna
    May 11, 2016 at 11:26

Your Answer

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

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