I currently have an Emacs/AucTeX setup where emacs --debug-init doesn't throw any errors, but things still don't work as expected. This being the case, I don't really know how to debug my .emacs file without endlessly shuffling lines around, etc.

Two examples of things that don't work as expected:

  • Although I have activated reftex-isearch-minor-mode (C-h v says it's t, although the status bar doesn't show it's activated), it only works if after emacs has started, I deactivate, and then activate the mode again via M-x.

  • I have activated electric-pair-mode, and in a multifile-document the following happens: Typing (, [ or { in the main file results in emacs inserting a pair as expected, but typing [ in a non-main file (?) only inserts a single [, while ( and { are still inserted as pairs.

So, my question is: How can I get my setup to work correctly, or can someone point me at a resource that tells me how and in what order I have to put in the various setq, require, and whatnot lines, so that everything is loaded and hooked correctly.

Disclaimer №1: I have practically no Lisp knowledge (and I fear it shows…).

Disclaimer №2: I first asked this question on tex.se, but was told it's more appropriate to post it here.

My .emacs (that is probably a bit messed up) for reference:

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")
                         ("melpa" . "http://melpa.milkbox.net/packages/")))

(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

(setq-default TeX-master nil)
(setq TeX-parse-self t) ; Enable parse on load.
(setq TeX-auto-save t) ; Enable parse on save.
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

;; Enable RefTeX automatically in AUCTeX buffers.
(autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
(add-hook 'TeX-mode-hook
      (lambda ()
(setq reftex-plug-into-AUCTeX t)

;; AUCTeX-related settings.
(add-hook 'LaTeX-mode-hook
      (lambda ()
         '("satz" LaTeX-env-label)
         '("lem" LaTeX-env-label)
         '("Bem" LaTeX-env-label)
         '("Bsp" LaTeX-env-label)
         '("Def" LaTeX-env-label))
        (add-to-list 'LaTeX-label-alist '("satz". "thm:"))
        (add-to-list 'LaTeX-label-alist '("lem" . "thm:"))       
        (add-to-list 'LaTeX-label-alist '("Bem" . "rem:"))
        (add-to-list 'LaTeX-label-alist '("Bsp" . "exp:"))  
        (add-to-list 'LaTeX-label-alist '("Def" . "def:"))))

;; RefTeX-related settings.
(setq reftex-label-alist
    ("satz"   ?T "thm:"  "~\\ref{%s}" nil ("theorem"   "thm."))
    ("lem"   ?T "thm:"  "~\\ref{%s}" nil ("lemma"   "lem."))
    ("Bem" ?R "rem:" "~\\ref{%s}" t   ("remark" "rmk."))
    ("Bsp" ?E "exp:" "~\\ref{%s}" t   ("example" "exp."))
    ("Def" ?D "def:" "~\\ref{%s}" t   ("definition" "def.")))
    reftex-insert-label-flags '("s" "sftTRED"))

(require 'org-table)

;; auctex-latexmk
(require 'auctex-latexmk)
(setq auctex-latexmk-inherit-TeX-PDF-mode t)

(setq TeX-source-correlate-mode t)
(setq reftex-isearch-minor-mode t)

(add-hook 'LaTeX-mode-hook (lambda ()
                             (TeX-fold-mode 1)))

;; Markdown-Major-Mode
(autoload 'markdown-mode "markdown-mode"
   "Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))

;; Pandoc-Minor-Mode
(autoload 'pandoc-mode "pandoc-mode" "Minor mode for using Pandoc" t)
(add-hook 'markdown-mode-hook 'pandoc-mode)

;; turn on automatic bracket insertion by pairs. New in emacs 24
(electric-pair-mode 1)

(setq TeX-electric-math t)

(add-hook 'plain-TeX-mode-hook
      (lambda () (set (make-variable-buffer-local 'TeX-electric-math)
              (cons "$" "$"))))
(add-hook 'LaTeX-mode-hook
      (lambda () (set (make-variable-buffer-local 'TeX-electric-math)
              (cons "\\(" "\\)"))))

;; turn on highlight matching brackets when cursor is on one
(show-paren-mode 1)

;; (setq show-paren-style 'parenthesis) ; highlight brackets
;; (setq show-paren-style 'expression) ; highlight entire expression
(setq show-paren-style 'mixed) ; highlight brackets if visible, else entire expression

;; The library uniquify overrides Emacs’ default mechanism for making buffer names unique 
(require 'uniquify)

 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(TeX-PDF-mode t)
   ["black" "#d55e00" "#009e73" "#f8ec59" "#0072b2" "#cc79a7" "#56b4e9" "white"])
 '(custom-enabled-themes (quote (zenburn)))
    ("67e998c3c23fe24ed0fb92b9de75011b92f35d3e89344157ae0d544d50a63a72" default)))
 '(ispell-dictionary "british")
    (zenburn-theme auctex-latexmk cdlatex org popup pandoc-mode markdown-mode csharp-mode)))
 '(reb-re-syntax (quote string)))
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
  • 1
    The usual: Recursively bisect your init file, to find the problem. If it loads other code (e.g. packages) then do the same for that code. This post risks being closed because it is too broad. It practically dumps an init file here and asks others to debug it. – Drew Jun 23 '17 at 0:53
  • Two remarks: (a) you should set reftex-search-minor-mode by calling the function of that name, not via setq. It would make most sense to put that call in the appropriate major mode hook. (b) for latex you should probably be setting the variable LaTeX-electric-left-right-brace rather than using electric-pair-mode. – Andrew Swann Jun 23 '17 at 6:55
  • Welcome to Emacs.SE! As @Drew noted, the usual way to debug an init file that is not behaving as expected is to recursively bisect the file (comment out half, then half of the non-working half, and so on, until you isolate the culprit). If you have a specific item that's not working and you would like help, please narrow down the question and isolate the lines in your init file that you think are causing the problem. It's easier to get good answers here when you can offer as discrete a question as possible – Dan Jun 23 '17 at 13:02
  • @Drew: Yes, I know about bisecting. My problem is that a) I don't get any errors, so checking whether something works or not is kind of difficult, especially since I'm not used to the modes, yet, so I don't always know what to expect, and b) I don't really know what to change. Do I just change the order of the lines, do I load a mode via a hook, or not, etc. – Lustique Jun 25 '17 at 15:14
  • 1
    @AndrewSwann - Thanks for pointing this out. This issue is fixed upstream in Emacs repo and should be available in next Emacs release. – Arash Esbati Aug 26 '17 at 13:18