1

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.
(package-initialize)

(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 ()
        (turn-on-reftex)))
(setq reftex-plug-into-AUCTeX t)

;; AUCTeX-related settings.
(add-hook 'LaTeX-mode-hook
      (lambda ()
        (LaTeX-add-environments
         '("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)
(auctex-latexmk-setup)
(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
 ;; 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)
 '(ansi-color-names-vector
   ["black" "#d55e00" "#009e73" "#f8ec59" "#0072b2" "#cc79a7" "#56b4e9" "white"])
 '(custom-enabled-themes (quote (zenburn)))
 '(custom-safe-themes
   (quote
    ("67e998c3c23fe24ed0fb92b9de75011b92f35d3e89344157ae0d544d50a63a72" default)))
 '(ispell-dictionary "british")
 '(package-selected-packages
   (quote
    (zenburn-theme auctex-latexmk cdlatex org popup pandoc-mode markdown-mode csharp-mode)))
 '(reb-re-syntax (quote string)))
(custom-set-faces
 ;; 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.
 )
Drew
  • 77,472
  • 10
  • 114
  • 243
Lustique
  • 119
  • 1
  • 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 00: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 06: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
  • @AndrewSwann: Thank you for your remarks! I tried to put reftex-isearch-minor-mode into a hook (specifially the reftex-mode-hook, because that's what I thought it would belong in), but it didn't work (I tried (add-hook 'reftex-mode-hook 'reftex-isearch-minor-mode)). Thankfully I found this comment here, and now it works. Now I'm just wondering whether I just lacked the lambda, or whether the mode I tried to hook this minor-mode into was wrong… And the thing about LaTeX-electric-left-right-brace vs. electric-pair-mode: – Lustique Jun 25 '17 at 15:17
  • @AndrewSwann: (cont.'d) Why do you recommend LaTeX-electric-left-right-brace? I just tried to put (electric-pair-mode 1) more or less at the top (before any (La)TeX-related lines), and now it seems to work. – Lustique Jun 25 '17 at 15:19
  • @Dan: Thanks for your comment, as well. It's just that I don't really know what to change and how to effectively check whether everything works correctly (see comment to @Drew). Is there something like a ‘.emacs for Dummies’ that explains how certain modes are supposed to be turned on, when to use hooks, etc.? – Lustique Jun 25 '17 at 15:21
  • The LaTeX-electric- customization is the one mentioned in the AuCtex documentation, it is the one I use and it works for me. I have not tried electric-pair-mode – Andrew Swann Jun 26 '17 at 08:07
  • @AndrewSwann: Thanks, I'll keep that in mind. For now I'm trying out smartparens, mostly for the movement-commands, slurping and barfing. These are pretty nice for math-editing. Now I've got another, this time more concrete question though: Did I do something wrong with my reftex-insert-label-flags? Reftex now asks for equation labels, instead of inserting a simple one (the default behaviour, which I like, because I can't think of proper, descriptive labels for all equations I use). Is this option case-insensitive (see my E for example, for which I want this behaviour)? – Lustique Jun 27 '17 at 15:39
  • The comparison is done with string-match, see the function reftex-typekey-check, whose behaviour depends on the value of case-fold-search. What happens if you set case-fold-search to nil? – Andrew Swann Jun 27 '17 at 17:01
  • @AndrewSwann: Then it seems to work as expected. For an equation (e key) I get the default behaviour again, and for my Bsp environment (which uses the E key) Reftex asks for a label. Should I set case-fold-search to nil in my .emacs now, should I use a different key or is this a bug in Reftex? As there are the n (footnote) and N (endnote) labels (as per the documentation), this doesn't seem like the expected behaviour… – Lustique Jun 27 '17 at 18:35
  • I think you should report a bug to the reftex maintainers. It is only by looking at the code that I deduced that it depended on case-fold-search - I would not have expected that as behaviour - they ought to locally switch off case-fold-search when matching the keys. – Andrew Swann Jun 28 '17 at 07:32
  • 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

0 Answers0